sexpr 0.6.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -1
- data/Gemfile +1 -8
- data/README.md +26 -4
- data/lib/sexpr/version.rb +2 -2
- data/lib/sexpr.rb +11 -3
- data/spec/integration/bool_expr/test_validation.rb +4 -4
- data/spec/integration/test_readme_examples.rb +4 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/grammar/matching/test_compile_rule_defn.rb +2 -2
- data/spec/unit/grammar/matching/test_compile_rules.rb +1 -1
- data/spec/unit/grammar/tagging/test_looks_a_sexpr.rb +4 -4
- data/spec/unit/matcher/non_terminal/test_match_q.rb +2 -2
- data/spec/unit/matcher/reference/test_match_q.rb +1 -1
- data/spec/unit/matcher/terminal/test_match_q.rb +3 -3
- data/spec/unit/matcher/terminal/test_terminal_match.rb +28 -28
- data/spec/unit/parser/citrus/test_recognize.rb +1 -1
- data/spec/unit/test_sexpr.rb +1 -1
- data/tasks/test.rake +5 -20
- metadata +33 -141
- data/Gemfile.lock +0 -27
- data/LICENCE.md +0 -22
- data/Manifest.txt +0 -16
- data/examples/bool_expr/bool_expr.citrus +0 -72
- data/examples/bool_expr/bool_expr.rb +0 -59
- data/examples/bool_expr/bool_expr.sexp.yml +0 -23
- data/lib/sexpr/loader.rb +0 -1
- data/sexpr.gemspec +0 -189
- data/sexpr.noespec +0 -33
- data/tasks/debug_mail.rake +0 -75
- data/tasks/debug_mail.txt +0 -13
- data/tasks/yard.rake +0 -51
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 67f9fda1b0281f22e49fc267f432c1bed5ba6f270911b0470786662533d257d0
|
4
|
+
data.tar.gz: 97b7fc7fce491b594f4fb52a06daa5837407a5d5db59ab6bb6ae56e517e38492
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 808fbbb1bd28d417addfd740a85c441e022208ed87111a713bd4cd1920254b606181c3c8a2bbabd2c4fcaa707543b11d3baa1db6e661378fa7f7b350256599f7
|
7
|
+
data.tar.gz: 2c3795497e39ededc4cec8897fd178a34911fa3647a40561d8218da19bc9b72671de4b6d86bbd5854beb1d9ebc2907d86536d33531fe7c8b38074338c8824263
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# Sexpr
|
2
2
|
|
3
|
-
[](http://travis-ci.org/blambeau/sexpr)
|
4
|
-
[](https://gemnasium.com/blambeau/sexpr)
|
5
|
-
|
6
3
|
A ruby compilation framework around s-expressions.
|
7
4
|
|
8
5
|
## Links
|
@@ -87,4 +84,29 @@ https://github.com/blambeau/sexpr
|
|
87
84
|
|
88
85
|
### Where to read next?
|
89
86
|
|
90
|
-
Have a look at the examples directory.
|
87
|
+
Have a look at the examples directory.
|
88
|
+
|
89
|
+
## Public API
|
90
|
+
|
91
|
+
`sexpr` uses Semver and reached 1.0. The public API is as follows:
|
92
|
+
|
93
|
+
* The structure of YAML grammar files
|
94
|
+
* The `Sexpr` module and its public methods
|
95
|
+
* The behavior of the `Grammar` class through its public methods
|
96
|
+
* The behavior of the `Node` class (public methods)
|
97
|
+
* The behavior of the `Processor` and `Rewriter` classes (public & protected methods)
|
98
|
+
* The list of error classes and when they are raised
|
99
|
+
|
100
|
+
## Contribute
|
101
|
+
|
102
|
+
Please use github issues and pull requests for all questions, bug reports,
|
103
|
+
and contributions. Don't hesitate to get in touch with us with an early code
|
104
|
+
spike if you plan to add non trivial features.
|
105
|
+
|
106
|
+
## Licence
|
107
|
+
|
108
|
+
This software is distributed by Enspirit SRL under a MIT Licence. Please
|
109
|
+
contact Bernard Lambeau (blambeau@gmail.com) with any question.
|
110
|
+
|
111
|
+
Enspirit (https://enspirit.be) and Klaro App (https://klaro.cards) are both
|
112
|
+
actively using and contributing to the library.
|
data/lib/sexpr/version.rb
CHANGED
data/lib/sexpr.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require_relative "sexpr/version"
|
3
|
-
require_relative "sexpr/loader"
|
4
3
|
require_relative "sexpr/errors"
|
5
4
|
require_relative "sexpr/node"
|
6
5
|
require_relative "sexpr/grammar"
|
@@ -14,6 +13,8 @@ require_relative "sexpr/rewriter"
|
|
14
13
|
module Sexpr
|
15
14
|
extend Grammar::Tagging
|
16
15
|
|
16
|
+
YAML_OPTIONS = { :permitted_classes => %w[Regexp], :aliases => true }
|
17
|
+
|
17
18
|
PathLike = lambda{|x|
|
18
19
|
x.respond_to?(:to_path) or (x.is_a?(String) and File.exists?(x))
|
19
20
|
}
|
@@ -30,11 +31,11 @@ module Sexpr
|
|
30
31
|
|
31
32
|
def self.load_file(input, options = {})
|
32
33
|
path = input.to_path rescue input.to_s
|
33
|
-
load_hash
|
34
|
+
load_hash load_yaml(File.read(path)), options.merge(:path => input)
|
34
35
|
end
|
35
36
|
|
36
37
|
def self.load_string(input, options = {})
|
37
|
-
load_hash
|
38
|
+
load_hash load_yaml(input), options
|
38
39
|
end
|
39
40
|
|
40
41
|
def self.load_hash(input, options = {})
|
@@ -42,4 +43,11 @@ module Sexpr
|
|
42
43
|
Grammar.new input, options
|
43
44
|
end
|
44
45
|
|
46
|
+
def self.load_yaml(source)
|
47
|
+
if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
|
48
|
+
YAML.safe_load(source, **YAML_OPTIONS)
|
49
|
+
else
|
50
|
+
YAML.load(source)
|
51
|
+
end
|
52
|
+
end
|
45
53
|
end # module Sexpr
|
@@ -3,13 +3,13 @@ describe BoolExpr, 'the validation feature' do
|
|
3
3
|
subject{ BoolExpr }
|
4
4
|
|
5
5
|
it 'validates s-expressions' do
|
6
|
-
subject.match?([:bool_lit, true]).should
|
7
|
-
subject.match?([:bool_lit, "x"]).should
|
6
|
+
subject.match?([:bool_lit, true]).should be_truthy
|
7
|
+
subject.match?([:bool_lit, "x"]).should be_falsey
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'validates s-expressions against specific rules' do
|
11
|
-
subject[:bool_lit].match?([:bool_lit, true]).should
|
12
|
-
subject[:bool_and].match?([:bool_lit, true]).should
|
11
|
+
subject[:bool_lit].match?([:bool_lit, true]).should be_truthy
|
12
|
+
subject[:bool_and].match?([:bool_lit, true]).should be_falsey
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -35,15 +35,15 @@ describe "the README examples" do
|
|
35
35
|
|
36
36
|
# the grammar can be used to verify the structure of s-expressions
|
37
37
|
f = (grammar === [:bool_and, [:bool_not, [:var_ref, "x"]], [:bool_lit, true]])
|
38
|
-
f.should
|
38
|
+
f.should be_truthy
|
39
39
|
|
40
40
|
f = (grammar === [:bool_and, [:bool_lit, "true"]])
|
41
|
-
f.should
|
41
|
+
f.should be_falsey
|
42
42
|
|
43
43
|
# the grammar can also be used to automatically have support on top of
|
44
44
|
# such s-expressions
|
45
45
|
expr = grammar.sexpr([:bool_lit, true])
|
46
|
-
(Sexpr===expr).should
|
46
|
+
(Sexpr===expr).should be_truthy
|
47
47
|
|
48
48
|
(expr.sexpr_type).should eq(:bool_lit)
|
49
49
|
# => :bool_lit
|
@@ -58,7 +58,7 @@ describe "the README examples" do
|
|
58
58
|
copy.should eq([:bool_lit, [:bool_lit, false]])
|
59
59
|
# => [:bool_lit, [:bool_lit, false]]
|
60
60
|
|
61
|
-
(Sexpr===copy).should
|
61
|
+
(Sexpr===copy).should be_truthy
|
62
62
|
|
63
63
|
end
|
64
64
|
|
data/spec/spec_helper.rb
CHANGED
@@ -72,7 +72,7 @@ module Sexpr
|
|
72
72
|
end
|
73
73
|
it 'compiles its elements' do
|
74
74
|
subject.terms.size.should eq(3)
|
75
|
-
subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should
|
75
|
+
subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should be_truthy
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -83,7 +83,7 @@ module Sexpr
|
|
83
83
|
end
|
84
84
|
it 'compiles its elements' do
|
85
85
|
subject.terms.size.should eq(3)
|
86
|
-
subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should
|
86
|
+
subject.terms.all?{|x| x.is_a?(Matcher::Terminal)}.should be_truthy
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -4,16 +4,16 @@ module Sexpr::Grammar
|
|
4
4
|
include Tagging
|
5
5
|
|
6
6
|
it 'recognizes s-expressions' do
|
7
|
-
looks_a_sexpr?([:lit]).should
|
7
|
+
looks_a_sexpr?([:lit]).should be_truthy
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'does not recognize empty arrays' do
|
11
|
-
looks_a_sexpr?([]).should
|
11
|
+
looks_a_sexpr?([]).should be_falsey
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'does not recognize others' do
|
15
|
-
looks_a_sexpr?(nil).should
|
16
|
-
looks_a_sexpr?(:lit).should
|
15
|
+
looks_a_sexpr?(nil).should be_falsey
|
16
|
+
looks_a_sexpr?(:lit).should be_falsey
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -10,7 +10,7 @@ module Sexpr::Matcher
|
|
10
10
|
context 'when match' do
|
11
11
|
let(:sexpr){ [:hello, "world"] }
|
12
12
|
|
13
|
-
it{ should
|
13
|
+
it{ should be_truthy }
|
14
14
|
end
|
15
15
|
|
16
16
|
[
|
@@ -24,7 +24,7 @@ module Sexpr::Matcher
|
|
24
24
|
context "when no match, e.g. #{example.inspect}" do
|
25
25
|
let(:sexpr){ example }
|
26
26
|
|
27
|
-
it{ should
|
27
|
+
it{ should be_falsey }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -9,7 +9,7 @@ module Sexpr::Matcher
|
|
9
9
|
|
10
10
|
it 'returns true on match' do
|
11
11
|
rule.should be_match(true)
|
12
|
-
(rule === true).should
|
12
|
+
(rule === true).should be_truthy
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'returns false on no match' do
|
@@ -25,7 +25,7 @@ module Sexpr::Matcher
|
|
25
25
|
|
26
26
|
it 'returns true on match' do
|
27
27
|
rule.should be_match(false)
|
28
|
-
(rule === false).should
|
28
|
+
(rule === false).should be_truthy
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns false on no match' do
|
@@ -41,7 +41,7 @@ module Sexpr::Matcher
|
|
41
41
|
|
42
42
|
it 'returns true on match' do
|
43
43
|
rule.should be_match(nil)
|
44
|
-
(rule === nil).should
|
44
|
+
(rule === nil).should be_truthy
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'returns false on no match' do
|
@@ -12,19 +12,19 @@ module Sexpr::Matcher
|
|
12
12
|
let(:arg){ /^[a-z]+$/ }
|
13
13
|
|
14
14
|
it 'matches a matching string' do
|
15
|
-
terminal.terminal_match?("hello").should
|
15
|
+
terminal.terminal_match?("hello").should be_truthy
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'matches a non matching string' do
|
19
|
-
terminal.terminal_match?("12").should
|
19
|
+
terminal.terminal_match?("12").should be_falsey
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'does not match a sexp' do
|
23
|
-
terminal.terminal_match?([:sexp, "Hello World"]).should
|
23
|
+
terminal.terminal_match?([:sexp, "Hello World"]).should be_falsey
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not match nil' do
|
27
|
-
terminal.terminal_match?(nil).should
|
27
|
+
terminal.terminal_match?(nil).should be_falsey
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,18 +32,18 @@ module Sexpr::Matcher
|
|
32
32
|
let(:arg){ true }
|
33
33
|
|
34
34
|
it 'matches true' do
|
35
|
-
terminal.terminal_match?(true).should
|
35
|
+
terminal.terminal_match?(true).should be_truthy
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'does not match false/nil' do
|
39
|
-
terminal.terminal_match?(false).should
|
40
|
-
terminal.terminal_match?(nil).should
|
39
|
+
terminal.terminal_match?(false).should be_falsey
|
40
|
+
terminal.terminal_match?(nil).should be_falsey
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'does not match anything else' do
|
44
|
-
terminal.terminal_match?([]).should
|
45
|
-
terminal.terminal_match?([:sexp]).should
|
46
|
-
terminal.terminal_match?("true").should
|
44
|
+
terminal.terminal_match?([]).should be_falsey
|
45
|
+
terminal.terminal_match?([:sexp]).should be_falsey
|
46
|
+
terminal.terminal_match?("true").should be_falsey
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,18 +51,18 @@ module Sexpr::Matcher
|
|
51
51
|
let(:arg){ false }
|
52
52
|
|
53
53
|
it 'matches false' do
|
54
|
-
terminal.terminal_match?(false).should
|
54
|
+
terminal.terminal_match?(false).should be_truthy
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'does not match true/nil' do
|
58
|
-
terminal.terminal_match?(true).should
|
59
|
-
terminal.terminal_match?(nil).should
|
58
|
+
terminal.terminal_match?(true).should be_falsey
|
59
|
+
terminal.terminal_match?(nil).should be_falsey
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'does not match anything else' do
|
63
|
-
terminal.terminal_match?([]).should
|
64
|
-
terminal.terminal_match?([:sexp]).should
|
65
|
-
terminal.terminal_match?("false").should
|
63
|
+
terminal.terminal_match?([]).should be_falsey
|
64
|
+
terminal.terminal_match?([:sexp]).should be_falsey
|
65
|
+
terminal.terminal_match?("false").should be_falsey
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,18 +70,18 @@ module Sexpr::Matcher
|
|
70
70
|
let(:arg){ nil }
|
71
71
|
|
72
72
|
it 'matches nil' do
|
73
|
-
terminal.terminal_match?(nil).should
|
73
|
+
terminal.terminal_match?(nil).should be_truthy
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'does not match true/false' do
|
77
|
-
terminal.terminal_match?(true).should
|
78
|
-
terminal.terminal_match?(false).should
|
77
|
+
terminal.terminal_match?(true).should be_falsey
|
78
|
+
terminal.terminal_match?(false).should be_falsey
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'does not match anything else' do
|
82
|
-
terminal.terminal_match?([]).should
|
83
|
-
terminal.terminal_match?([:sexp]).should
|
84
|
-
terminal.terminal_match?("nil").should
|
82
|
+
terminal.terminal_match?([]).should be_falsey
|
83
|
+
terminal.terminal_match?([:sexp]).should be_falsey
|
84
|
+
terminal.terminal_match?("nil").should be_falsey
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -89,18 +89,18 @@ module Sexpr::Matcher
|
|
89
89
|
let(:arg){ Symbol }
|
90
90
|
|
91
91
|
it 'matches a symbol' do
|
92
|
-
terminal.terminal_match?(:hello).should
|
92
|
+
terminal.terminal_match?(:hello).should be_truthy
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'does not match a string' do
|
96
|
-
terminal.terminal_match?("hello").should
|
96
|
+
terminal.terminal_match?("hello").should be_falsey
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'does not match anything else' do
|
100
|
-
terminal.terminal_match?(nil).should
|
101
|
-
terminal.terminal_match?([]).should
|
102
|
-
terminal.terminal_match?([:sexp]).should
|
103
|
-
terminal.terminal_match?("nil").should
|
100
|
+
terminal.terminal_match?(nil).should be_falsey
|
101
|
+
terminal.terminal_match?([]).should be_falsey
|
102
|
+
terminal.terminal_match?([:sexp]).should be_falsey
|
103
|
+
terminal.terminal_match?("nil").should be_falsey
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
data/spec/unit/test_sexpr.rb
CHANGED
data/tasks/test.rake
CHANGED
@@ -1,26 +1,11 @@
|
|
1
|
-
require "rspec/core/rake_task"
|
2
1
|
namespace :test do
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
-
desc
|
4
|
+
desc %q{Run all RSpec tests}
|
5
5
|
RSpec::Core::RakeTask.new(:unit) do |t|
|
6
|
-
t.
|
7
|
-
t.fail_on_error = true
|
8
|
-
t.failure_message = nil
|
9
|
-
t.verbose = true
|
10
|
-
t.rspec_path = "rspec"
|
11
|
-
t.rspec_opts = ["--color", "--backtrace"]
|
6
|
+
t.rspec_opts = %w[-I. -Ilib -Ispec --pattern=spec/**/test_*.rb --color .]
|
12
7
|
end
|
13
8
|
|
14
|
-
|
15
|
-
RSpec::Core::RakeTask.new(:integration) do |t|
|
16
|
-
t.pattern = "spec/integration/**/test_*.rb"
|
17
|
-
t.fail_on_error = true
|
18
|
-
t.failure_message = nil
|
19
|
-
t.verbose = true
|
20
|
-
t.rspec_path = "rspec"
|
21
|
-
t.rspec_opts = ["--color", "--backtrace"]
|
22
|
-
end
|
23
|
-
|
24
|
-
task :all => [ :unit, :integration ]
|
9
|
+
task :all => :"unit"
|
25
10
|
end
|
26
|
-
task :test =>
|
11
|
+
task :test => :"test:all"
|