antelope 0.2.0 → 0.2.2
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 +4 -4
- data/.gitignore +25 -23
- data/.rspec +3 -3
- data/.travis.yml +10 -9
- data/.yardopts +7 -7
- data/CONTRIBUTING.md +38 -38
- data/GENERATORS.md +124 -124
- data/Gemfile +7 -7
- data/LICENSE.txt +22 -22
- data/README.md +104 -104
- data/Rakefile +2 -2
- data/TODO.md +58 -58
- data/antelope.gemspec +28 -28
- data/bin/antelope +7 -7
- data/examples/deterministic.ace +35 -35
- data/examples/example.ace +51 -50
- data/examples/example.err +192 -0
- data/examples/{example.output → example.inf} +384 -385
- data/examples/liquidscript.ace +233 -162
- data/examples/simple.ace +22 -22
- data/lib/antelope/ace/compiler.rb +334 -334
- data/lib/antelope/ace/errors.rb +48 -48
- data/lib/antelope/ace/grammar/generation.rb +80 -80
- data/lib/antelope/ace/grammar/loading.rb +53 -53
- data/lib/antelope/ace/grammar/precedences.rb +68 -65
- data/lib/antelope/ace/grammar/productions.rb +156 -150
- data/lib/antelope/ace/grammar/symbols.rb +66 -66
- data/lib/antelope/ace/grammar.rb +69 -69
- data/lib/antelope/ace/precedence.rb +61 -61
- data/lib/antelope/ace/production.rb +57 -57
- data/lib/antelope/ace/scanner/argument.rb +57 -57
- data/lib/antelope/ace/scanner/first.rb +89 -89
- data/lib/antelope/ace/scanner/second.rb +177 -177
- data/lib/antelope/ace/scanner/third.rb +27 -27
- data/lib/antelope/ace/scanner.rb +134 -134
- data/lib/antelope/ace/token/epsilon.rb +24 -24
- data/lib/antelope/ace/token/error.rb +26 -26
- data/lib/antelope/ace/token/nonterminal.rb +17 -17
- data/lib/antelope/ace/token/terminal.rb +17 -17
- data/lib/antelope/ace/token.rb +238 -238
- data/lib/antelope/ace.rb +53 -53
- data/lib/antelope/cli.rb +55 -55
- data/lib/antelope/errors.rb +8 -8
- data/lib/antelope/generation/constructor/first.rb +88 -88
- data/lib/antelope/generation/constructor/follow.rb +103 -103
- data/lib/antelope/generation/constructor/nullable.rb +64 -64
- data/lib/antelope/generation/constructor.rb +126 -126
- data/lib/antelope/generation/errors.rb +17 -17
- data/lib/antelope/generation/null.rb +13 -13
- data/lib/antelope/generation/recognizer/rule.rb +216 -216
- data/lib/antelope/generation/recognizer/state.rb +130 -130
- data/lib/antelope/generation/recognizer.rb +180 -180
- data/lib/antelope/generation/tableizer.rb +175 -154
- data/lib/antelope/generation.rb +15 -15
- data/lib/antelope/generator/base.rb +264 -264
- data/lib/antelope/generator/c.rb +11 -11
- data/lib/antelope/generator/c_header.rb +105 -105
- data/lib/antelope/generator/c_source.rb +39 -39
- data/lib/antelope/generator/error.rb +34 -0
- data/lib/antelope/generator/group.rb +57 -57
- data/lib/antelope/generator/html.rb +51 -0
- data/lib/antelope/generator/info.rb +47 -0
- data/lib/antelope/generator/null.rb +18 -18
- data/lib/antelope/generator/output.rb +17 -49
- data/lib/antelope/generator/ruby.rb +79 -79
- data/lib/antelope/generator/templates/c_header.ant +36 -36
- data/lib/antelope/generator/templates/c_source.ant +202 -202
- data/lib/antelope/generator/templates/error.ant +33 -0
- data/lib/antelope/generator/templates/html/antelope.css +1 -0
- data/lib/antelope/generator/templates/html/antelope.html +1 -0
- data/lib/antelope/generator/templates/html/antelope.js +1 -0
- data/lib/antelope/generator/templates/html/css.ant +53 -0
- data/lib/antelope/generator/templates/html/html.ant +82 -0
- data/lib/antelope/generator/templates/html/js.ant +9 -0
- data/lib/antelope/generator/templates/info.ant +53 -0
- data/lib/antelope/generator/templates/ruby.ant +178 -146
- data/lib/antelope/generator.rb +66 -63
- data/lib/antelope/template/compiler.rb +78 -78
- data/lib/antelope/template/errors.rb +9 -9
- data/lib/antelope/template/scanner.rb +109 -109
- data/lib/antelope/template.rb +65 -60
- data/lib/antelope/version.rb +6 -6
- data/lib/antelope.rb +13 -13
- data/optimizations.txt +42 -0
- data/spec/antelope/ace/compiler_spec.rb +60 -60
- data/spec/antelope/ace/scanner_spec.rb +27 -27
- data/spec/antelope/constructor_spec.rb +133 -136
- data/spec/antelope/template_spec.rb +50 -49
- data/spec/fixtures/simple.ace +22 -22
- data/spec/spec_helper.rb +39 -39
- data/spec/support/benchmark_helper.rb +5 -5
- data/spec/support/grammar_helper.rb +15 -15
- data/subl/Ace (Ruby).JSON-tmLanguage +94 -94
- data/subl/Ace (Ruby).tmLanguage +153 -153
- metadata +17 -6
- data/lib/antelope/generator/templates/output.ant +0 -68
@@ -1,60 +1,60 @@
|
|
1
|
-
describe Ace::Compiler do
|
2
|
-
let :file do
|
3
|
-
<<-DOC
|
4
|
-
%{
|
5
|
-
test
|
6
|
-
%}
|
7
|
-
|
8
|
-
%require "#{VERSION}"
|
9
|
-
%language "ruby"
|
10
|
-
|
11
|
-
%terminal NUMBER
|
12
|
-
%terminal SEMICOLON ";"
|
13
|
-
%terminal ADD "+"
|
14
|
-
%terminal LPAREN "("
|
15
|
-
%terminal RPAREN ")"
|
16
|
-
|
17
|
-
%%
|
18
|
-
|
19
|
-
s: e
|
20
|
-
e: t ADD e
|
21
|
-
t: NUMBER | LPAREN e RPAREN
|
22
|
-
|
23
|
-
%%
|
24
|
-
|
25
|
-
hello
|
26
|
-
DOC
|
27
|
-
end
|
28
|
-
|
29
|
-
let :tokens do
|
30
|
-
Ace::Scanner.scan(file)
|
31
|
-
end
|
32
|
-
|
33
|
-
let :compiler do
|
34
|
-
Ace::Compiler.new(tokens)
|
35
|
-
end
|
36
|
-
|
37
|
-
subject do
|
38
|
-
compiler.compile
|
39
|
-
compiler
|
40
|
-
end
|
41
|
-
|
42
|
-
its(:body) { should =~ /test/ }
|
43
|
-
its(:body) { should =~ /hello/ }
|
44
|
-
its(:options) { should have_key :type }
|
45
|
-
|
46
|
-
it "should have the proper terminals" do
|
47
|
-
expect(subject.options[:terminals].map(&:first)).to eq [:NUMBER,
|
48
|
-
:SEMICOLON, :ADD, :LPAREN, :RPAREN]
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with an unmatched version" do
|
52
|
-
let :file do "%require \"0.0.0\"\n%%\n%%\n" end
|
53
|
-
|
54
|
-
it "should raise an error" do
|
55
|
-
expect {
|
56
|
-
subject
|
57
|
-
}.to raise_error(Ace::IncompatibleVersionError)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
describe Ace::Compiler do
|
2
|
+
let :file do
|
3
|
+
<<-DOC
|
4
|
+
%{
|
5
|
+
test
|
6
|
+
%}
|
7
|
+
|
8
|
+
%require "#{VERSION}"
|
9
|
+
%language "ruby"
|
10
|
+
|
11
|
+
%terminal NUMBER
|
12
|
+
%terminal SEMICOLON ";"
|
13
|
+
%terminal ADD "+"
|
14
|
+
%terminal LPAREN "("
|
15
|
+
%terminal RPAREN ")"
|
16
|
+
|
17
|
+
%%
|
18
|
+
|
19
|
+
s: e
|
20
|
+
e: t ADD e
|
21
|
+
t: NUMBER | LPAREN e RPAREN
|
22
|
+
|
23
|
+
%%
|
24
|
+
|
25
|
+
hello
|
26
|
+
DOC
|
27
|
+
end
|
28
|
+
|
29
|
+
let :tokens do
|
30
|
+
Ace::Scanner.scan(file)
|
31
|
+
end
|
32
|
+
|
33
|
+
let :compiler do
|
34
|
+
Ace::Compiler.new(tokens)
|
35
|
+
end
|
36
|
+
|
37
|
+
subject do
|
38
|
+
compiler.compile
|
39
|
+
compiler
|
40
|
+
end
|
41
|
+
|
42
|
+
its(:body) { should =~ /test/ }
|
43
|
+
its(:body) { should =~ /hello/ }
|
44
|
+
its(:options) { should have_key :type }
|
45
|
+
|
46
|
+
it "should have the proper terminals" do
|
47
|
+
expect(subject.options[:terminals].map(&:first)).to eq [:NUMBER,
|
48
|
+
:SEMICOLON, :ADD, :LPAREN, :RPAREN]
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with an unmatched version" do
|
52
|
+
let :file do "%require \"0.0.0\"\n%%\n%%\n" end
|
53
|
+
|
54
|
+
it "should raise an error" do
|
55
|
+
expect {
|
56
|
+
subject
|
57
|
+
}.to raise_error(Ace::IncompatibleVersionError)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
describe Ace::Scanner do
|
2
|
-
|
3
|
-
it "properly scans" do
|
4
|
-
expect(scan("%test \"a\" hi\n%%\nt: d { { } }\n%%\nhi\n")).to eq [
|
5
|
-
[:directive, "test", ["a", "hi"]],
|
6
|
-
[:second],
|
7
|
-
[:label, "t", nil],
|
8
|
-
[:part, "d", nil],
|
9
|
-
[:block, "{ { } }"],
|
10
|
-
[:third],
|
11
|
-
[:copy, "\nhi\n"]
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "throws an error" do
|
16
|
-
expect {
|
17
|
-
scan("% %% %% ")
|
18
|
-
}.to raise_error(Ace::SyntaxError)
|
19
|
-
end
|
20
|
-
|
21
|
-
def scan(source)
|
22
|
-
Timeout.timeout(5) do
|
23
|
-
Ace::Scanner.scan(source)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
1
|
+
describe Ace::Scanner do
|
2
|
+
|
3
|
+
it "properly scans" do
|
4
|
+
expect(scan("%test \"a\" hi\n%%\nt: d { { } }\n%%\nhi\n")).to eq [
|
5
|
+
[:directive, "test", ["a", "hi"]],
|
6
|
+
[:second],
|
7
|
+
[:label, "t", nil],
|
8
|
+
[:part, "d", nil],
|
9
|
+
[:block, "{ { } }"],
|
10
|
+
[:third],
|
11
|
+
[:copy, "\nhi\n"]
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "throws an error" do
|
16
|
+
expect {
|
17
|
+
scan("% %% %% ")
|
18
|
+
}.to raise_error(Ace::SyntaxError)
|
19
|
+
end
|
20
|
+
|
21
|
+
def scan(source)
|
22
|
+
Timeout.timeout(5) do
|
23
|
+
Ace::Scanner.scan(source)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -1,136 +1,133 @@
|
|
1
|
-
describe Generation::Constructor do
|
2
|
-
let(:grammar) { double("grammar") }
|
3
|
-
let(:terminal) { token(:TERMINAL) }
|
4
|
-
let(:epsilon) { token(:epsilon) }
|
5
|
-
|
6
|
-
subject { described_class.new(grammar) }
|
7
|
-
|
8
|
-
context "#nullable?" do
|
9
|
-
context "when given an epsilon token" do
|
10
|
-
it "returns true" do
|
11
|
-
expect(subject.nullable?(epsilon)).to be true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when given a terminal" do
|
16
|
-
it "returns false" do
|
17
|
-
expect(subject.nullable?(terminal)).to be false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when given an array" do
|
22
|
-
context "with one of the elements not nullable" do
|
23
|
-
it "returns false" do
|
24
|
-
expect(subject.nullable?([terminal, epsilon])).to be false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "with all of the elements nullable" do
|
29
|
-
it "returns true" do
|
30
|
-
expect(subject.nullable?([epsilon, epsilon])).to be true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when given a nonterminal" do
|
36
|
-
let(:grammar) { with_recognizer }
|
37
|
-
|
38
|
-
context "with no nullable productions" do
|
39
|
-
let(:nonterminal) { Ace::Token::Nonterminal.new(:l) }
|
40
|
-
|
41
|
-
it "returns false" do
|
42
|
-
expect(subject.nullable?(nonterminal)).to be false
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with a nullable production" do
|
47
|
-
let(:nonterminal) { Ace::Token::Nonterminal.new(:e) }
|
48
|
-
|
49
|
-
it "returns true" do
|
50
|
-
expect(subject.nullable?(nonterminal)).to be true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when given a bad argument" do
|
56
|
-
it "raises an error" do
|
57
|
-
expect { subject.nullable?(nil) }.to raise_error(ArgumentError)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "#first" do
|
63
|
-
context "when given an epsilon token" do
|
64
|
-
it "generates an empty set" do
|
65
|
-
expect(subject.first(epsilon)).to eq Set.new
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when given a terminal" do
|
70
|
-
it "generates a set" do
|
71
|
-
expect(subject.first(terminal)).to eq [terminal].to_set
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when given an array" do
|
76
|
-
let(:terminal2) { token(:terminal, :TERMINAL2) }
|
77
|
-
|
78
|
-
it "generates a set" do
|
79
|
-
expect(subject.first([epsilon, terminal])).
|
80
|
-
to eq [terminal].to_set
|
81
|
-
expect(subject.first([terminal, terminal2])).
|
82
|
-
to eq [terminal].to_set
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when given a nonterminal" do
|
87
|
-
let(:grammar) { with_recognizer }
|
88
|
-
let(:nonterminal) { token(:nonterminal, :e) }
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
type.new(name, ttype, id, value)
|
135
|
-
end
|
136
|
-
end
|
1
|
+
describe Generation::Constructor do
|
2
|
+
let(:grammar) { double("grammar") }
|
3
|
+
let(:terminal) { token(:TERMINAL) }
|
4
|
+
let(:epsilon) { token(:epsilon) }
|
5
|
+
|
6
|
+
subject { described_class.new(grammar) }
|
7
|
+
|
8
|
+
context "#nullable?" do
|
9
|
+
context "when given an epsilon token" do
|
10
|
+
it "returns true" do
|
11
|
+
expect(subject.nullable?(epsilon)).to be true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when given a terminal" do
|
16
|
+
it "returns false" do
|
17
|
+
expect(subject.nullable?(terminal)).to be false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when given an array" do
|
22
|
+
context "with one of the elements not nullable" do
|
23
|
+
it "returns false" do
|
24
|
+
expect(subject.nullable?([terminal, epsilon])).to be false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with all of the elements nullable" do
|
29
|
+
it "returns true" do
|
30
|
+
expect(subject.nullable?([epsilon, epsilon])).to be true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when given a nonterminal" do
|
36
|
+
let(:grammar) { with_recognizer }
|
37
|
+
|
38
|
+
context "with no nullable productions" do
|
39
|
+
let(:nonterminal) { Ace::Token::Nonterminal.new(:l) }
|
40
|
+
|
41
|
+
it "returns false" do
|
42
|
+
expect(subject.nullable?(nonterminal)).to be false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with a nullable production" do
|
47
|
+
let(:nonterminal) { Ace::Token::Nonterminal.new(:e) }
|
48
|
+
|
49
|
+
it "returns true" do
|
50
|
+
expect(subject.nullable?(nonterminal)).to be true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when given a bad argument" do
|
56
|
+
it "raises an error" do
|
57
|
+
expect { subject.nullable?(nil) }.to raise_error(ArgumentError)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "#first" do
|
63
|
+
context "when given an epsilon token" do
|
64
|
+
it "generates an empty set" do
|
65
|
+
expect(subject.first(epsilon)).to eq Set.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when given a terminal" do
|
70
|
+
it "generates a set" do
|
71
|
+
expect(subject.first(terminal)).to eq [terminal].to_set
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when given an array" do
|
76
|
+
let(:terminal2) { token(:terminal, :TERMINAL2) }
|
77
|
+
|
78
|
+
it "generates a set" do
|
79
|
+
expect(subject.first([epsilon, terminal])).
|
80
|
+
to eq [terminal].to_set
|
81
|
+
expect(subject.first([terminal, terminal2])).
|
82
|
+
to eq [terminal].to_set
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when given a nonterminal" do
|
87
|
+
let(:grammar) { with_recognizer }
|
88
|
+
let(:nonterminal) { token(:nonterminal, :e) }
|
89
|
+
|
90
|
+
it "generates a set" do
|
91
|
+
expect(subject.first(nonterminal)).
|
92
|
+
to eq [token(:terminal, :IDENT), token(:terminal, :STAR, "*")].to_set
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when given a bad argument" do
|
97
|
+
it "raises an error" do
|
98
|
+
expect { subject.first(nil) }.to raise_error(ArgumentError)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "#follow" do
|
104
|
+
context "when given a bad argument" do
|
105
|
+
it "raises an error" do
|
106
|
+
expect { subject.follow(nil) }.to raise_error(ArgumentError)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "when given a nonterminal" do
|
111
|
+
let(:grammar) { with_recognizer }
|
112
|
+
let(:nonterminal) { token(:nonterminal, :l) }
|
113
|
+
|
114
|
+
before do
|
115
|
+
subject.productions.merge grammar.productions.values.flatten
|
116
|
+
end
|
117
|
+
|
118
|
+
it "generates a set" do
|
119
|
+
expect(subject.follow(nonterminal)).to eq [
|
120
|
+
token(:terminal, :EQUALS, "="),
|
121
|
+
token(:terminal, :"$end")
|
122
|
+
].to_set
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def token(type, name = nil, value = nil, ttype = nil, id = nil)
|
130
|
+
type = Ace::Token.const_get(type.to_s.capitalize)
|
131
|
+
type.new(name, ttype, id, value)
|
132
|
+
end
|
133
|
+
end
|
@@ -1,49 +1,50 @@
|
|
1
|
-
describe Template do
|
2
|
-
|
3
|
-
let(:content) { "hello {{ world }} test" }
|
4
|
-
|
5
|
-
subject { Template.new(content) }
|
6
|
-
|
7
|
-
it "generates ruby code" do
|
8
|
-
expect(subject.parse).to eq %Q(
|
9
|
-
end
|
10
|
-
|
11
|
-
context "when the tag is on its own line" do
|
12
|
-
|
13
|
-
let :content do
|
14
|
-
<<-TEST
|
15
|
-
hello
|
16
|
-
{{= something }}
|
17
|
-
world
|
18
|
-
|
19
|
-
{{ thing }}
|
20
|
-
a
|
21
|
-
|
22
|
-
TEST
|
23
|
-
end
|
24
|
-
|
25
|
-
it "removes surrounding whitespace" do
|
26
|
-
expect(subject.parse).to eq <<-TEST
|
27
|
-
|
28
|
-
_out
|
29
|
-
_out <<
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
_out
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def object.
|
44
|
-
|
45
|
-
|
46
|
-
expect(
|
47
|
-
|
48
|
-
|
49
|
-
end
|
1
|
+
describe Template do
|
2
|
+
|
3
|
+
let(:content) { "hello {{ world }} test" }
|
4
|
+
|
5
|
+
subject { Template.new(content) }
|
6
|
+
|
7
|
+
it "generates ruby code" do
|
8
|
+
expect(subject.parse).to eq %Q(# encoding: utf-8\n_out ||= ""\n_out << "hello "\n world\n_out << " test"\n_out\n)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when the tag is on its own line" do
|
12
|
+
|
13
|
+
let :content do
|
14
|
+
<<-TEST
|
15
|
+
hello
|
16
|
+
{{= something }}
|
17
|
+
world
|
18
|
+
|
19
|
+
{{ thing }}
|
20
|
+
a
|
21
|
+
|
22
|
+
TEST
|
23
|
+
end
|
24
|
+
|
25
|
+
it "removes surrounding whitespace" do
|
26
|
+
expect(subject.parse).to eq <<-TEST
|
27
|
+
# encoding: utf-8
|
28
|
+
_out ||= ""
|
29
|
+
_out << "hello"
|
30
|
+
_out << begin
|
31
|
+
something
|
32
|
+
end.to_s
|
33
|
+
_out << "\\nworld\\n"
|
34
|
+
thing
|
35
|
+
_out << "\\na\\n\\n"
|
36
|
+
_out
|
37
|
+
TEST
|
38
|
+
end
|
39
|
+
|
40
|
+
it "runs in ruby" do
|
41
|
+
object = Object.new
|
42
|
+
result = nil
|
43
|
+
def object.something; "-" end
|
44
|
+
def object.thing; end
|
45
|
+
|
46
|
+
expect { result = object.instance_eval(subject.parse) }.to_not raise_error
|
47
|
+
expect(result).to eq "hello-\nworld\n\na\n\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/fixtures/simple.ace
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
%language <ruby>
|
2
|
-
|
3
|
-
%terminal IDENT
|
4
|
-
%terminal STAR "*"
|
5
|
-
%terminal EQUALS "="
|
6
|
-
|
7
|
-
%%
|
8
|
-
|
9
|
-
e: l EQUALS r
|
10
|
-
| r
|
11
|
-
| nothing
|
12
|
-
|
13
|
-
l: IDENT
|
14
|
-
| STAR r
|
15
|
-
|
16
|
-
r: l
|
17
|
-
|
18
|
-
%%
|
19
|
-
|
20
|
-
class SimpleParser
|
21
|
-
%{write}
|
22
|
-
end
|
1
|
+
%language <ruby>
|
2
|
+
|
3
|
+
%terminal IDENT
|
4
|
+
%terminal STAR "*"
|
5
|
+
%terminal EQUALS "="
|
6
|
+
|
7
|
+
%%
|
8
|
+
|
9
|
+
e: l EQUALS r
|
10
|
+
| r
|
11
|
+
| nothing
|
12
|
+
|
13
|
+
l: IDENT
|
14
|
+
| STAR r
|
15
|
+
|
16
|
+
r: l
|
17
|
+
|
18
|
+
%%
|
19
|
+
|
20
|
+
class SimpleParser
|
21
|
+
%{write}
|
22
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
Bundler.setup
|
4
|
-
|
5
|
-
require "timeout"
|
6
|
-
require "benchmark"
|
7
|
-
require "simplecov"
|
8
|
-
require "coveralls"
|
9
|
-
|
10
|
-
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
11
|
-
SimpleCov.start do
|
12
|
-
add_filter 'spec'
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
require "rspec/its"
|
17
|
-
require "antelope"
|
18
|
-
|
19
|
-
include Antelope
|
20
|
-
|
21
|
-
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
22
|
-
|
23
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
24
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
25
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
26
|
-
# loaded once.
|
27
|
-
#
|
28
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
29
|
-
RSpec.configure do |config|
|
30
|
-
config.run_all_when_everything_filtered = true
|
31
|
-
|
32
|
-
# Run specs in random order to surface order dependencies. If you find an
|
33
|
-
# order dependency and want to debug it, you can fix the order by providing
|
34
|
-
# the seed, which is printed after each run.
|
35
|
-
# --seed 1234
|
36
|
-
config.order = 'random'
|
37
|
-
config.include BenchmarkHelper
|
38
|
-
config.include GrammarHelper
|
39
|
-
end
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require "timeout"
|
6
|
+
require "benchmark"
|
7
|
+
require "simplecov"
|
8
|
+
require "coveralls"
|
9
|
+
|
10
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter 'spec'
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
require "rspec/its"
|
17
|
+
require "antelope"
|
18
|
+
|
19
|
+
include Antelope
|
20
|
+
|
21
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
22
|
+
|
23
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
24
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
25
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
26
|
+
# loaded once.
|
27
|
+
#
|
28
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.run_all_when_everything_filtered = true
|
31
|
+
|
32
|
+
# Run specs in random order to surface order dependencies. If you find an
|
33
|
+
# order dependency and want to debug it, you can fix the order by providing
|
34
|
+
# the seed, which is printed after each run.
|
35
|
+
# --seed 1234
|
36
|
+
config.order = 'random'
|
37
|
+
config.include BenchmarkHelper
|
38
|
+
config.include GrammarHelper
|
39
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module BenchmarkHelper
|
2
|
-
def benchmark
|
3
|
-
Benchmark.realtime(&Proc.new)
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module BenchmarkHelper
|
2
|
+
def benchmark
|
3
|
+
Benchmark.realtime(&Proc.new)
|
4
|
+
end
|
5
|
+
end
|