antlr3 1.7.5 → 1.8.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.
- data/java/RubyTarget.java +50 -16
- data/java/antlr-full-3.2.1.jar +0 -0
- data/lib/antlr3/streams.rb +82 -41
- data/lib/antlr3/template/group-file-lexer.rb +59 -59
- data/lib/antlr3/template/group-file-parser.rb +6 -6
- data/lib/antlr3/test/functional.rb +64 -36
- data/lib/antlr3/version.rb +2 -2
- data/templates/Ruby.stg +1 -1
- data/test/functional/ast-output/auto-ast.rb +86 -86
- data/test/functional/ast-output/construction.rb +14 -15
- data/test/functional/ast-output/hetero-nodes.rb +63 -66
- data/test/functional/ast-output/rewrites.rb +119 -120
- data/test/functional/ast-output/tree-rewrite.rb +96 -96
- data/test/functional/debugging/debug-mode.rb +379 -379
- data/test/functional/debugging/profile-mode.rb +6 -6
- data/test/functional/debugging/rule-tracing.rb +4 -5
- data/test/functional/delegation/import.rb +32 -32
- data/test/functional/lexer/basic.rb +27 -27
- data/test/functional/lexer/filter-mode.rb +6 -7
- data/test/functional/lexer/nuances.rb +2 -3
- data/test/functional/lexer/properties.rb +7 -8
- data/test/functional/lexer/syn-pred.rb +1 -2
- data/test/functional/lexer/xml.rb +3 -3
- data/test/functional/main/main-scripts.rb +37 -37
- data/test/functional/parser/actions.rb +8 -8
- data/test/functional/parser/backtracking.rb +1 -2
- data/test/functional/parser/basic.rb +10 -10
- data/test/functional/parser/calc.rb +9 -9
- data/test/functional/parser/ll-star.rb +3 -3
- data/test/functional/parser/nuances.rb +4 -5
- data/test/functional/parser/predicates.rb +3 -4
- data/test/functional/parser/properties.rb +14 -14
- data/test/functional/parser/rule-methods.rb +8 -7
- data/test/functional/parser/scopes.rb +15 -16
- data/test/functional/template-output/template-output.rb +1 -1
- data/test/functional/token-rewrite/basic.rb +60 -61
- data/test/functional/token-rewrite/via-parser.rb +3 -4
- data/test/functional/tree-parser/basic.rb +30 -31
- data/test/unit/test-streams.rb +10 -10
- data/test/unit/test-template.rb +1 -1
- metadata +2 -2
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'antlr3/test/functional'
|
5
5
|
|
6
6
|
class TestCalcParser < ANTLR3::Test::Functional
|
7
|
-
inline_grammar(<<-'END')
|
7
|
+
inline_grammar( <<-'END' )
|
8
8
|
grammar TestCalc;
|
9
9
|
options { language = Ruby; }
|
10
10
|
|
@@ -64,12 +64,12 @@ class TestCalcParser < ANTLR3::Test::Functional
|
|
64
64
|
WS: (' ' | '\n' | '\t')+ {$channel = HIDDEN};
|
65
65
|
END
|
66
66
|
|
67
|
-
def evaluate(expression)
|
67
|
+
def evaluate( expression )
|
68
68
|
lexer = TestCalc::Lexer.new( expression )
|
69
69
|
parser = TestCalc::Parser.new lexer
|
70
70
|
value = parser.evaluate
|
71
71
|
errors = parser.reported_errors
|
72
|
-
return [value, errors]
|
72
|
+
return [ value, errors ]
|
73
73
|
end
|
74
74
|
|
75
75
|
tests = %[
|
@@ -77,14 +77,14 @@ class TestCalcParser < ANTLR3::Test::Functional
|
|
77
77
|
1 + 2 * 3 = 7
|
78
78
|
10 / 2 = 5
|
79
79
|
6 + 2*(3+1) - 4 = 10
|
80
|
-
].strip!.split(/\n/).map { |line|
|
81
|
-
expr, val = line.strip.split(/\s+=\s+/, 2)
|
82
|
-
[expr, Integer(val)]
|
80
|
+
].strip!.split( /\n/ ).map { |line|
|
81
|
+
expr, val = line.strip.split( /\s+=\s+/, 2 )
|
82
|
+
[ expr, Integer( val ) ]
|
83
83
|
}
|
84
84
|
|
85
85
|
tests.each do |expression, true_value|
|
86
|
-
example "should parse '#{expression}'" do
|
87
|
-
parser_value, errors = evaluate(expression)
|
86
|
+
example "should parse '#{ expression }'" do
|
87
|
+
parser_value, errors = evaluate( expression )
|
88
88
|
parser_value.should == true_value
|
89
89
|
end
|
90
90
|
end
|
@@ -92,7 +92,7 @@ class TestCalcParser < ANTLR3::Test::Functional
|
|
92
92
|
example "badly formed input" do
|
93
93
|
val, errors = evaluate "6 - (2*1"
|
94
94
|
|
95
|
-
errors.should have(1).thing
|
95
|
+
errors.should have( 1 ).thing
|
96
96
|
errors.first.should =~ /mismatched/
|
97
97
|
end
|
98
98
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'antlr3/test/functional'
|
5
5
|
|
6
6
|
class TestLLStarParser < ANTLR3::Test::Functional
|
7
|
-
inline_grammar(<<-'END')
|
7
|
+
inline_grammar( <<-'END' )
|
8
8
|
grammar LLStar;
|
9
9
|
|
10
10
|
options { language = Ruby; }
|
@@ -117,7 +117,7 @@ class TestLLStarParser < ANTLR3::Test::Functional
|
|
117
117
|
|
118
118
|
|
119
119
|
example "parsing with a LL(*) grammar" do
|
120
|
-
lexer = LLStar::Lexer.new(<<-'END'.fixed_indent(0))
|
120
|
+
lexer = LLStar::Lexer.new( <<-'END'.fixed_indent( 0 ) )
|
121
121
|
char c;
|
122
122
|
int x;
|
123
123
|
|
@@ -134,7 +134,7 @@ class TestLLStarParser < ANTLR3::Test::Functional
|
|
134
134
|
parser = LLStar::Parser.new lexer
|
135
135
|
|
136
136
|
parser.program
|
137
|
-
parser.output.should == <<-'END'.fixed_indent(0)
|
137
|
+
parser.output.should == <<-'END'.fixed_indent( 0 )
|
138
138
|
bar is a declaration
|
139
139
|
foo is a definition
|
140
140
|
END
|
@@ -5,7 +5,7 @@ require 'antlr3/test/functional'
|
|
5
5
|
|
6
6
|
class TestEmptyAlternative < ANTLR3::Test::Functional
|
7
7
|
|
8
|
-
inline_grammar(<<-'END')
|
8
|
+
inline_grammar( <<-'END' )
|
9
9
|
grammar EmptyAlt;
|
10
10
|
options {
|
11
11
|
language = Ruby;
|
@@ -34,7 +34,7 @@ end
|
|
34
34
|
|
35
35
|
class TestSubrulePrediction < ANTLR3::Test::Functional
|
36
36
|
|
37
|
-
inline_grammar(<<-'END')
|
37
|
+
inline_grammar( <<-'END' )
|
38
38
|
grammar Subrule;
|
39
39
|
options {
|
40
40
|
language = Ruby;
|
@@ -65,7 +65,7 @@ end
|
|
65
65
|
|
66
66
|
class TestSpecialStates < ANTLR3::Test::Functional
|
67
67
|
|
68
|
-
inline_grammar(<<-'END')
|
68
|
+
inline_grammar( <<-'END' )
|
69
69
|
grammar SpecialStates;
|
70
70
|
options { language = Ruby; }
|
71
71
|
|
@@ -121,7 +121,7 @@ end
|
|
121
121
|
|
122
122
|
class TestDFABug < ANTLR3::Test::Functional
|
123
123
|
|
124
|
-
inline_grammar(<<-'END')
|
124
|
+
inline_grammar( <<-'END' )
|
125
125
|
grammar DFABug;
|
126
126
|
options {
|
127
127
|
language = Ruby;
|
@@ -162,4 +162,3 @@ class TestDFABug < ANTLR3::Test::Functional
|
|
162
162
|
end
|
163
163
|
|
164
164
|
end
|
165
|
-
|
@@ -5,7 +5,7 @@ require 'antlr3/test/functional'
|
|
5
5
|
|
6
6
|
class TestPredicateHoist < ANTLR3::Test::Functional
|
7
7
|
|
8
|
-
inline_grammar(<<-'END')
|
8
|
+
inline_grammar( <<-'END' )
|
9
9
|
grammar TestHoist;
|
10
10
|
options {
|
11
11
|
language = Ruby;
|
@@ -68,7 +68,7 @@ end
|
|
68
68
|
|
69
69
|
class TestSyntacticPredicate < ANTLR3::Test::Functional
|
70
70
|
|
71
|
-
inline_grammar(<<-'END')
|
71
|
+
inline_grammar( <<-'END' )
|
72
72
|
grammar SyntacticPredicate;
|
73
73
|
options {
|
74
74
|
language = Ruby;
|
@@ -95,9 +95,8 @@ class TestSyntacticPredicate < ANTLR3::Test::Functional
|
|
95
95
|
END
|
96
96
|
|
97
97
|
example "rule with syntactic predicate" do
|
98
|
-
lexer = SyntacticPredicate::Lexer.new(' +foo>')
|
98
|
+
lexer = SyntacticPredicate::Lexer.new( ' +foo>' )
|
99
99
|
parser = SyntacticPredicate::Parser.new lexer
|
100
100
|
events = parser.a
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
@@ -5,7 +5,7 @@ require 'antlr3/test/functional'
|
|
5
5
|
|
6
6
|
class TestRulePropertyReference < ANTLR3::Test::Functional
|
7
7
|
|
8
|
-
inline_grammar(<<-'END')
|
8
|
+
inline_grammar( <<-'END' )
|
9
9
|
grammar RuleProperties;
|
10
10
|
options { language = Ruby; }
|
11
11
|
|
@@ -52,7 +52,7 @@ end
|
|
52
52
|
|
53
53
|
class TestLabels < ANTLR3::Test::Functional
|
54
54
|
|
55
|
-
inline_grammar(<<-'END')
|
55
|
+
inline_grammar( <<-'END' )
|
56
56
|
grammar Labels;
|
57
57
|
options { language = Ruby; }
|
58
58
|
|
@@ -88,13 +88,13 @@ class TestLabels < ANTLR3::Test::Functional
|
|
88
88
|
parser = Labels::Parser.new lexer
|
89
89
|
ids, w = parser.a
|
90
90
|
|
91
|
-
ids.should have(6).things
|
92
|
-
ids[0].text.should == 'a'
|
93
|
-
ids[1].text.should == 'b'
|
94
|
-
ids[2].text.should == 'c'
|
95
|
-
ids[3].text.should == '1'
|
96
|
-
ids[4].text.should == '2'
|
97
|
-
ids[5].text.should == 'A'
|
91
|
+
ids.should have( 6 ).things
|
92
|
+
ids[ 0 ].text.should == 'a'
|
93
|
+
ids[ 1 ].text.should == 'b'
|
94
|
+
ids[ 2 ].text.should == 'c'
|
95
|
+
ids[ 3 ].text.should == '1'
|
96
|
+
ids[ 4 ].text.should == '2'
|
97
|
+
ids[ 5 ].text.should == 'A'
|
98
98
|
|
99
99
|
w.text.should == 'GNU1'
|
100
100
|
end
|
@@ -105,7 +105,7 @@ end
|
|
105
105
|
|
106
106
|
class TestTokenLabelReference < ANTLR3::Test::Functional
|
107
107
|
|
108
|
-
inline_grammar(<<-'END')
|
108
|
+
inline_grammar( <<-'END' )
|
109
109
|
grammar TokenLabels;
|
110
110
|
options {
|
111
111
|
language = Ruby;
|
@@ -162,7 +162,7 @@ class TestTokenLabelReference < ANTLR3::Test::Functional
|
|
162
162
|
lexer = TokenLabels::Lexer.new( ' a' )
|
163
163
|
parser = TokenLabels::Parser.new lexer
|
164
164
|
tk = parser.a
|
165
|
-
tk.should == [
|
165
|
+
tk.should == [
|
166
166
|
'a', TokenLabels::TokenData::A, 'A',
|
167
167
|
1, 3, 1, :default
|
168
168
|
]
|
@@ -173,7 +173,7 @@ end
|
|
173
173
|
|
174
174
|
class TestRuleLabelReference < ANTLR3::Test::Functional
|
175
175
|
|
176
|
-
inline_grammar(<<-'END')
|
176
|
+
inline_grammar( <<-'END' )
|
177
177
|
grammar RuleLabelReference;
|
178
178
|
options {language = Ruby;}
|
179
179
|
|
@@ -224,7 +224,7 @@ end
|
|
224
224
|
|
225
225
|
class TestReferenceDoesntSetChannel < ANTLR3::Test::Functional
|
226
226
|
|
227
|
-
inline_grammar(<<-'END')
|
227
|
+
inline_grammar( <<-'END' )
|
228
228
|
grammar ReferenceSetChannel;
|
229
229
|
options {language=Ruby;}
|
230
230
|
a returns [foo]: A EOF { $foo = '\%s, channel=\%p' \% [$A.text, $A.channel]; } ;
|
@@ -234,7 +234,7 @@ class TestReferenceDoesntSetChannel < ANTLR3::Test::Functional
|
|
234
234
|
END
|
235
235
|
|
236
236
|
example 'verifying that a token reference does not set its channel' do
|
237
|
-
lexer = ReferenceSetChannel::Lexer.new("- 34")
|
237
|
+
lexer = ReferenceSetChannel::Lexer.new( "- 34" )
|
238
238
|
parser = ReferenceSetChannel::Parser.new lexer
|
239
239
|
parser.a.should == "- 34, channel=:default"
|
240
240
|
end
|
@@ -5,7 +5,7 @@ require 'antlr3/test/functional'
|
|
5
5
|
|
6
6
|
class TestParameters < ANTLR3::Test::Functional
|
7
7
|
|
8
|
-
inline_grammar(<<-'END')
|
8
|
+
inline_grammar( <<-'END' )
|
9
9
|
grammar Parameters;
|
10
10
|
options {
|
11
11
|
language = Ruby;
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
|
55
55
|
class TestMultipleReturnValues < ANTLR3::Test::Functional
|
56
56
|
|
57
|
-
inline_grammar(<<-'END')
|
57
|
+
inline_grammar( <<-'END' )
|
58
58
|
grammar MultipleReturnValues;
|
59
59
|
options { language = Ruby; }
|
60
60
|
@parser::members {
|
@@ -109,7 +109,7 @@ end
|
|
109
109
|
|
110
110
|
|
111
111
|
class TestRuleVisibility < ANTLR3::Test::Functional
|
112
|
-
inline_grammar(<<-'END')
|
112
|
+
inline_grammar( <<-'END' )
|
113
113
|
grammar RuleVisibility;
|
114
114
|
options { language=Ruby; }
|
115
115
|
|
@@ -123,10 +123,11 @@ class TestRuleVisibility < ANTLR3::Test::Functional
|
|
123
123
|
END
|
124
124
|
|
125
125
|
example 'using visibility modifiers on rules' do
|
126
|
-
|
127
|
-
|
128
|
-
RuleVisibility::Parser.
|
126
|
+
mname = RUBY_VERSION =~ /^1\.9/ ? proc { | n | n.to_sym } : proc { | n | n.to_s }
|
127
|
+
|
128
|
+
RuleVisibility::Parser.public_instance_methods.should include( mname[ 'a' ] )
|
129
|
+
RuleVisibility::Parser.protected_instance_methods.should include( mname[ 'c' ] )
|
130
|
+
RuleVisibility::Parser.private_instance_methods.should include( mname[ 'b' ] )
|
129
131
|
end
|
130
132
|
|
131
133
|
end
|
132
|
-
|
@@ -5,7 +5,7 @@ require 'antlr3/test/functional'
|
|
5
5
|
|
6
6
|
class TestScopes1 < ANTLR3::Test::Functional
|
7
7
|
|
8
|
-
inline_grammar(<<-'END')
|
8
|
+
inline_grammar( <<-'END' )
|
9
9
|
grammar SimpleScope;
|
10
10
|
|
11
11
|
options {
|
@@ -34,7 +34,7 @@ class TestScopes1 < ANTLR3::Test::Functional
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class TestScopes2 < ANTLR3::Test::Functional
|
37
|
-
inline_grammar(<<-'END')
|
37
|
+
inline_grammar( <<-'END' )
|
38
38
|
grammar LotsaScopes;
|
39
39
|
|
40
40
|
options {
|
@@ -175,25 +175,25 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
175
175
|
END
|
176
176
|
|
177
177
|
example "parsing 'foobar' with rule a" do
|
178
|
-
lexer = LotsaScopes::Lexer.new("foobar")
|
178
|
+
lexer = LotsaScopes::Lexer.new( "foobar" )
|
179
179
|
parser = LotsaScopes::Parser.new lexer
|
180
180
|
parser.a
|
181
181
|
end
|
182
182
|
|
183
183
|
example "failing to parse 'foobar' with rule b[false]" do
|
184
|
-
lexer = LotsaScopes::Lexer.new("foobar")
|
184
|
+
lexer = LotsaScopes::Lexer.new( "foobar" )
|
185
185
|
parser = LotsaScopes::Parser.new lexer
|
186
|
-
proc { parser.b(false) }.should raise_error(ANTLR3::RecognitionError)
|
186
|
+
proc { parser.b( false ) }.should raise_error( ANTLR3::RecognitionError )
|
187
187
|
end
|
188
188
|
|
189
189
|
example "parsing 'foobar' with rule b[true]" do
|
190
|
-
lexer = LotsaScopes::Lexer.new("foobar")
|
190
|
+
lexer = LotsaScopes::Lexer.new( "foobar" )
|
191
191
|
parser = LotsaScopes::Parser.new lexer
|
192
|
-
parser.b(true)
|
192
|
+
parser.b( true )
|
193
193
|
end
|
194
194
|
|
195
195
|
example "parsing a decl block with rule c" do
|
196
|
-
lexer = LotsaScopes::Lexer.new(<<-END.here_indent!)
|
196
|
+
lexer = LotsaScopes::Lexer.new( <<-END.here_indent! )
|
197
197
|
| {
|
198
198
|
| int i;
|
199
199
|
| int j;
|
@@ -203,13 +203,13 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
203
203
|
parser = LotsaScopes::Parser.new lexer
|
204
204
|
|
205
205
|
symbols = parser.c
|
206
|
-
symbols.should have(2).things
|
206
|
+
symbols.should have( 2 ).things
|
207
207
|
symbols.should include 'i'
|
208
208
|
symbols.should include 'j'
|
209
209
|
end
|
210
210
|
|
211
211
|
example "failing to parse undeclared symbols with rule c" do
|
212
|
-
lexer = LotsaScopes::Lexer.new(<<-END.here_indent!)
|
212
|
+
lexer = LotsaScopes::Lexer.new( <<-END.here_indent! )
|
213
213
|
| {
|
214
214
|
| int i;
|
215
215
|
| int j;
|
@@ -223,7 +223,7 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
223
223
|
end
|
224
224
|
|
225
225
|
example "parsing nested declaration blocks" do
|
226
|
-
lexer = LotsaScopes::Lexer.new(<<-END.here_indent!)
|
226
|
+
lexer = LotsaScopes::Lexer.new( <<-END.here_indent! )
|
227
227
|
| {
|
228
228
|
| int i;
|
229
229
|
| int j;
|
@@ -238,13 +238,13 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
238
238
|
parser = LotsaScopes::Parser.new lexer
|
239
239
|
|
240
240
|
symbols = parser.d
|
241
|
-
symbols.should have(2).things
|
241
|
+
symbols.should have( 2 ).things
|
242
242
|
symbols.should include 'i'
|
243
243
|
symbols.should include 'j'
|
244
244
|
end
|
245
245
|
|
246
246
|
example "parsing a deeply nested set of blocks with rule e" do
|
247
|
-
lexer = LotsaScopes::Lexer.new(<<-END.here_indent!)
|
247
|
+
lexer = LotsaScopes::Lexer.new( <<-END.here_indent! )
|
248
248
|
| { { { { 12 } } } }
|
249
249
|
END
|
250
250
|
|
@@ -253,7 +253,7 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
253
253
|
end
|
254
254
|
|
255
255
|
example "parsing a deeply nested set of blocks with rule f" do
|
256
|
-
lexer = LotsaScopes::Lexer.new(<<-END.here_indent!)
|
256
|
+
lexer = LotsaScopes::Lexer.new( <<-END.here_indent! )
|
257
257
|
| { { { { 12 } } } }
|
258
258
|
END
|
259
259
|
|
@@ -262,7 +262,7 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
262
262
|
end
|
263
263
|
|
264
264
|
example "parsing a 2-level nested set of blocks with rule f" do
|
265
|
-
lexer = LotsaScopes::Lexer.new(<<-END.here_indent!)
|
265
|
+
lexer = LotsaScopes::Lexer.new( <<-END.here_indent! )
|
266
266
|
| { { 12 } }
|
267
267
|
END
|
268
268
|
parser = LotsaScopes::Parser.new lexer
|
@@ -271,4 +271,3 @@ class TestScopes2 < ANTLR3::Test::Functional
|
|
271
271
|
end
|
272
272
|
|
273
273
|
end
|
274
|
-
|
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'antlr3/test/functional'
|
5
5
|
|
6
6
|
class TestRewritingLexerOutputDirectly < ANTLR3::Test::Functional
|
7
|
-
inline_grammar(<<-'END')
|
7
|
+
inline_grammar( <<-'END' )
|
8
8
|
lexer grammar SimpleRewriting;
|
9
9
|
options {
|
10
10
|
language = Ruby;
|
@@ -15,23 +15,23 @@ class TestRewritingLexerOutputDirectly < ANTLR3::Test::Functional
|
|
15
15
|
C: 'c';
|
16
16
|
END
|
17
17
|
|
18
|
-
def rewrite(input, expected)
|
19
|
-
lexer = SimpleRewriting::Lexer.new(input)
|
20
|
-
tokens = ANTLR3::TokenRewriteStream.new(lexer)
|
21
|
-
yield(tokens)
|
18
|
+
def rewrite( input, expected )
|
19
|
+
lexer = SimpleRewriting::Lexer.new( input )
|
20
|
+
tokens = ANTLR3::TokenRewriteStream.new( lexer )
|
21
|
+
yield( tokens )
|
22
22
|
tokens.render.should == expected
|
23
|
-
return(tokens)
|
23
|
+
return( tokens )
|
24
24
|
end
|
25
25
|
|
26
26
|
example 'insert before' do
|
27
27
|
rewrite( 'abc', '0abc' ) do |stream|
|
28
|
-
stream.insert_before(0, '0')
|
28
|
+
stream.insert_before( 0, '0' )
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
example 'insert after last index' do
|
33
33
|
rewrite( 'abc', 'abcx' ) do |stream|
|
34
|
-
stream.insert_after(2, 'x')
|
34
|
+
stream.insert_after( 2, 'x' )
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -44,7 +44,7 @@ class TestRewritingLexerOutputDirectly < ANTLR3::Test::Functional
|
|
44
44
|
|
45
45
|
example 'replace index 0' do
|
46
46
|
rewrite( 'abc', 'xbc' ) do |stream|
|
47
|
-
stream.replace(0, 'x')
|
47
|
+
stream.replace( 0, 'x' )
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -56,7 +56,7 @@ class TestRewritingLexerOutputDirectly < ANTLR3::Test::Functional
|
|
56
56
|
|
57
57
|
example 'replace last index' do
|
58
58
|
rewrite( 'abc', 'abx' ) do |stream|
|
59
|
-
stream.replace(2, 'x')
|
59
|
+
stream.replace( 2, 'x' )
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -97,129 +97,129 @@ class TestRewritingLexerOutputDirectly < ANTLR3::Test::Functional
|
|
97
97
|
|
98
98
|
example 'insert middle index' do
|
99
99
|
rewrite( "abc", "ayxbc" ) do |stream|
|
100
|
-
stream.insert_before(1, "x")
|
101
|
-
stream.insert_before(1, "y")
|
100
|
+
stream.insert_before( 1, "x" )
|
101
|
+
stream.insert_before( 1, "y" )
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
example 'insert then replace index0' do
|
106
106
|
rewrite( "abc", "zbc" ) do |stream|
|
107
|
-
stream.insert_before(0, "x")
|
108
|
-
stream.insert_before(0, "y")
|
109
|
-
stream.replace(0, "z")
|
107
|
+
stream.insert_before( 0, "x" )
|
108
|
+
stream.insert_before( 0, "y" )
|
109
|
+
stream.replace( 0, "z" )
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
example 'replace then insert before last index' do
|
114
114
|
rewrite( "abc", "abyx" ) do |stream|
|
115
|
-
stream.replace(2, "x")
|
116
|
-
stream.insert_before(2, "y")
|
115
|
+
stream.replace( 2, "x" )
|
116
|
+
stream.insert_before( 2, "y" )
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
example 'insert then replace last index' do
|
121
121
|
rewrite( "abc", "abx" ) do |stream|
|
122
|
-
stream.insert_before(2, "y")
|
123
|
-
stream.replace(2, "x")
|
122
|
+
stream.insert_before( 2, "y" )
|
123
|
+
stream.replace( 2, "x" )
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
example 'replace then insert after last index' do
|
128
128
|
rewrite( "abc", "abxy" ) do |stream|
|
129
|
-
stream.replace(2, "x")
|
130
|
-
stream.insert_after(2, "y")
|
129
|
+
stream.replace( 2, "x" )
|
130
|
+
stream.insert_after( 2, "y" )
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
134
|
example 'replace range then insert at left edge' do
|
135
135
|
rewrite( "abcccba", "abyxba" ) do |stream|
|
136
|
-
stream.replace(2, 4, "x")
|
137
|
-
stream.insert_before(2, "y")
|
136
|
+
stream.replace( 2, 4, "x" )
|
137
|
+
stream.insert_before( 2, "y" )
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
141
|
example 'replace range then insert after right edge' do
|
142
142
|
rewrite( "abcccba", "abxyba" ) do |stream|
|
143
|
-
stream.replace(2, 4, "x")
|
144
|
-
stream.insert_after(4, "y")
|
143
|
+
stream.replace( 2, 4, "x" )
|
144
|
+
stream.insert_after( 4, "y" )
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
example 'replace all' do
|
149
149
|
rewrite( "abcccba", "x" ) do |stream|
|
150
|
-
stream.replace(0, 6, "x")
|
150
|
+
stream.replace( 0, 6, "x" )
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
example 'replace single middle then overlapping superset' do
|
155
155
|
rewrite( "abcba", "fooa" ) do |stream|
|
156
|
-
stream.replace(2, 2, "xyz")
|
157
|
-
stream.replace(0, 3, "foo")
|
156
|
+
stream.replace( 2, 2, "xyz" )
|
157
|
+
stream.replace( 0, 3, "foo" )
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
161
|
example 'combine inserts' do
|
162
162
|
rewrite( "abc", "yxabc" ) do |stream|
|
163
|
-
stream.insert_before(0, "x")
|
164
|
-
stream.insert_before(0, "y")
|
163
|
+
stream.insert_before( 0, "x" )
|
164
|
+
stream.insert_before( 0, "y" )
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
example 'combine3 inserts' do
|
169
169
|
rewrite( "abc", "yazxbc" ) do |stream|
|
170
|
-
stream.insert_before(1, "x")
|
171
|
-
stream.insert_before(0, "y")
|
172
|
-
stream.insert_before(1, "z")
|
170
|
+
stream.insert_before( 1, "x" )
|
171
|
+
stream.insert_before( 0, "y" )
|
172
|
+
stream.insert_before( 1, "z" )
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
176
|
example 'disjoint inserts' do
|
177
177
|
rewrite( "abc", "zaxbyc" ) do |stream|
|
178
|
-
stream.insert_before(1, "x")
|
179
|
-
stream.insert_before(2, "y")
|
180
|
-
stream.insert_before(0, "z")
|
178
|
+
stream.insert_before( 1, "x" )
|
179
|
+
stream.insert_before( 2, "y" )
|
180
|
+
stream.insert_before( 0, "z" )
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
184
|
example 'leave alone disjoint insert' do
|
185
185
|
rewrite( "abcc", "axbfoo" ) do |stream|
|
186
|
-
stream.insert_before(1, "x")
|
187
|
-
stream.replace(2, 3, "foo")
|
186
|
+
stream.insert_before( 1, "x" )
|
187
|
+
stream.replace( 2, 3, "foo" )
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
191
|
example 'leave alone disjoint insert2' do
|
192
192
|
rewrite( "abcc", "axbfoo" ) do |stream|
|
193
|
-
stream.replace(2, 3, "foo")
|
194
|
-
stream.insert_before(1, "x")
|
193
|
+
stream.replace( 2, 3, "foo" )
|
194
|
+
stream.insert_before( 1, "x" )
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
198
|
example 'combine insert on left with delete' do
|
199
199
|
rewrite( "abc", "z" ) do |stream|
|
200
|
-
stream.delete(0, 2)
|
201
|
-
stream.insert_before(0, "z")
|
200
|
+
stream.delete( 0, 2 )
|
201
|
+
stream.insert_before( 0, "z" )
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
example 'overlapping replace' do
|
206
206
|
rewrite( "abcc", "bar" ) do |stream|
|
207
|
-
stream.replace(1, 2, "foo")
|
208
|
-
stream.replace(0, 3, "bar")
|
207
|
+
stream.replace( 1, 2, "foo" )
|
208
|
+
stream.replace( 0, 3, "bar" )
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
212
|
example 'overlapping replace3' do
|
213
213
|
rewrite( "abcc", "barc" ) do |stream|
|
214
|
-
stream.replace(1, 2, "foo")
|
215
|
-
stream.replace(0, 2, "bar")
|
214
|
+
stream.replace( 1, 2, "foo" )
|
215
|
+
stream.replace( 0, 2, "bar" )
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
219
|
example 'overlapping replace 4' do
|
220
220
|
rewrite( "abcc", "abar" ) do |stream|
|
221
|
-
stream.replace(1, 2, "foo")
|
222
|
-
stream.replace(1, 3, "bar")
|
221
|
+
stream.replace( 1, 2, "foo" )
|
222
|
+
stream.replace( 1, 3, "bar" )
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
@@ -286,9 +286,9 @@ class TestRewritingWithTokenStream2 < ANTLR3::Test::Functional
|
|
286
286
|
WS : ' '+;
|
287
287
|
END
|
288
288
|
|
289
|
-
def rewrite(input)
|
290
|
-
lexer = SimpleRewriting2::Lexer.new(input)
|
291
|
-
ANTLR3::TokenRewriteStream.new(lexer)
|
289
|
+
def rewrite( input )
|
290
|
+
lexer = SimpleRewriting2::Lexer.new( input )
|
291
|
+
ANTLR3::TokenRewriteStream.new( lexer )
|
292
292
|
end
|
293
293
|
|
294
294
|
example 'rendering over a range' do
|
@@ -296,8 +296,8 @@ class TestRewritingWithTokenStream2 < ANTLR3::Test::Functional
|
|
296
296
|
stream.replace 4, 8, '0'
|
297
297
|
stream.original_string.should == 'x = 3 * 0;'
|
298
298
|
stream.render.should == 'x = 0;'
|
299
|
-
stream.render(0, 9).should == 'x = 0;'
|
300
|
-
stream.render(4, 8).should == '0'
|
299
|
+
stream.render( 0, 9 ).should == 'x = 0;'
|
300
|
+
stream.render( 4, 8 ).should == '0'
|
301
301
|
end
|
302
302
|
|
303
303
|
example 'more rendering over a range' do
|
@@ -305,14 +305,13 @@ class TestRewritingWithTokenStream2 < ANTLR3::Test::Functional
|
|
305
305
|
stream.original_string.should == 'x = 3 * 0 + 2 * 0;'
|
306
306
|
stream.replace 4, 8, '0'
|
307
307
|
stream.render.should == 'x = 0 + 2 * 0;'
|
308
|
-
stream.render(0, 17).should == 'x = 0 + 2 * 0;'
|
309
|
-
stream.render(4, 8).should == '0'
|
310
|
-
stream.render(0, 8).should == 'x = 0'
|
311
|
-
stream.render(12, 16).should == '2 * 0'
|
312
|
-
stream.insert_after(17, '// comment')
|
313
|
-
stream.render(12, 17).should == '2 * 0;// comment'
|
314
|
-
stream.render(0, 8).should == 'x = 0'
|
308
|
+
stream.render( 0, 17 ).should == 'x = 0 + 2 * 0;'
|
309
|
+
stream.render( 4, 8 ).should == '0'
|
310
|
+
stream.render( 0, 8 ).should == 'x = 0'
|
311
|
+
stream.render( 12, 16 ).should == '2 * 0'
|
312
|
+
stream.insert_after( 17, '// comment' )
|
313
|
+
stream.render( 12, 17 ).should == '2 * 0;// comment'
|
314
|
+
stream.render( 0, 8 ).should == 'x = 0'
|
315
315
|
end
|
316
316
|
|
317
317
|
end
|
318
|
-
|