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
@@ -2,10 +2,10 @@
|
|
2
2
|
#
|
3
3
|
# GroupFile.g
|
4
4
|
#
|
5
|
-
# Generated using ANTLR version: 3.2.1-SNAPSHOT
|
6
|
-
# Ruby runtime library version: 1.7.
|
5
|
+
# Generated using ANTLR version: 3.2.1-SNAPSHOT Jun 18, 2010 05:38:11
|
6
|
+
# Ruby runtime library version: 1.7.5
|
7
7
|
# Input grammar file: GroupFile.g
|
8
|
-
# Generated at: 2010-
|
8
|
+
# Generated at: 2010-07-03 23:15:35
|
9
9
|
#
|
10
10
|
|
11
11
|
# ~~~> start load path setup
|
@@ -16,7 +16,7 @@ antlr_load_failed = proc do
|
|
16
16
|
load_path = $LOAD_PATH.map { |dir| ' - ' << dir }.join( $/ )
|
17
17
|
raise LoadError, <<-END.strip!
|
18
18
|
|
19
|
-
Failed to load the ANTLR3 runtime library (version 1.7.
|
19
|
+
Failed to load the ANTLR3 runtime library (version 1.7.5):
|
20
20
|
|
21
21
|
Ensure the library has been installed on your system and is available
|
22
22
|
on the load path. If rubygems is available on your system, this can
|
@@ -46,7 +46,7 @@ rescue LoadError
|
|
46
46
|
|
47
47
|
# 3: try to activate the antlr3 gem
|
48
48
|
begin
|
49
|
-
Gem.activate( 'antlr3', '~> 1.7.
|
49
|
+
Gem.activate( 'antlr3', '~> 1.7.5' )
|
50
50
|
rescue Gem::LoadError
|
51
51
|
antlr_load_failed.call
|
52
52
|
end
|
@@ -103,7 +103,7 @@ module GroupFile
|
|
103
103
|
include TokenData
|
104
104
|
|
105
105
|
begin
|
106
|
-
generated_using( "GroupFile.g", "3.2.1-SNAPSHOT
|
106
|
+
generated_using( "GroupFile.g", "3.2.1-SNAPSHOT Jun 18, 2010 05:38:11", "1.7.5" )
|
107
107
|
rescue NoMethodError => error
|
108
108
|
# ignore
|
109
109
|
end
|
@@ -22,28 +22,33 @@ module Location
|
|
22
22
|
File.dirname( test_path )
|
23
23
|
end
|
24
24
|
|
25
|
-
def local_path(*parts)
|
25
|
+
def local_path( *parts )
|
26
26
|
File.join( test_directory, *parts )
|
27
27
|
end
|
28
28
|
|
29
|
-
def output_directory(name = test_group)
|
29
|
+
def output_directory( name = test_group )
|
30
30
|
local_path( name )
|
31
31
|
end
|
32
32
|
|
33
33
|
end # module Location
|
34
34
|
|
35
35
|
module NameSpace
|
36
|
+
|
37
|
+
#
|
38
|
+
# import( ruby_file ) => [ new constants, ... ]
|
39
|
+
# Read the source code from the path given by +ruby_file+ and
|
40
|
+
# evaluate it within the class body. Return new constants
|
41
|
+
# created in the class after the evaluation.
|
42
|
+
#
|
36
43
|
def import( ruby_file )
|
37
44
|
constants_before = constants
|
38
|
-
class_eval(File.read(ruby_file), ruby_file, 1)
|
45
|
+
class_eval( File.read( ruby_file ), ruby_file, 1 )
|
39
46
|
constants - constants_before
|
40
47
|
end
|
41
48
|
|
42
|
-
def import_grammar_targets(grammar)
|
43
|
-
# reverse because delegates need to be in the test class's name
|
44
|
-
# space before the masters
|
49
|
+
def import_grammar_targets( grammar )
|
45
50
|
for file in grammar.target_files
|
46
|
-
import(file)
|
51
|
+
import( file )
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -59,22 +64,40 @@ module GrammarManager
|
|
59
64
|
end
|
60
65
|
module_function :add_default_compile_option
|
61
66
|
|
62
|
-
if ANTLR_JAR = ENV['ANTLR_JAR'] || ANTLR3.antlr_jar
|
67
|
+
if ANTLR_JAR = ENV[ 'ANTLR_JAR' ] || ANTLR3.antlr_jar
|
63
68
|
add_default_compile_option( :antlr_jar, ANTLR_JAR )
|
64
69
|
|
65
70
|
Grammar.global_dependency( ANTLR_JAR )
|
66
71
|
end
|
67
72
|
|
73
|
+
#
|
74
|
+
# Compile and load inline grammars on demand when their constant name
|
75
|
+
# is referenced in the code. This makes it easier to catch big errors
|
76
|
+
# quickly as test cases are run, instead of waiting a few minutes
|
77
|
+
# for all grammars to compile, and then discovering there's a big dumb
|
78
|
+
# error ruining most of the grammars.
|
79
|
+
#
|
68
80
|
def const_missing( name )
|
69
81
|
if g = grammars[ name.to_s ]
|
70
82
|
compile( g )
|
71
83
|
grammars.delete( name.to_s )
|
72
84
|
const_get( name )
|
85
|
+
elsif superclass.respond_to?( :grammars )
|
86
|
+
superclass.const_missing( name )
|
87
|
+
# ^-- for some reason, in ruby 1.9, rspec runs examples as instances of
|
88
|
+
# anonymous subclasses, of the actual test class, which messes up the
|
89
|
+
# assumptions made in the test code. Grammars are stored in @grammars belonging
|
90
|
+
# to the test class, so in 1.9, this method is called with @grammars = {}
|
91
|
+
# since it's a subclass
|
73
92
|
else
|
74
93
|
super
|
75
94
|
end
|
76
95
|
end
|
77
96
|
|
97
|
+
#
|
98
|
+
# An index of grammar file objects created in the test class
|
99
|
+
# (defined inline or loaded from a file)
|
100
|
+
#
|
78
101
|
def grammars
|
79
102
|
@grammars ||= {}
|
80
103
|
end
|
@@ -91,38 +114,39 @@ module GrammarManager
|
|
91
114
|
return grammar
|
92
115
|
end
|
93
116
|
|
94
|
-
def inline_grammar(source, options = {})
|
95
|
-
call = call_stack.find { |call| call.file != __FILE__}
|
117
|
+
def inline_grammar( source, options = {} )
|
118
|
+
call = call_stack.find { |call| call.file != __FILE__ }
|
96
119
|
grammar = Grammar.inline source,
|
97
120
|
:output_directory => output_directory,
|
98
|
-
:file => (call.file rescue nil),
|
99
|
-
:line => (call.line rescue nil)
|
100
|
-
register_grammar(grammar)
|
121
|
+
:file => ( call.file rescue nil ),
|
122
|
+
:line => ( call.line rescue nil )
|
123
|
+
register_grammar( grammar )
|
101
124
|
return grammar
|
102
125
|
end
|
103
126
|
|
104
|
-
def compile_options(defaults = nil)
|
127
|
+
def compile_options( defaults = nil )
|
105
128
|
@compile_options ||= DEFAULT_COMPILE_OPTIONS.clone
|
106
|
-
@compile_options.update(defaults) if defaults
|
129
|
+
@compile_options.update( defaults ) if defaults
|
107
130
|
return @compile_options
|
108
131
|
end
|
109
132
|
|
110
|
-
def compile(grammar, options = {})
|
111
|
-
grammar.compile( compile_options.merge(options) )
|
133
|
+
def compile( grammar, options = {} )
|
134
|
+
grammar.compile( compile_options.merge( options ) )
|
112
135
|
import_grammar_targets( grammar )
|
113
136
|
return grammar
|
114
137
|
end
|
115
138
|
|
116
139
|
private
|
117
140
|
|
118
|
-
def register_grammar(grammar)
|
141
|
+
def register_grammar( grammar )
|
119
142
|
name = grammar.name
|
143
|
+
@grammars ||= {}
|
120
144
|
|
121
|
-
if conflict = grammars[ name ] and conflict.source != grammar.source
|
122
|
-
message = "Multiple grammars exist with the name ``#{name}''"
|
145
|
+
if conflict = @grammars[ name ] and conflict.source != grammar.source
|
146
|
+
message = "Multiple grammars exist with the name ``#{ name }''"
|
123
147
|
raise NameError, message
|
124
148
|
else
|
125
|
-
grammars[ name ] = grammar
|
149
|
+
@grammars[ name ] = grammar
|
126
150
|
end
|
127
151
|
end
|
128
152
|
end # module GrammarManager
|
@@ -130,13 +154,17 @@ end # module GrammarManager
|
|
130
154
|
class Functional < ::Test::Unit::TestCase
|
131
155
|
extend GrammarManager
|
132
156
|
|
133
|
-
def self.inherited(klass)
|
157
|
+
def self.inherited( klass )
|
158
|
+
super
|
159
|
+
klass.test_path = call_stack[ 0 ].file
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.example( *args, &b )
|
134
163
|
super
|
135
|
-
klass.test_path = call_stack[0].file
|
136
164
|
end
|
137
165
|
|
138
|
-
def local_path(*args)
|
139
|
-
self.class.local_path(*args)
|
166
|
+
def local_path( *args )
|
167
|
+
self.class.local_path( *args )
|
140
168
|
end
|
141
169
|
|
142
170
|
def test_path
|
@@ -148,7 +176,7 @@ class Functional < ::Test::Unit::TestCase
|
|
148
176
|
end
|
149
177
|
|
150
178
|
def inline_grammar( source )
|
151
|
-
call = call_stack.find { |call| call.file != __FILE__}
|
179
|
+
call = call_stack.find { |call| call.file != __FILE__ }
|
152
180
|
grammar = Grammar.inline source,
|
153
181
|
:output_directory => output_directory,
|
154
182
|
:file => call.file,
|
@@ -165,7 +193,7 @@ end # class Functional
|
|
165
193
|
module CaptureOutput
|
166
194
|
require 'stringio'
|
167
195
|
def output_buffer
|
168
|
-
defined?(@output_buffer) or @output_buffer = StringIO.new('')
|
196
|
+
defined?( @output_buffer ) or @output_buffer = StringIO.new( '' )
|
169
197
|
@output_buffer
|
170
198
|
end
|
171
199
|
|
@@ -173,35 +201,35 @@ module CaptureOutput
|
|
173
201
|
output_buffer.string
|
174
202
|
end
|
175
203
|
|
176
|
-
def say(*args)
|
177
|
-
output_buffer.puts(*args)
|
204
|
+
def say( *args )
|
205
|
+
output_buffer.puts( *args )
|
178
206
|
end
|
179
207
|
|
180
|
-
def capture(*args)
|
181
|
-
output_buffer.write(*args)
|
208
|
+
def capture( *args )
|
209
|
+
output_buffer.write( *args )
|
182
210
|
end
|
183
211
|
end
|
184
212
|
|
185
213
|
module RaiseErrors
|
186
|
-
def emit_error_message(msg)
|
214
|
+
def emit_error_message( msg )
|
187
215
|
# do nothing
|
188
216
|
end
|
189
217
|
|
190
|
-
def report_error(error)
|
218
|
+
def report_error( error )
|
191
219
|
raise error
|
192
220
|
end
|
193
221
|
end
|
194
222
|
|
195
223
|
module CollectErrors
|
196
224
|
def reported_errors
|
197
|
-
defined?(@reported_errors) or @reported_errors = []
|
225
|
+
defined?( @reported_errors ) or @reported_errors = []
|
198
226
|
return @reported_errors
|
199
227
|
end
|
200
228
|
|
201
|
-
def emit_error_message(msg)
|
229
|
+
def emit_error_message( msg )
|
202
230
|
reported_errors << msg
|
203
231
|
end
|
204
232
|
end
|
205
233
|
|
206
234
|
end # module Test
|
207
|
-
end # module ANTLR3
|
235
|
+
end # module ANTLR3
|
data/lib/antlr3/version.rb
CHANGED
@@ -19,8 +19,8 @@ module ANTLR3
|
|
19
19
|
# The version data for the current state the library itself
|
20
20
|
#
|
21
21
|
MAJOR_VERSION = 1
|
22
|
-
MINOR_VERSION =
|
23
|
-
PATCH_VERSION =
|
22
|
+
MINOR_VERSION = 8
|
23
|
+
PATCH_VERSION = 0
|
24
24
|
VERSION = [ MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION ]
|
25
25
|
VERSION_STRING = VERSION.join( '.' ).freeze
|
26
26
|
|
data/templates/Ruby.stg
CHANGED
@@ -5,60 +5,60 @@ require 'antlr3/test/functional'
|
|
5
5
|
|
6
6
|
class TestAutoAST < ANTLR3::Test::Functional
|
7
7
|
|
8
|
-
def parse(grammar, rule, input, expect_errors = false)
|
9
|
-
@grammar = inline_grammar(grammar)
|
8
|
+
def parse( grammar, rule, input, expect_errors = false )
|
9
|
+
@grammar = inline_grammar( grammar )
|
10
10
|
compile_and_load @grammar
|
11
|
-
grammar_module = self.class.const_get(@grammar.name)
|
11
|
+
grammar_module = self.class.const_get( @grammar.name )
|
12
12
|
|
13
|
-
grammar_module::Lexer.send(:include, ANTLR3::Test::CollectErrors)
|
14
|
-
grammar_module::Lexer.send(:include, ANTLR3::Test::CaptureOutput)
|
15
|
-
grammar_module::Parser.send(:include, ANTLR3::Test::CollectErrors)
|
16
|
-
grammar_module::Parser.send(:include, ANTLR3::Test::CaptureOutput)
|
13
|
+
grammar_module::Lexer.send( :include, ANTLR3::Test::CollectErrors )
|
14
|
+
grammar_module::Lexer.send( :include, ANTLR3::Test::CaptureOutput )
|
15
|
+
grammar_module::Parser.send( :include, ANTLR3::Test::CollectErrors )
|
16
|
+
grammar_module::Parser.send( :include, ANTLR3::Test::CaptureOutput )
|
17
17
|
|
18
18
|
lexer = grammar_module::Lexer.new( input )
|
19
19
|
parser = grammar_module::Parser.new( lexer )
|
20
20
|
|
21
|
-
r = parser.send(rule)
|
21
|
+
r = parser.send( rule )
|
22
22
|
parser.reported_errors.should be_empty unless expect_errors
|
23
23
|
result = ''
|
24
24
|
|
25
25
|
unless r.nil?
|
26
|
-
result += r.result if r.respond_to?(:result)
|
26
|
+
result += r.result if r.respond_to?( :result )
|
27
27
|
result += r.tree.inspect if r.tree
|
28
28
|
end
|
29
|
-
return(expect_errors ? [result, parser.reported_errors] : result)
|
29
|
+
return( expect_errors ? [ result, parser.reported_errors ] : result )
|
30
30
|
end
|
31
31
|
|
32
|
-
def tree_parse(grammar, tree_grammar, rule, tree_rule, input)
|
33
|
-
@grammar = inline_grammar(grammar)
|
34
|
-
@tree_grammar = inline_grammar(tree_grammar)
|
32
|
+
def tree_parse( grammar, tree_grammar, rule, tree_rule, input )
|
33
|
+
@grammar = inline_grammar( grammar )
|
34
|
+
@tree_grammar = inline_grammar( tree_grammar )
|
35
35
|
compile_and_load @grammar
|
36
36
|
compile_and_load @tree_grammar
|
37
37
|
|
38
|
-
grammar_module = self.class.const_get(@grammar.name)
|
39
|
-
tree_grammar_module = self.class.const_get(@tree_grammar.name)
|
38
|
+
grammar_module = self.class.const_get( @grammar.name )
|
39
|
+
tree_grammar_module = self.class.const_get( @tree_grammar.name )
|
40
40
|
|
41
|
-
grammar_module::Lexer.send(:include, ANTLR3::Test::CollectErrors)
|
42
|
-
grammar_module::Lexer.send(:include, ANTLR3::Test::CaptureOutput)
|
43
|
-
grammar_module::Parser.send(:include, ANTLR3::Test::CollectErrors)
|
44
|
-
grammar_module::Parser.send(:include, ANTLR3::Test::CaptureOutput)
|
45
|
-
tree_grammar_module::TreeParser.send(:include, ANTLR3::Test::CollectErrors)
|
46
|
-
tree_grammar_module::TreeParser.send(:include, ANTLR3::Test::CaptureOutput)
|
41
|
+
grammar_module::Lexer.send( :include, ANTLR3::Test::CollectErrors )
|
42
|
+
grammar_module::Lexer.send( :include, ANTLR3::Test::CaptureOutput )
|
43
|
+
grammar_module::Parser.send( :include, ANTLR3::Test::CollectErrors )
|
44
|
+
grammar_module::Parser.send( :include, ANTLR3::Test::CaptureOutput )
|
45
|
+
tree_grammar_module::TreeParser.send( :include, ANTLR3::Test::CollectErrors )
|
46
|
+
tree_grammar_module::TreeParser.send( :include, ANTLR3::Test::CaptureOutput )
|
47
47
|
|
48
48
|
lexer = grammar_module::Lexer.new( input )
|
49
49
|
parser = grammar.module::Parser.new( lexer )
|
50
|
-
r = parser.send(rule)
|
50
|
+
r = parser.send( rule )
|
51
51
|
nodes = ANTLR3::CommonTreeNodeStream( r.tree )
|
52
52
|
nodes.token_stream = parser.input
|
53
53
|
walker = tree_grammar_module::TreeParser.new( nodes )
|
54
|
-
r = walker.send(tree_rule)
|
54
|
+
r = walker.send( tree_rule )
|
55
55
|
|
56
|
-
return(r ? r.tree.inspect : '')
|
56
|
+
return( r ? r.tree.inspect : '' )
|
57
57
|
end
|
58
58
|
|
59
59
|
|
60
60
|
example 'flat token list' do
|
61
|
-
result = parse(<<-'END', :a, 'abc 34')
|
61
|
+
result = parse( <<-'END', :a, 'abc 34' )
|
62
62
|
grammar TokenList;
|
63
63
|
options {language=Ruby;output=AST;}
|
64
64
|
a : ID INT ;
|
@@ -70,7 +70,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
70
70
|
end
|
71
71
|
|
72
72
|
example 'token list in a single-alternative subrule' do
|
73
|
-
result = parse(<<-'END', :a, 'abc 34')
|
73
|
+
result = parse( <<-'END', :a, 'abc 34' )
|
74
74
|
grammar TokenListInSingleAltBlock;
|
75
75
|
options {language=Ruby;output=AST;}
|
76
76
|
a : (ID INT) ;
|
@@ -82,7 +82,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
82
82
|
end
|
83
83
|
|
84
84
|
example "simple root at the outer level via the `^' operator" do
|
85
|
-
result = parse(<<-'END', :a, 'abc 34')
|
85
|
+
result = parse( <<-'END', :a, 'abc 34' )
|
86
86
|
grammar SimpleRootAtOuterLevel;
|
87
87
|
options {language=Ruby;output=AST;}
|
88
88
|
a : ID^ INT ;
|
@@ -94,7 +94,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
94
94
|
end
|
95
95
|
|
96
96
|
example "outer-level root changing token order from the `^' operator" do
|
97
|
-
result = parse(<<-'END', :a, '34 abc')
|
97
|
+
result = parse( <<-'END', :a, '34 abc' )
|
98
98
|
grammar SimpleRootAtOuterLevelReverse;
|
99
99
|
options {language=Ruby;output=AST;}
|
100
100
|
a : INT ID^ ;
|
@@ -106,7 +106,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
106
106
|
end
|
107
107
|
|
108
108
|
example "leaving out tokens using the `!' operator" do
|
109
|
-
result = parse(<<-'END', :a, 'abc 34 dag 4532')
|
109
|
+
result = parse( <<-'END', :a, 'abc 34 dag 4532' )
|
110
110
|
grammar Bang;
|
111
111
|
options {language=Ruby;output=AST;}
|
112
112
|
a : ID INT! ID! INT ;
|
@@ -119,7 +119,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
119
119
|
end
|
120
120
|
|
121
121
|
example "tokens in `(...)?' optional subrule" do
|
122
|
-
result = parse(<<-'END', :a, 'a 1 b')
|
122
|
+
result = parse( <<-'END', :a, 'a 1 b' )
|
123
123
|
grammar OptionalThenRoot;
|
124
124
|
options {language=Ruby;output=AST;}
|
125
125
|
a : ( ID INT )? ID^ ;
|
@@ -131,7 +131,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
131
131
|
end
|
132
132
|
|
133
133
|
example "labeled literal-string root token" do
|
134
|
-
result = parse(<<-'END', :a, 'void foo;')
|
134
|
+
result = parse( <<-'END', :a, 'void foo;' )
|
135
135
|
grammar LabeledStringRoot;
|
136
136
|
options {language=Ruby;output=AST;}
|
137
137
|
a : v='void'^ ID ';' ;
|
@@ -143,7 +143,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
143
143
|
end
|
144
144
|
|
145
145
|
example 'rule with token wildcard' do
|
146
|
-
result = parse(<<-'END', :a, 'void foo;')
|
146
|
+
result = parse( <<-'END', :a, 'void foo;' )
|
147
147
|
grammar Wildcard;
|
148
148
|
options {language=Ruby;output=AST;}
|
149
149
|
a : v='void'^ . ';' ;
|
@@ -155,7 +155,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
155
155
|
end
|
156
156
|
|
157
157
|
example "token wildcard as root via the `^' operator" do
|
158
|
-
result = parse(<<-'END', :a, 'void foo;')
|
158
|
+
result = parse( <<-'END', :a, 'void foo;' )
|
159
159
|
grammar WildcardRoot;
|
160
160
|
options {language=Ruby;output=AST;}
|
161
161
|
a : v='void' .^ ';' ;
|
@@ -167,7 +167,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
167
167
|
end
|
168
168
|
|
169
169
|
example "labeled token wildcard as root via the `^' operator" do
|
170
|
-
result = parse(<<-'END', :a, 'void foo;')
|
170
|
+
result = parse( <<-'END', :a, 'void foo;' )
|
171
171
|
grammar WildcardRootWithLabel;
|
172
172
|
options {language=Ruby;output=AST;}
|
173
173
|
a : v='void' x=.^ ';' ;
|
@@ -180,7 +180,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
180
180
|
|
181
181
|
|
182
182
|
example "token wildcard as root (with list label)" do
|
183
|
-
result = parse(<<-'END', :a, 'void foo;')
|
183
|
+
result = parse( <<-'END', :a, 'void foo;' )
|
184
184
|
grammar WildcardRootWithListLabel;
|
185
185
|
options {language=Ruby;output=AST;}
|
186
186
|
a : v='void' x=.^ ';' ;
|
@@ -193,7 +193,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
193
193
|
end
|
194
194
|
|
195
195
|
example "trashed token wildcard" do
|
196
|
-
result = parse(<<-'END', :a, 'void foo;')
|
196
|
+
result = parse( <<-'END', :a, 'void foo;' )
|
197
197
|
grammar WildcardBangWithListLabel;
|
198
198
|
options {language=Ruby;output=AST;}
|
199
199
|
a : v='void' x=.! ';' ;
|
@@ -206,7 +206,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
206
206
|
end
|
207
207
|
|
208
208
|
example "multiple occurences of the `^' operator in a list of tokens" do
|
209
|
-
result = parse(<<-'END', :a, 'a 34 c')
|
209
|
+
result = parse( <<-'END', :a, 'a 34 c' )
|
210
210
|
grammar RootRoot;
|
211
211
|
options {language=Ruby;output=AST;}
|
212
212
|
a : ID^ INT^ ID ;
|
@@ -219,7 +219,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
219
219
|
end
|
220
220
|
|
221
221
|
example "another case of multiple occurences of the `^' operator" do
|
222
|
-
result = parse(<<-'END', :a, 'a 34 c')
|
222
|
+
result = parse( <<-'END', :a, 'a 34 c' )
|
223
223
|
grammar RootRoot2;
|
224
224
|
options {language=Ruby;output=AST;}
|
225
225
|
a : ID INT^ ID^ ;
|
@@ -232,7 +232,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
232
232
|
end
|
233
233
|
|
234
234
|
example "root-hoist using `^' from within a (...)+ block" do
|
235
|
-
result = parse(<<-'END', :a, 'a 34 * b 9 * c')
|
235
|
+
result = parse( <<-'END', :a, 'a 34 * b 9 * c' )
|
236
236
|
grammar RootThenRootInLoop;
|
237
237
|
options {language=Ruby;output=AST;}
|
238
238
|
a : ID^ (INT '*'^ ID)+ ;
|
@@ -245,7 +245,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
245
245
|
end
|
246
246
|
|
247
247
|
example "nested subrules without any AST ops resulting in a flat list" do
|
248
|
-
result = parse(<<-'END', :a, 'void a b;')
|
248
|
+
result = parse( <<-'END', :a, 'void a b;' )
|
249
249
|
grammar NestedSubrule;
|
250
250
|
options {language=Ruby;output=AST;}
|
251
251
|
a : 'void' (({
|
@@ -260,7 +260,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
260
260
|
end
|
261
261
|
|
262
262
|
example "invoking another rule without any AST ops, resulting in a flat list" do
|
263
|
-
result = parse(<<-'END', :a, 'int a')
|
263
|
+
result = parse( <<-'END', :a, 'int a' )
|
264
264
|
grammar InvokeRule;
|
265
265
|
options {language=Ruby;output=AST;}
|
266
266
|
a : type ID ;
|
@@ -276,7 +276,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
276
276
|
end
|
277
277
|
|
278
278
|
example "hoisting the results of another rule as root using the `^' operator" do
|
279
|
-
result = parse(<<-'END', :a, 'int a')
|
279
|
+
result = parse( <<-'END', :a, 'int a' )
|
280
280
|
grammar InvokeRuleAsRoot;
|
281
281
|
options {language=Ruby;output=AST;}
|
282
282
|
a : type^ ID ;
|
@@ -292,7 +292,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
292
292
|
end
|
293
293
|
|
294
294
|
example "hoisting another rule's true as root using the `^' operator (with a label)" do
|
295
|
-
result = parse(<<-'END', :a, 'int a')
|
295
|
+
result = parse( <<-'END', :a, 'int a' )
|
296
296
|
grammar InvokeRuleAsRootWithLabel;
|
297
297
|
options {language=Ruby;output=AST;}
|
298
298
|
a : x=type^ ID ;
|
@@ -308,7 +308,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
308
308
|
end
|
309
309
|
|
310
310
|
example "hoisting another rule's result tree as root using the `^' operator (with a list += label)" do
|
311
|
-
result = parse(<<-'END', :a, 'int a')
|
311
|
+
result = parse( <<-'END', :a, 'int a' )
|
312
312
|
grammar InvokeRuleAsRootWithListLabel;
|
313
313
|
options {language=Ruby;output=AST;}
|
314
314
|
a : x+=type^ ID ;
|
@@ -324,7 +324,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
324
324
|
end
|
325
325
|
|
326
326
|
example "root-hoist via `^' within a (...)* loop resulting in a deeply-nested tree" do
|
327
|
-
result = parse(<<-'END', :a, 'a+b+c+d')
|
327
|
+
result = parse( <<-'END', :a, 'a+b+c+d' )
|
328
328
|
grammar RuleRootInLoop;
|
329
329
|
options {language=Ruby;output=AST;}
|
330
330
|
a : ID ('+'^ ID)* ;
|
@@ -337,7 +337,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
337
337
|
end
|
338
338
|
|
339
339
|
example "hoisting another rule's result tree as root from within a (...)* loop resulting in a deeply nested tree" do
|
340
|
-
result = parse(<<-'END', :a, 'a+b+c-d')
|
340
|
+
result = parse( <<-'END', :a, 'a+b+c-d' )
|
341
341
|
grammar RuleInvocationRuleRootInLoop;
|
342
342
|
options {language=Ruby;output=AST;}
|
343
343
|
a : ID (op^ ID)* ;
|
@@ -353,7 +353,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
353
353
|
end
|
354
354
|
|
355
355
|
example "using tail recursion to build deeply-nested expression trees" do
|
356
|
-
result = parse(<<-'END', :s, '3 exp 4 exp 5')
|
356
|
+
result = parse( <<-'END', :s, '3 exp 4 exp 5' )
|
357
357
|
grammar TailRecursion;
|
358
358
|
options {language=Ruby;output=AST;}
|
359
359
|
s : a ;
|
@@ -368,7 +368,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
368
368
|
end
|
369
369
|
|
370
370
|
example "simple token node from a token type set" do
|
371
|
-
result = parse(<<-'END', :a, 'abc')
|
371
|
+
result = parse( <<-'END', :a, 'abc' )
|
372
372
|
grammar TokenSet;
|
373
373
|
options {language=Ruby; output=AST;}
|
374
374
|
a : ID|INT ;
|
@@ -380,7 +380,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
380
380
|
end
|
381
381
|
|
382
382
|
example "hoisting a token-type set token as root with `^'" do
|
383
|
-
result = parse(<<-'END', :a, '+abc')
|
383
|
+
result = parse( <<-'END', :a, '+abc' )
|
384
384
|
grammar SetRoot;
|
385
385
|
options {language=Ruby;output=AST;}
|
386
386
|
a : ('+' | '-')^ ID ;
|
@@ -393,7 +393,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
393
393
|
end
|
394
394
|
|
395
395
|
example "hoisting a token-type set token as root with `^' (with a label)" do
|
396
|
-
result = parse(<<-'END', :a, '+abc')
|
396
|
+
result = parse( <<-'END', :a, '+abc' )
|
397
397
|
grammar SetRootWithLabel;
|
398
398
|
options {language=Ruby;output=AST;}
|
399
399
|
a : (x=('+' | '-'))^ ID ;
|
@@ -406,7 +406,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
406
406
|
end
|
407
407
|
|
408
408
|
example "hoisting a token-type set token as root from within a (...)* loop" do
|
409
|
-
result = parse(<<-'END', :a, 'a+b-c')
|
409
|
+
result = parse( <<-'END', :a, 'a+b-c' )
|
410
410
|
grammar SetAsRuleRootInLoop;
|
411
411
|
options {language=Ruby;output=AST;}
|
412
412
|
a : ID (('+'|'-')^ ID)* ;
|
@@ -419,7 +419,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
419
419
|
end
|
420
420
|
|
421
421
|
example "an `~' inverted token-type set element" do
|
422
|
-
result = parse(<<-'END', :a, '34+2')
|
422
|
+
result = parse( <<-'END', :a, '34+2' )
|
423
423
|
grammar NotSet;
|
424
424
|
options {language=Ruby;output=AST;}
|
425
425
|
a : ~ID '+' INT ;
|
@@ -432,7 +432,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
432
432
|
end
|
433
433
|
|
434
434
|
example "a `~' inverted token-type set in a rule (with a label)" do
|
435
|
-
result = parse(<<-'END', :a, '34+2')
|
435
|
+
result = parse( <<-'END', :a, '34+2' )
|
436
436
|
grammar NotSetWithLabel;
|
437
437
|
options {language=Ruby;output=AST;}
|
438
438
|
a : x=~ID '+' INT ;
|
@@ -445,7 +445,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
445
445
|
end
|
446
446
|
|
447
447
|
example "a `~' inverted token-type set element in a rule (with a list += label)" do
|
448
|
-
result = parse(<<-'END', :a, '34+2')
|
448
|
+
result = parse( <<-'END', :a, '34+2' )
|
449
449
|
grammar NotSetWithListLabel;
|
450
450
|
options {language=Ruby;output=AST;}
|
451
451
|
a : x=~ID '+' INT ;
|
@@ -458,7 +458,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
458
458
|
end
|
459
459
|
|
460
460
|
example "a `~' inverted token-type set element hoisted to root via `^'" do
|
461
|
-
result = parse(<<-'END', :a, '34 55')
|
461
|
+
result = parse( <<-'END', :a, '34 55' )
|
462
462
|
grammar NotSetRoot;
|
463
463
|
options {language=Ruby;output=AST;}
|
464
464
|
a : ~'+'^ INT ;
|
@@ -473,7 +473,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
473
473
|
# FIXME: no label actually in the grammar
|
474
474
|
|
475
475
|
example "hoisting a `~' inverted token-type set to root using `^' (with label)" do
|
476
|
-
result = parse(<<-'END', :a, '34 55')
|
476
|
+
result = parse( <<-'END', :a, '34 55' )
|
477
477
|
grammar NotSetRootWithLabel;
|
478
478
|
options {language=Ruby;output=AST;}
|
479
479
|
a : x=~'+'^ INT ;
|
@@ -487,7 +487,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
487
487
|
# FIXME: no label here either
|
488
488
|
|
489
489
|
example "hoisting a `~' inverted token-type set to root using `^' (with list += label)" do
|
490
|
-
result = parse(<<-'END', :a, '34 55')
|
490
|
+
result = parse( <<-'END', :a, '34 55' )
|
491
491
|
grammar NotSetRootWithListLabel;
|
492
492
|
options {language=Ruby;output=AST;}
|
493
493
|
a : x+=~'+'^ INT ;
|
@@ -500,7 +500,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
500
500
|
end
|
501
501
|
|
502
502
|
example "hoisting a `~' inverted token-type set to root from within a (...)* loop" do
|
503
|
-
result = parse(<<-'END', :a, '3+4+5')
|
503
|
+
result = parse( <<-'END', :a, '3+4+5' )
|
504
504
|
grammar NotSetRuleRootInLoop;
|
505
505
|
options {language=Ruby;output=AST;}
|
506
506
|
a : INT (~INT^ INT)* ;
|
@@ -514,7 +514,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
514
514
|
end
|
515
515
|
|
516
516
|
example "multiple tokens with the same label in a rule" do
|
517
|
-
result = parse(<<-'END', :a, 'a b')
|
517
|
+
result = parse( <<-'END', :a, 'a b' )
|
518
518
|
grammar TokenLabelReuse;
|
519
519
|
options {language=Ruby;output=AST;}
|
520
520
|
a returns [result] : id=ID id=ID {
|
@@ -529,7 +529,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
529
529
|
end
|
530
530
|
|
531
531
|
example "multiple tokens with the same label in a rule (with a `^' root hoist)" do
|
532
|
-
result = parse(<<-'END', :a, 'a b')
|
532
|
+
result = parse( <<-'END', :a, 'a b' )
|
533
533
|
grammar TokenLabelReuse2;
|
534
534
|
options {language=Ruby;output=AST;}
|
535
535
|
a returns [result]: id=ID id=ID^ {$result = "2nd id=#{$id.text},"} ;
|
@@ -542,7 +542,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
542
542
|
end
|
543
543
|
|
544
544
|
example "extra token in a simple declaration" do
|
545
|
-
result, errors = parse(<<-'END', :decl, 'int 34 x=1;', true)
|
545
|
+
result, errors = parse( <<-'END', :decl, 'int 34 x=1;', true )
|
546
546
|
grammar ExtraTokenInSimpleDecl;
|
547
547
|
options {language=Ruby;output=AST;}
|
548
548
|
decl : type^ ID '='! INT ';'! ;
|
@@ -552,12 +552,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
552
552
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
553
553
|
|
554
554
|
END
|
555
|
-
errors.should == ["line 1:4 extraneous input \"34\" expecting ID"]
|
555
|
+
errors.should == [ "line 1:4 extraneous input \"34\" expecting ID" ]
|
556
556
|
result.should == '(int x 1)'
|
557
557
|
end
|
558
558
|
|
559
559
|
example "missing ID in a simple declaration" do
|
560
|
-
result, errors = parse(<<-'END', :decl, 'int =1;', true)
|
560
|
+
result, errors = parse( <<-'END', :decl, 'int =1;', true )
|
561
561
|
grammar MissingIDInSimpleDecl;
|
562
562
|
options {language=Ruby;output=AST;}
|
563
563
|
tokens {EXPR;}
|
@@ -567,12 +567,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
567
567
|
INT : '0'..'9'+;
|
568
568
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
569
569
|
END
|
570
|
-
errors.should == ["line 1:4 missing ID at \"=\""]
|
570
|
+
errors.should == [ "line 1:4 missing ID at \"=\"" ]
|
571
571
|
result.should == '(int <missing ID> 1)'
|
572
572
|
end
|
573
573
|
|
574
574
|
example "missing token of a token-type set in a simple declaration" do
|
575
|
-
result, errors = parse(<<-'END', :decl, 'x=1;', true)
|
575
|
+
result, errors = parse( <<-'END', :decl, 'x=1;', true )
|
576
576
|
grammar MissingSetInSimpleDecl;
|
577
577
|
options {language=Ruby;output=AST;}
|
578
578
|
tokens {EXPR;}
|
@@ -583,12 +583,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
583
583
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
584
584
|
|
585
585
|
END
|
586
|
-
errors.should == ["line 1:0 mismatched input \"x\" expecting set nil"]
|
586
|
+
errors.should == [ "line 1:0 mismatched input \"x\" expecting set nil" ]
|
587
587
|
result.should == '(<error: x> x 1)'
|
588
588
|
end
|
589
589
|
|
590
590
|
example "missing INT token simulated with a `<missing INT>' error node" do
|
591
|
-
result, errors = parse(<<-'END', :a, 'abc', true)
|
591
|
+
result, errors = parse( <<-'END', :a, 'abc', true )
|
592
592
|
grammar MissingTokenGivesErrorNode;
|
593
593
|
options {language=Ruby;output=AST;}
|
594
594
|
a : ID INT ; // follow is EOF
|
@@ -597,12 +597,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
597
597
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
598
598
|
|
599
599
|
END
|
600
|
-
errors.should == ["line 0:-1 missing INT at \"<EOF>\""]
|
600
|
+
errors.should == [ "line 0:-1 missing INT at \"<EOF>\"" ]
|
601
601
|
result.should == 'abc <missing INT>'
|
602
602
|
end
|
603
603
|
|
604
604
|
example "missing token from invoked rule results in error node with a resync attribute" do
|
605
|
-
result, errors = parse(<<-'END', :a, 'abc', true)
|
605
|
+
result, errors = parse( <<-'END', :a, 'abc', true )
|
606
606
|
grammar MissingTokenGivesErrorNodeInInvokedRule;
|
607
607
|
options {language=Ruby;output=AST;}
|
608
608
|
a : b ;
|
@@ -612,12 +612,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
612
612
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
613
613
|
|
614
614
|
END
|
615
|
-
errors.should == ["line 0:-1 mismatched input \"<EOF>\" expecting INT"]
|
615
|
+
errors.should == [ "line 0:-1 mismatched input \"<EOF>\" expecting INT" ]
|
616
616
|
result.should == '<mismatched token: <EOF>, resync = abc>'
|
617
617
|
end
|
618
618
|
|
619
619
|
example "extraneous ID token displays error and is ignored in AST output" do
|
620
|
-
result, errors = parse(<<-'END', :a, 'abc ick 34', true)
|
620
|
+
result, errors = parse( <<-'END', :a, 'abc ick 34', true )
|
621
621
|
grammar ExtraTokenGivesErrorNode;
|
622
622
|
options {language=Ruby;output=AST;}
|
623
623
|
a : b c ;
|
@@ -628,12 +628,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
628
628
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
629
629
|
|
630
630
|
END
|
631
|
-
errors.should == ["line 1:4 extraneous input \"ick\" expecting INT"]
|
631
|
+
errors.should == [ "line 1:4 extraneous input \"ick\" expecting INT" ]
|
632
632
|
result.should == 'abc 34'
|
633
633
|
end
|
634
634
|
|
635
635
|
example "missing ID token simulated with a `<missing ID>' error node" do
|
636
|
-
result, errors = parse(<<-'END', :a, '34', true)
|
636
|
+
result, errors = parse( <<-'END', :a, '34', true )
|
637
637
|
grammar MissingFirstTokenGivesErrorNode;
|
638
638
|
options {language=Ruby;output=AST;}
|
639
639
|
a : ID INT ;
|
@@ -642,12 +642,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
642
642
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
643
643
|
|
644
644
|
END
|
645
|
-
errors.should == ["line 1:0 missing ID at \"34\""]
|
645
|
+
errors.should == [ "line 1:0 missing ID at \"34\"" ]
|
646
646
|
result.should == '<missing ID> 34'
|
647
647
|
end
|
648
648
|
|
649
649
|
example "another case where a missing ID token is simulated with a `<missing ID>' error node" do
|
650
|
-
result, errors = parse(<<-'END', :a, '34', true)
|
650
|
+
result, errors = parse( <<-'END', :a, '34', true )
|
651
651
|
grammar MissingFirstTokenGivesErrorNode2;
|
652
652
|
options {language=Ruby;output=AST;}
|
653
653
|
a : b c ;
|
@@ -658,12 +658,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
658
658
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
659
659
|
|
660
660
|
END
|
661
|
-
errors.should == ["line 1:0 missing ID at \"34\""]
|
661
|
+
errors.should == [ "line 1:0 missing ID at \"34\"" ]
|
662
662
|
result.should == '<missing ID> 34'
|
663
663
|
end
|
664
664
|
|
665
665
|
example "no viable alternative for rule is represented as a single `<unexpected: ...>' error node" do
|
666
|
-
result, errors = parse(<<-'END', :a, '*', true)
|
666
|
+
result, errors = parse( <<-'END', :a, '*', true )
|
667
667
|
grammar NoViableAltGivesErrorNode;
|
668
668
|
options {language=Ruby;output=AST;}
|
669
669
|
a : b | c ;
|
@@ -674,12 +674,12 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
674
674
|
INT : '0'..'9'+;
|
675
675
|
WS : (' '|'\n') {$channel=HIDDEN;} ;
|
676
676
|
END
|
677
|
-
errors.should == ["line 1:0 no viable alternative at input \"*\""]
|
677
|
+
errors.should == [ "line 1:0 no viable alternative at input \"*\"" ]
|
678
678
|
result.should == "<unexpected: 0 S[\"*\"] @ line 1 col 0 (0..0), resync = *>"
|
679
679
|
end
|
680
680
|
|
681
681
|
example "token with a `+=' list label hoisted to root with `^'" do
|
682
|
-
result = parse(<<-'END', :a, 'a')
|
682
|
+
result = parse( <<-'END', :a, 'a' )
|
683
683
|
grammar TokenListLabelRuleRoot;
|
684
684
|
options {language=Ruby;output=AST;}
|
685
685
|
a : id+=ID^ ;
|
@@ -692,7 +692,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
692
692
|
end
|
693
693
|
|
694
694
|
example "token with a list `+=' label trashed with `!'" do
|
695
|
-
result = parse(<<-'END', :a, 'a')
|
695
|
+
result = parse( <<-'END', :a, 'a' )
|
696
696
|
grammar TokenListLabelBang;
|
697
697
|
options {language=Ruby;output=AST;}
|
698
698
|
a : id+=ID! ;
|
@@ -705,7 +705,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
705
705
|
end
|
706
706
|
|
707
707
|
example "using list `+=' labels to collect trees of invoked rules" do
|
708
|
-
result = parse(<<-'END', :a, 'a b')
|
708
|
+
result = parse( <<-'END', :a, 'a b' )
|
709
709
|
grammar RuleListLabel;
|
710
710
|
options {language=Ruby;output=AST;}
|
711
711
|
a returns [result]: x+=b x+=b {
|
@@ -722,7 +722,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
722
722
|
end
|
723
723
|
|
724
724
|
example "using a list `+=' label to collect the trees of invoked rules within a (...)+ block" do
|
725
|
-
result = parse(<<-'END', :a, 'a b')
|
725
|
+
result = parse( <<-'END', :a, 'a b' )
|
726
726
|
grammar RuleListLabelRuleRoot;
|
727
727
|
options {language=Ruby;output=AST;}
|
728
728
|
a returns [result] : ( x+=b^ )+ {
|
@@ -738,7 +738,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
738
738
|
end
|
739
739
|
|
740
740
|
example "trashing the tree of an invoked rule with `!' while collecting the tree with a list `+=' label" do
|
741
|
-
result = parse(<<-'END', :a, 'a b')
|
741
|
+
result = parse( <<-'END', :a, 'a b' )
|
742
742
|
grammar RuleListLabelBang;
|
743
743
|
options {language=Ruby;output=AST;}
|
744
744
|
a returns [result] : x+=b! x+=b {
|
@@ -754,7 +754,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
754
754
|
end
|
755
755
|
|
756
756
|
example "a whole bunch of different elements" do
|
757
|
-
result = parse(<<-'END', :a, 'a b b c c d')
|
757
|
+
result = parse( <<-'END', :a, 'a b b c c d' )
|
758
758
|
grammar ComplicatedMelange;
|
759
759
|
options {language=Ruby;output=AST;}
|
760
760
|
a : A b=B b=B c+=C c+=C D {s = $D.text} ;
|
@@ -768,7 +768,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
768
768
|
end
|
769
769
|
|
770
770
|
example "rule return values in addition to AST output" do
|
771
|
-
result = parse(<<-'END', :a, 'abc 34')
|
771
|
+
result = parse( <<-'END', :a, 'abc 34' )
|
772
772
|
grammar ReturnValueWithAST;
|
773
773
|
options {language=Ruby;output=AST;}
|
774
774
|
a returns [result] : ID b { $result = $b.i.to_s + "\n" } ;
|
@@ -782,7 +782,7 @@ class TestAutoAST < ANTLR3::Test::Functional
|
|
782
782
|
end
|
783
783
|
|
784
784
|
example "a (...)+ loop containing a token-type set" do
|
785
|
-
result = parse(<<-'END', :r, 'abc 34 d')
|
785
|
+
result = parse( <<-'END', :r, 'abc 34 d' )
|
786
786
|
grammar SetLoop;
|
787
787
|
options { language=Ruby;output=AST; }
|
788
788
|
r : (INT|ID)+ ;
|