antlr3 1.8.13 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -61,18 +61,18 @@ _last = _save_last_<treeLevel>
61
61
 
62
62
  >>
63
63
 
64
- tokenRefBang(token,label,elementIndex) ::= <<
64
+ tokenRefBang(token,label,elementIndex,terminalOptions) ::= <<
65
65
  _last = @input.look
66
66
  <super.tokenRef(...)>
67
67
  >>
68
68
 
69
- tokenRef(token,label,elementIndex,hetero) ::= <<
69
+ tokenRef(token,label,elementIndex,terminalOptions) ::= <<
70
70
  _last = @input.look
71
71
  <super.tokenRef(...)>
72
72
  <if(!rewriteMode)>
73
73
  <gatedAction({
74
- <if(hetero)>
75
- tree_for_<label> = <hetero; format="constantPath">.new( <label; format="label"> )
74
+ <if(terminalOptions.node)>
75
+ tree_for_<label> = <terminalOptions.node; format="constantPath">.new( <label; format="label"> )
76
76
  <else>
77
77
  tree_for_<label> = @adaptor.copy_node( <label; format="label"> )
78
78
  <endif><\n>
@@ -87,18 +87,18 @@ _first_<treeLevel> ||= <label; format="label"><\n>
87
87
 
88
88
 
89
89
 
90
- tokenRefAndListLabel(token,label,elementIndex,hetero) ::= <<
90
+ tokenRefAndListLabel(token,label,elementIndex,terminalOptions) ::= <<
91
91
  <tokenRef(...)>
92
92
  <addToList(elem={<label; format="label">},...)>
93
93
  >>
94
94
 
95
- tokenRefRuleRoot(token,label,elementIndex,hetero) ::= <<
95
+ tokenRefRuleRoot(token,label,elementIndex,terminalOptions) ::= <<
96
96
  _last = @input.look
97
97
  <super.tokenRef(...)>
98
98
  <if(!rewriteMode)>
99
99
  <gatedAction({
100
- <if(hetero)>
101
- tree_for_<label> = <hetero; format="constantPath">.new( <label; format="label"> )
100
+ <if(terminalOptions.node)>
101
+ tree_for_<label> = <terminalOptions.node; format="constantPath">.new( <label; format="label"> )
102
102
  <else>
103
103
  tree_for_<label> = @adaptor.copy_node( <label; format="label"> )
104
104
  <endif><\n>
@@ -107,12 +107,12 @@ root_<treeLevel> = @adaptor.become_root( tree_for_<label>, root_<treeLevel> )
107
107
  <endif>
108
108
  >>
109
109
 
110
- tokenRefRuleRootAndListLabel(token,label,elementIndex,hetero) ::= <<
110
+ tokenRefRuleRootAndListLabel(token,label,elementIndex,terminalOptions) ::= <<
111
111
  <tokenRefRuleRoot(...)>
112
112
  <addToList(elem={<label; format="label">},...)>
113
113
  >>
114
114
 
115
- wildcard(token,label,elementIndex,hetero) ::= <<
115
+ wildcard(token,label,elementIndex,terminalOptions) ::= <<
116
116
  _last = @input.look
117
117
  <super.wildcard(...)>
118
118
  <if(!rewriteMode)>
@@ -127,49 +127,49 @@ _first_<treeLevel> and _first_<treeLevel> = <label; format="label">
127
127
  <endif>
128
128
  >>
129
129
 
130
- matchSet(s,label,hetero,elementIndex,postmatchCode) ::= <<
130
+ matchSet(s,label,terminalOptions,elementIndex,postmatchCode) ::= <<
131
131
  _last = @input.look
132
- <super.matchSet(..., postmatchCode={
132
+ <super.matchSet(postmatchCode={
133
133
  <if(!rewriteMode)>
134
134
  <gatedAction({
135
- <if(hetero)>
136
- tree_for_<label> = <hetero; format="constantPath">.new( <label; format="label"> )
135
+ <if(terminalOptions.node)>
136
+ tree_for_<label> = <terminalOptions.node; format="constantPath">.new( <label; format="label"> )
137
137
  <else>
138
138
  tree_for_<label> = @adaptor.copy_node( <label; format="label"> )
139
139
  <endif><\n>
140
140
  @adaptor.add_child( root_<treeLevel>, tree_for_<label> )
141
141
  })>
142
142
  <endif>
143
- })>
143
+ }, ...)>
144
144
  >>
145
145
 
146
146
 
147
147
 
148
- matchRuleBlockSet(s,label,hetero,elementIndex,postmatchCode,treeLevel="0") ::= <<
148
+ matchRuleBlockSet(s,label,terminalOptions,elementIndex,postmatchCode,treeLevel="0") ::= <<
149
149
  <matchSet(...)>
150
- <noRewrite()>
150
+ <noRewrite(...)>
151
151
  >>
152
152
 
153
153
 
154
154
 
155
- matchSetBang(s,label,elementIndex,postmatchCode) ::= <<
155
+ matchSetBang(s,label,terminalOptions,elementIndex,postmatchCode) ::= <<
156
156
  _last = @input.look
157
157
  <super.matchSet(...)>
158
158
  >>
159
159
 
160
- matchSetRuleRoot(s,label,hetero,elementIndex,debug) ::= <<
161
- <super.matchSet(..., postmatchCode={
160
+ matchSetRuleRoot(s,label,terminalOptions,elementIndex,debug) ::= <<
161
+ <super.matchSet(postmatchCode={
162
162
  <if(!rewriteMode)>
163
163
  <gatedAction({
164
- <if(hetero)>
165
- tree_for_<label> = <hetero; format="constantPath">.new( <label; format="label"> )
164
+ <if(terminalOptions.node)>
165
+ tree_for_<label> = <terminalOptions.node; format="constantPath">.new( <label; format="label"> )
166
166
  <else>
167
167
  tree_for_<label> = @adaptor.copy_node( <label; format="label"> )
168
168
  <endif><\n>
169
169
  root_<treeLevel> = @adaptor.become_root( tree_for_<label>, root_<treeLevel> )
170
170
  })>
171
171
  <endif>
172
- })>
172
+ }, ...)>
173
173
  >>
174
174
 
175
175
  ruleRef(rule,label,elementIndex,args,scope) ::= <<
@@ -224,13 +224,13 @@ _last = @input.look
224
224
  <super.ruleRefRuleRootTrackAndListLabel(...)>
225
225
  >>
226
226
 
227
- createRewriteNodeFromElement(token,hetero,scope) ::= <<
228
- <if(hetero)>
229
- <hetero; format="constantPath">.new( stream_<token>.next_node )
227
+ createRewriteNodeFromElement(token,args={},terminalOptions={}) ::= <%
228
+ <if(terminalOptions.node)>
229
+ <terminalOptions.node; format="constantPath">.new( stream_<token>.next_node )
230
230
  <else>
231
231
  stream_<token>.next_node
232
232
  <endif>
233
- >>
233
+ %>
234
234
 
235
235
  ruleCleanUp() ::= <<
236
236
  <super.ruleCleanUp()>
@@ -1,7 +1,7 @@
1
1
  group Dbg;
2
2
 
3
3
  /*
4
- [The "BSD licence"]
4
+ [The "BSD license"]
5
5
  Copyright (c) 2005-2009 Terence Parr
6
6
  All rights reserved.
7
7
 
@@ -44,11 +44,11 @@ RULE_NAMES = [
44
44
 
45
45
  @rule.body() ::= <<
46
46
  in_rule(grammar_file_name, "<ruleName>") do
47
- @debug_listener.location(<ruleDescriptor.tree.line>, <ruleDescriptor.tree.column>)
48
-
47
+ @debug_listener.location(<ruleDescriptor.tree.line>, <ruleDescriptor.tree.charPositionInLine>)
48
+
49
49
  <@super.body()>
50
-
51
- @debug_listener.location(<ruleDescriptor.EORNode.line>, <ruleDescriptor.EORNode.column>)
50
+
51
+ @debug_listener.location(<ruleDescriptor.EORNode.line>, <ruleDescriptor.EORNode.charPositionInLine>)
52
52
  end
53
53
  >>
54
54
 
@@ -143,12 +143,12 @@ end
143
143
  >>
144
144
 
145
145
 
146
- @altSwitchCase.prealt() ::= "<enterAlt(n=i)>"
146
+ @altSwitchCase.prealt() ::= "<enterAlt(altNum)>" // altNum is arg of altSwitchCase
147
147
 
148
148
 
149
- element() ::= <<
150
- @debug_listener.location(<it.line>, <it.pos>)
151
- <super.element()>
149
+ element(e) ::= <<
150
+ @debug_listener.location(<e.line>, <e.pos>)
151
+ <super.element(e)>
152
152
  >>
153
153
 
154
154
 
@@ -1,9 +1,66 @@
1
- group Ruby implements ANTLRCore;
1
+ group Ruby;
2
2
 
3
3
  /******************************************************************************
4
4
  ********************* M A J O R C O M P O N E N T S **********************
5
5
  ******************************************************************************/
6
-
6
+
7
+ // System.Boolean.ToString() returns "True" and "False", but the proper C# literals are "true" and "false"
8
+ // The Java version of Boolean returns "true" and "false", so they map to themselves here.
9
+ booleanLiteral ::= [
10
+ "True":"true",
11
+ "False":"false",
12
+ "true":"true",
13
+ "false":"false",
14
+ default:"false"
15
+ ]
16
+
17
+ action(name, code) ::= <<
18
+ <if(code)>
19
+ # - - - - @<name> action - - - -
20
+ <code><\n>
21
+ <endif>
22
+ >>
23
+
24
+ autoloadDelegates() ::= <<
25
+ <if(grammar.directDelegates)>
26
+ <grammar.directDelegates:{it| autoload :<it.name>, "<it.recognizerName>"<\n>}>
27
+ <endif>
28
+ >>
29
+
30
+ delegateLexerRule(ruleDescriptor) ::= <<
31
+ # delegated lexer rule <ruleDescriptor.name; format="lexerRule"> (<ruleDescriptor.name> in the grammar)
32
+ def <ruleDescriptor.name; format="lexerRule"><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope()> )<endif>
33
+ <methodCall(del=ruleDescriptor.grammar, n={<ruleDescriptor.name; format="lexerRule">}, args=ruleDescriptor.parameterScope.attributes)>
34
+ end
35
+ >>
36
+
37
+ rootClassName() ::= <<
38
+ <if(grammar.grammarIsRoot)><grammar.name><else><grammar.composite.rootGrammar.name><endif>::<if(TREE_PARSER)>TreeParser<elseif(PARSER)>Parser<else>Lexer<endif>
39
+ >>
40
+
41
+ grammarClassName() ::= <<
42
+ <gram.name>::<if(TREE_PARSER)>TreeParser<elseif(PARSER)>Parser<else>Lexer<endif>
43
+ >>
44
+
45
+ newDelegate(gram) ::= <<
46
+ <gram.name>.new( <trunc(gram.delegators):{p|<p:delegateName()>, }>
47
+ self, @input, :state => @state<@delegateOptions()>
48
+ )
49
+ >>
50
+
51
+ placeAction(scope, name) ::= <<
52
+ <if(actions.(scope))>
53
+ <if(actions.(scope).(name))>
54
+ # - - - - - - begin action @<scope>::<name> - - - - - -
55
+ <if(fileName)># <fileName><\n><endif>
56
+ <actions.(scope).(name)>
57
+ # - - - - - - end action @<scope>::<name> - - - - - - -<\n>
58
+ <endif>
59
+ <endif>
60
+ >>
61
+
62
+ runtimeLibraryVersion() ::= "1.8.1"
63
+
7
64
  /** The overall file structure of a recognizer; stores methods
8
65
  * for rules and cyclic DFAs plus support code.
9
66
  */
@@ -20,22 +77,22 @@ outputFile(LEXER, PARSER, TREE_PARSER, actionScope, actions, docComment, recogni
20
77
  # Ruby runtime library version: <runtimeLibraryVersion()>
21
78
  # Input grammar file: <fileName>
22
79
  # Generated at: <generatedTimestamp>
23
- #
80
+ #
24
81
 
25
- # ~~~\> start load path setup
82
+ # ~~~> start load path setup
26
83
  this_directory = File.expand_path( File.dirname( __FILE__ ) )
27
84
  $LOAD_PATH.unshift( this_directory ) unless $LOAD_PATH.include?( this_directory )
28
85
 
29
86
  antlr_load_failed = proc do
30
87
  load_path = $LOAD_PATH.map { |dir| ' - ' \<\< dir }.join( $/ )
31
88
  raise LoadError, \<\<-END.strip!
32
-
89
+
33
90
  Failed to load the ANTLR3 runtime library (version <runtimeLibraryVersion()>):
34
91
 
35
92
  Ensure the library has been installed on your system and is available
36
93
  on the load path. If rubygems is available on your system, this can
37
94
  be done with the command:
38
-
95
+
39
96
  gem install antlr3
40
97
 
41
98
  Current load path:
@@ -45,53 +102,86 @@ Current load path:
45
102
  end
46
103
 
47
104
  defined?( ANTLR3 ) or begin
48
-
105
+
49
106
  # 1: try to load the ruby antlr3 runtime library from the system path
50
107
  require 'antlr3'
51
-
108
+
52
109
  rescue LoadError
53
-
110
+
54
111
  # 2: try to load rubygems if it isn't already loaded
55
112
  defined?( Gem ) or begin
56
113
  require 'rubygems'
57
114
  rescue LoadError
58
115
  antlr_load_failed.call
59
116
  end
60
-
117
+
61
118
  # 3: try to activate the antlr3 gem
62
119
  begin
63
- defined?( gem ) and gem( "antlr3", '~> <runtimeLibraryVersion()>' )
120
+ defined?( gem ) and gem( 'antlr3', '~> <runtimeLibraryVersion()>' )
64
121
  rescue Gem::LoadError
65
122
  antlr_load_failed.call
66
123
  end
67
-
124
+
68
125
  require 'antlr3'
69
-
126
+
70
127
  end
71
128
  # \<~~~ end load path setup
72
129
 
73
- <placeAction(scope="all", name="header")>
74
- <placeAction(scope=actionScope,name="header")>
130
+ <if(actions.all)>
131
+ <if(actions.all.header)>
132
+ # - - - - - - begin action @all::header - - - - - -
133
+ <if(fileName)># <fileName><\n><endif>
134
+ <actions.all.header>
135
+ # - - - - - - end action @all::header - - - - - - -<\n>
136
+ <endif>
137
+ <endif>
138
+ <if(actions.(actionScope))>
139
+ <if(actions.(actionScope).header)>
140
+ # - - - - - - begin action @<actionScope>::header - - - - - -
141
+ <if(fileName)># <fileName><\n><endif>
142
+ <actions.(actionScope).header>
143
+ # - - - - - - end action @<actionScope>::header - - - - - - -<\n>
144
+ <endif>
145
+ <endif>
75
146
 
76
147
  <if(recognizer.grammar.grammarIsRoot)>
77
- <rootGrammarOutputFile()>
148
+ <rootGrammarOutputFile(...)>
78
149
  <else>
79
150
  <delegateGrammarOutputFile()>
80
151
  <endif>
81
152
 
82
- <placeAction(scope=actionScope,name="footer")>
83
- <placeAction(scope="all", name="footer")>
153
+ <if(actions.(actionScope))>
154
+ <if(actions.(actionScope).footer)>
155
+ # - - - - - - begin action @<actionScope>::footer - - - - - -
156
+ <if(fileName)># <fileName><\n><endif>
157
+ <actions.(actionScope).footer>
158
+ # - - - - - - end action @<actionScope>::footer - - - - - - -<\n>
159
+ <endif>
160
+ <endif>
161
+ <if(actions.all)>
162
+ <if(actions.all.footer)>
163
+ # - - - - - - begin action @all::footer - - - - - -
164
+ <if(fileName)># <fileName><\n><endif>
165
+ <actions.all.footer>
166
+ # - - - - - - end action @all::footer - - - - - - -<\n>
167
+ <endif>
168
+ <endif>
84
169
 
170
+ <if(actions.(actionScope))>
85
171
  <if(actions.(actionScope).main)>
86
172
  if __FILE__ == $0 and ARGV.first != '--'
87
- <placeAction(scope=actionScope,name="main")>
173
+ # - - - - - - begin action @<actionScope>::main - - - - - -
174
+ <if(fileName)># <fileName><\n><endif>
175
+ <actions.(actionScope).main>
176
+ # - - - - - - end action @<actionScope>::main - - - - - - -<\n>
88
177
  end
89
178
  <endif>
179
+ <endif>
90
180
  >>
91
181
 
92
182
  tokenDataModule() ::= <<
93
183
  # TokenData defines all of the token type integer values
94
- # as constants, which will be included in all
184
+ # as constants, which will be included in all
95
185
  # ANTLR-generated recognizers.
96
186
  const_defined?( :TokenData ) or TokenData = ANTLR3::TokenScheme.new
97
187
 
@@ -99,7 +189,7 @@ module TokenData
99
189
  <if(tokens)>
100
190
 
101
191
  # define the token constants
102
- define_tokens( <tokens:{:<it.name> => <it.type>}; anchor, wrap="\n", separator=", "> )
192
+ define_tokens( <tokens:{it | :<it.name> => <it.type>}; anchor, wrap="\n", separator=", "> )
103
193
 
104
194
  <endif>
105
195
  <if(tokenNames)>
@@ -110,21 +200,21 @@ module TokenData
110
200
  # this is necessary because anonymous tokens, which are
111
201
  # created from literal values in the grammar, do not
112
202
  # have descriptive names
113
- register_names( <tokenNames:{<it>}; separator=", ", anchor, wrap="\n"> )
203
+ register_names( <tokenNames:{it | <it>}; separator=", ", anchor, wrap="\n"> )
114
204
 
115
205
  <endif>
116
-
117
- <placeAction(scope="token",name="scheme")>
118
- <placeAction(scope="token",name="members")>
206
+
207
+ <placeAction(scope="token", name="scheme",...)>
208
+ <placeAction(scope="token", name="members",...)>
119
209
  end<\n>
120
210
  >>
121
211
 
122
212
  rootGrammarOutputFile() ::= <<
123
213
  module <recognizer.grammar.name>
124
- <placeAction(scope="module",name="head")>
125
- <tokenDataModule()>
214
+ <placeAction(scope="module", name="head", ...)>
215
+ <tokenDataModule(...)>
126
216
  <recognizer>
127
- <placeAction(scope="module",name="foot")>
217
+ <placeAction(scope="module", name="foot", ...)>
128
218
  end
129
219
  >>
130
220
 
@@ -163,7 +253,7 @@ parser(
163
253
  <if(grammar.grammarIsRoot)><autoloadDelegates()><endif>
164
254
 
165
255
  class <if(grammar.grammarIsRoot)>Parser<else><grammar.name><endif> \< <superClass>
166
- <parserBody(inputStreamType="ANTLR3::TokenStream", rewriteElementType="Token", actionScope="parser", ...)>
256
+ <parserBody(inputStreamType="ANTLR3::TokenStream", rewriteElementType="Token", actionScope="parser", filterMode="false", ...)>
167
257
  end # class <if(grammar.grammarIsRoot)>Parser<else><grammar.name><endif> \< <superClass>
168
258
  <if(!actions.(actionScope).main)>
169
259
 
@@ -174,7 +264,7 @@ at_exit { <if(grammar.grammarIsRoot)>Parser<else><grammar.name><endif>.main( ARG
174
264
  /** How to generate a tree parser; same as parser except the
175
265
  * input stream is a different type.
176
266
  */
177
- treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, labelType={<ASTLabelType>}, ASTLabelType="Object", superClass="ANTLR3::TreeParser", members={<actions.treeparser.members>}, filterMode) ::= <<
267
+ treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, filterMode, labelType={<ASTLabelType>}, ASTLabelType="Object", superClass="ANTLR3::TreeParser", members={<actions.treeparser.members>}) ::= <<
178
268
  <if(grammar.grammarIsRoot)><autoloadDelegates()><endif>
179
269
 
180
270
  class <if(grammar.grammarIsRoot)>TreeParser<else><grammar.name><endif> \< <superClass>
@@ -186,15 +276,15 @@ at_exit { <if(grammar.grammarIsRoot)>TreeParser<else><grammar.name><endif>.main(
186
276
  <endif>
187
277
  >>
188
278
 
189
- parserBody(grammar, name, scopes, tokens, tokenNames, rules, numRules, bitsets, inputStreamType, superClass, filterMode, ASTLabelType="Object", labelType, members, rewriteElementType, actionScope) ::= <<
279
+ parserBody(grammar, name, scopes, tokens, tokenNames, rules, numRules, bitsets, inputStreamType, superClass, filterMode, labelType, members, rewriteElementType, actionScope, ASTLabelType="Object") ::= <<
190
280
  @grammar_home = <grammar.name>
191
281
  <if(!grammar.grammarIsRoot)><autoloadDelegates()><\n><endif>
192
282
  <@mixins()>
193
283
 
194
- RULE_METHODS = [ <rules:{r|:<r.ruleName>}; separator=", ", wrap="\n", anchor> ].freeze
284
+ RULE_METHODS = [ <rules:{r |:<r.ruleName>}; wrap, anchor, separator=", "> ].freeze
195
285
 
196
- <scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeClass(scope=it)><\n><endif>}>
197
- <rules:{<ruleAttributeScopeClass(scope=it.ruleDescriptor.ruleScope)>}>
286
+ <scopes:{it|<if(it.isDynamicGlobalScope)><globalAttributeScopeClass(it)><\n><endif>}>
287
+ <rules:{it|<ruleAttributeScopeClass(it.ruleDescriptor.ruleScope)>}>
198
288
  <if(grammar.delegators)>
199
289
  masters( <grammar.delegators:{d|:<d.name>}; separator=", "> )<\n>
200
290
  <endif>
@@ -214,11 +304,11 @@ end
214
304
  require '<grammar.composite.rootGrammar.recognizerName>'
215
305
  include <grammar.composite.rootGrammar.name>::TokenData<\n><\n>
216
306
  <endif>
217
- <parserConstructor()>
307
+ <parserConstructor(...)>
218
308
  <@additionalMembers()>
219
309
  <members>
220
310
  # - - - - - - - - - - - - Rules - - - - - - - - - - - - -
221
- <rules:{<it><\n>}>
311
+ <rules:{it | <it><\n>}>
222
312
 
223
313
  <if(grammar.delegatedRules)>
224
314
  # - - - - - - - - - - Delegated Rules - - - - - - - - - - -
@@ -226,17 +316,17 @@ include <grammar.composite.rootGrammar.name>::TokenData<\n><\n>
226
316
  <endif>
227
317
  <if(cyclicDFAs)>
228
318
  # - - - - - - - - - - DFA definitions - - - - - - - - - - -
229
- <cyclicDFAs:{<cyclicDFA(it)>}>
319
+ <cyclicDFAs:{it | <cyclicDFA(it)>}>
230
320
 
231
321
  private
232
322
 
233
323
  def initialize_dfas
234
324
  super rescue nil
235
- <cyclicDFAs:{<cyclicDFAInit(it)>}>
325
+ <cyclicDFAs:{it | <cyclicDFAInit(it)>}>
236
326
  end
237
327
 
238
328
  <endif>
239
- <bitsets:{TOKENS_FOLLOWING_<it.name>_IN_<it.inName>_<it.tokenIndex> = Set[ <it.tokenTypes:{<it>}; separator=", "> ]<\n>}>
329
+ <bitsets:{it|TOKENS_FOLLOWING_<it.name; format="tokenLabel">_IN_<it.inName>_<it.tokenIndex> = Set[ <it.tokenTypes:{it|<it>}; separator=", "> ]<\n>}>
240
330
  >>
241
331
 
242
332
  parserConstructor() ::= <<
@@ -245,8 +335,8 @@ def initialize( <grammar.delegators:{g|<g:delegateName()>, }>input, options = {}
245
335
  <if(memoize)><if(grammar.grammarIsRoot)>
246
336
  @state.rule_memory = {}
247
337
  <endif><endif>
248
- <scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeStack(scope=it)><\n><endif>}><rules:{<ruleAttributeScopeStack(scope=it.ruleDescriptor.ruleScope)>}>
249
- <placeAction(scope=actionScope,name="init")>
338
+ <scopes:{it|<if(it.isDynamicGlobalScope)><globalAttributeScopeStack(it)><\n><endif>}><rules:{it | <ruleAttributeScopeStack(it.ruleDescriptor.ruleScope)>}>
339
+ <placeAction(scope=actionScope, name="init", ...)>
250
340
  <grammar.delegators:{g|@<g:delegateName()> = <g:delegateName()><\n>}><grammar.directDelegates:{g|@<g:delegateName()> = <newDelegate(g)><\n>}><last(grammar.delegators):{g|@parent = @<g:delegateName()><\n>}><@init()>
251
341
  end
252
342
  >>
@@ -263,17 +353,17 @@ end
263
353
  * need to be in a rule by themselves.
264
354
  */
265
355
  synpredRule(ruleName, ruleDescriptor, block, description, nakedBlock) ::= <<
266
- #
356
+ #
267
357
  # syntactic predicate <ruleName>
268
- #
358
+ #
269
359
  # (in <fileName>)
270
360
  # <description>
271
- #
361
+ #
272
362
  # This is an imaginary rule inserted by ANTLR to
273
363
  # implement a syntactic predicate decision
274
- #
275
- def <ruleName><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope(scope=it)> )<endif>
276
- <traceIn()><ruleLabelDefs()>
364
+ #
365
+ def <ruleName><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope()> )<endif>
366
+ <traceIn()><ruleLabelDefs(desc=ruleDescriptor)>
277
367
  <block>
278
368
  ensure
279
369
  <traceOut()>
@@ -285,18 +375,22 @@ end
285
375
  * type data aggregates required for multiple return values.
286
376
  */
287
377
  rule(ruleName, ruleDescriptor, block, emptyRule, description, exceptions, finally, memoize) ::= <<
288
- <returnScope(scope=ruleDescriptor.returnScope)>
378
+ <returnScope(...)>
289
379
 
290
- #
380
+ #
291
381
  # parser rule <ruleName>
292
- #
382
+ #
293
383
  # (in <fileName>)
294
384
  # <description>
295
- #
296
- def <ruleName><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope(scope=it)> )<endif>
297
- <traceIn()><ruleScopeSetUp()><ruleDeclarations()><ruleLabelDefs()><action(name="init", code=ruleDescriptor.actions.init)>
385
+ #
386
+ def <ruleName><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope()> )<endif>
387
+ <traceIn()>
388
+ <ruleScopeSetUp(...)>
389
+ <ruleDeclarations(...)>
390
+ <ruleLabelDefs(desc=ruleDescriptor)>
391
+ <action(name="init", code=ruleDescriptor.actions.init)>
298
392
  <@body><ruleBody()><@end>
299
-
393
+
300
394
  return <ruleReturnValue()>
301
395
  end
302
396
  <if(ruleDescriptor.modifier)>
@@ -307,8 +401,8 @@ end
307
401
 
308
402
  delegateRule(ruleDescriptor) ::= <<
309
403
  # delegated rule <ruleDescriptor.name>
310
- def <ruleDescriptor.name><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope(scope=it)> )<endif>
311
- <methodCall(del=ruleDescriptor.grammar, n=ruleDescriptor.name, args={<ruleDescriptor.parameterScope.attributes:{<it.name>}>})>
404
+ def <ruleDescriptor.name><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope()> )<endif>
405
+ <methodCall(del=ruleDescriptor.grammar, n=ruleDescriptor.name, args={<ruleDescriptor.parameterScope.attributes:{it | <it.name>}>})>
312
406
  end
313
407
  >>
314
408
  // HELPERS
@@ -327,16 +421,16 @@ initializeDelegator() ::= <<
327
421
  @<g:delegateName()> = <g:delegateName()>
328
422
  >>
329
423
 
330
- altSwitchCase() ::= <<
331
- when <i>
424
+ altSwitchCase(altNum,alt) ::= <<
425
+ when <altNum>
332
426
  <@prealt()>
333
- <it>
427
+ <alt>
334
428
  >>
335
429
 
336
430
  blockBody() ::= <<
337
431
  <@decision><decision><@end>
338
432
  case alt_<decisionNumber>
339
- <alts:altSwitchCase(); separator="\n">
433
+ <alts:{a | <altSwitchCase(i,a)>}; separator="\n">
340
434
  end
341
435
  >>
342
436
 
@@ -351,35 +445,43 @@ while true # decision <decisionNumber>
351
445
  alt_<decisionNumber> = <maxAlt>
352
446
  <@decisionBody><decision><@end>
353
447
  case alt_<decisionNumber>
354
- <alts:altSwitchCase(); separator="\n">
448
+ <alts:{a | <altSwitchCase(i,a)>}; separator="\n">
355
449
  else
356
450
  break # out of loop for decision <decisionNumber>
357
451
  end
358
452
  end # loop for decision <decisionNumber>
359
453
  >>
360
454
 
361
- delegateName() ::= <<
362
- <if(it.label)><it.label; format="label"><else><it.name; format="snakecase"><endif>
455
+ delegateName(d) ::= <<
456
+ <if(d.label)><d.label; format="label"><else><d.name; format="snakecase"><endif>
363
457
  >>
364
458
 
365
- element() ::= <<
366
- <it.el><\n>
459
+ element(e) ::= <<
460
+ <e.el><\n>
367
461
  >>
368
462
 
369
463
  execForcedAction(action) ::= "<action>"
370
464
 
371
- globalAttributeScopeClass(scope) ::= <<
372
- <if(scope.attributes)>@@<scope.name> = Scope( <scope.attributes:{<it.decl; format="rubyString">}; separator=", "> )<\n><endif>
373
- >>
465
+ globalAttributeScopeClass(scope) ::= <%
466
+ <if(scope)>
467
+ <if(scope.attributes)>
468
+ @@<scope.name> = Scope(
469
+ <scope.attributes:{it| <it.decl; format="rubyString">}; separator=", "> )<\n>
470
+ <endif>
471
+ <endif>
472
+ %>
374
473
 
375
- globalAttributeScopeStack(scope) ::= <<
376
- <if(scope.attributes)>@<scope.name>_stack = []<\n><endif>
377
- >>
474
+ globalAttributeScopeStack(scope) ::= <%
475
+ <if(scope)>
476
+ <if(scope.attributes)>@<scope.name>_stack = []<\n>
477
+ <endif>
478
+ <endif>
479
+ %>
378
480
 
379
481
  noRewrite(rewriteBlockLevel, treeLevel) ::= ""
380
482
 
381
483
  parameterScope(scope) ::= <<
382
- <scope.attributes:{<it.decl>}; separator=", ">
484
+ <scope.attributes:{it | <it.decl>}; separator=", ">
383
485
  >>
384
486
 
385
487
  positiveClosureBlockLoop() ::= <<
@@ -388,7 +490,7 @@ while true
388
490
  alt_<decisionNumber> = <maxAlt>
389
491
  <@decisionBody><decision><@end>
390
492
  case alt_<decisionNumber>
391
- <alts:altSwitchCase(); separator="\n">
493
+ <alts:{a | <altSwitchCase(i,a)>}; separator="\n">
392
494
  else
393
495
  match_count_<decisionNumber> > 0 and break
394
496
  <ruleBacktrackFailure()>
@@ -400,11 +502,15 @@ while true
400
502
  end<\n>
401
503
  >>
402
504
 
403
- returnScope(scope) ::= <<
505
+ returnScope(ruleDescriptor) ::= <%
404
506
  <if(ruleDescriptor.hasMultipleReturnValues)>
405
- <ruleDescriptor:returnStructName(r=it)> = define_return_scope <scope.attributes:{:<it.decl>}; separator=", ">
507
+ <if(ruleDescriptor.returnScope)>
508
+ <returnStructName(r=ruleDescriptor)> = define_return_scope <ruleDescriptor.returnScope.attributes:{it | :<it.decl>}; separator=", ">
509
+ <else>
510
+ <returnStructName(r=ruleDescriptor)> = define_return_scope
406
511
  <endif>
407
- >>
512
+ <endif>
513
+ %>
408
514
 
409
515
  returnStructName(r) ::= "<r.name; format=\"camelcase\">ReturnValue"
410
516
 
@@ -432,7 +538,7 @@ begin
432
538
  <if(!emptyRule)>
433
539
  <if(actions.(actionScope).rulecatch)>
434
540
 
435
- # - - - - - - - - @rulecatch - - - - - - - -
541
+ # - - - - - - - - @rulecatch - - - - - - - -
436
542
  <actions.(actionScope).rulecatch>
437
543
  <else>
438
544
  rescue ANTLR3::Error::RecognitionError => re
@@ -448,7 +554,7 @@ ensure
448
554
  end
449
555
  >>
450
556
 
451
- ruleReturnValue() ::= <<
557
+ ruleReturnValue() ::= <%
452
558
  <if(!ruleDescriptor.isSynPred)>
453
559
  <if(ruleDescriptor.hasReturnValue)>
454
560
  <if(ruleDescriptor.hasSingleReturnValue)>
@@ -458,7 +564,7 @@ return_value
458
564
  <endif>
459
565
  <endif>
460
566
  <endif>
461
- >>
567
+ %>
462
568
 
463
569
 
464
570
  ruleDeclarations() ::= <<
@@ -468,8 +574,10 @@ return_value = <returnStructName(r=ruleDescriptor)>.new
468
574
  # $rule.start = the first token seen before matching
469
575
  return_value.start = @input.look<\n>
470
576
  <else>
577
+ <if(ruleDescriptor.returnScope)>
471
578
  <ruleDescriptor.returnScope.attributes:{a|<a.name> = <if(a.initValue)><a.initValue><else>nil<endif><\n>}>
472
579
  <endif>
580
+ <endif>
473
581
  <if(memoize)>
474
582
  <ruleDescriptor.name>_start_index = @input.index<\n>
475
583
  <endif>
@@ -479,22 +587,21 @@ ruleLabelDef(label) ::= <<
479
587
  <label.label.text; format="label"> = nil<\n>
480
588
  >>
481
589
 
482
- ruleLabelDefs() ::= <<
590
+ ruleLabelDefs(desc) ::= <<
483
591
  <[
484
- ruleDescriptor.tokenLabels,
485
- ruleDescriptor.tokenListLabels,
486
- ruleDescriptor.wildcardTreeLabels,
487
- ruleDescriptor.wildcardTreeListLabels,
488
- ruleDescriptor.ruleLabels,
489
- ruleDescriptor.ruleListLabels
490
- ]:
491
- {<it.label.text; format="label"> = nil<\n>}
492
- ><[
493
- ruleDescriptor.tokenListLabels,
494
- ruleDescriptor.ruleListLabels,
495
- ruleDescriptor.wildcardTreeListLabels
496
- ]:
497
- {list_of_<it.label.text; format="label"> = []<\n>}
592
+ desc.tokenLabels,
593
+ desc.tokenListLabels,
594
+ desc.wildcardTreeLabels,
595
+ desc.wildcardTreeListLabels,
596
+ desc.ruleLabels,
597
+ desc.ruleListLabels
598
+ ]:{it|<if(it.label)><it.label.text; format="label"> = nil<\n><endif>}
599
+ >
600
+ <[
601
+ desc.tokenListLabels,
602
+ desc.ruleListLabels,
603
+ desc.wildcardTreeListLabels
604
+ ]:{it|<if(it.label)>list_of_<it.label.text; format="label"> = []<\n><endif>}
498
605
  >
499
606
  >>
500
607
 
@@ -539,11 +646,11 @@ end<\n>
539
646
 
540
647
 
541
648
  ruleScopeSetUp() ::= <<
542
- <ruleDescriptor.useScopes:{@<it>_stack.push( @@<it>.new )<\n>}><ruleDescriptor.ruleScope:{@<it.name>_stack.push( @@<it.name>.new )<\n>}>
649
+ <ruleDescriptor.useScopes:{it | @<it>_stack.push( @@<it>.new )<\n>}><ruleDescriptor.ruleScope:{it | @<it.name>_stack.push( @@<it.name>.new )<\n>}>
543
650
  >>
544
651
 
545
652
  ruleScopeCleanUp() ::= <<
546
- <ruleDescriptor.useScopes:{@<it>_stack.pop<\n>}><ruleDescriptor.ruleScope:{@<it.name>_stack.pop<\n>}>
653
+ <ruleDescriptor.useScopes:{it | @<it>_stack.pop<\n>}><ruleDescriptor.ruleScope:{it | @<it.name>_stack.pop<\n>}>
547
654
  >>
548
655
 
549
656
  memoize() ::= <<
@@ -576,7 +683,7 @@ alt_<decisionNumber> = <maxAlt>
576
683
  <decls>
577
684
  <@decision><decision><@end>
578
685
  case alt_<decisionNumber>
579
- <alts:altSwitchCase(); separator="\n">
686
+ <alts:{a | <altSwitchCase(i,a)>}; separator="\n">
580
687
  end
581
688
  >>
582
689
 
@@ -632,19 +739,19 @@ alt(elements,altNum,description,autoAST,outerAlt,treeLevel,rew) ::= <<
632
739
  >>
633
740
 
634
741
  /** match a token optionally with a label in front */
635
- tokenRef(token,label,elementIndex,hetero) ::= <<
636
- <if(label)><label; format="label"> = <endif>match( <token>, TOKENS_FOLLOWING_<token>_IN_<ruleName>_<elementIndex> )
742
+ tokenRef(token,label,elementIndex,terminalOptions) ::= <<
743
+ <if(label)><label; format="label"> = <endif>match( <token; format="tokenLabel">, TOKENS_FOLLOWING_<token; format="tokenLabel">_IN_<ruleName>_<elementIndex> )
637
744
  >>
638
745
 
639
746
  /** ids+=ID */
640
- tokenRefAndListLabel(token,label,elementIndex,hetero) ::= <<
747
+ tokenRefAndListLabel(token,label,elementIndex,terminalOptions) ::= <<
641
748
  <tokenRef(...)>
642
749
  <addToList(elem={<label; format="label">},...)>
643
750
  >>
644
751
 
645
752
  /* TRY THIS:
646
- tokenRefAndListLabel(token,label,elementIndex,hetero) ::= <<
647
- list_of_<label; format="label"> << match( <token>, TOKENS_FOLLOWING_<token>_IN_<ruleName>_<elementIndex> )
753
+ tokenRefAndListLabel(token,label,elementIndex,terminalOptions) ::= <<
754
+ list_of_<label; format="label"> << match( <token; format="tokenLabel">, TOKENS_FOLLOWING_<token; format="tokenLabel">_IN_<ruleName>_<elementIndex> )
648
755
  >>
649
756
  */
650
757
 
@@ -655,7 +762,7 @@ list_of_<label; format="label"> \<\< <elem><\n>
655
762
  listLabel ::= addToList
656
763
 
657
764
  /** For now, sets are interval tests and must be tested inline */
658
- matchSet(s,label,elementIndex,postmatchCode) ::= <<
765
+ matchSet(s,label,elementIndex,terminalOptions,postmatchCode) ::= <<
659
766
  <if(label)>
660
767
  <label; format="label"> = @input.look<\n>
661
768
  <endif>
@@ -687,7 +794,7 @@ matchSetAndListLabel(s,label,elementIndex,postmatchCode) ::= <<
687
794
 
688
795
  matchRuleBlockSet ::= matchSet
689
796
 
690
- wildcard(label,elementIndex) ::= <<
797
+ wildcard(token,label,elementIndex,terminalOptions) ::= <<
691
798
  <if(label)>
692
799
  <label; format="label"> = @input.look<\n>
693
800
  <endif>
@@ -700,7 +807,7 @@ wildcard(label,elementIndex) ::= <<
700
807
  >>
701
808
  */
702
809
 
703
- wildcardAndListLabel(label,elementIndex) ::= <<
810
+ wildcardAndListLabel(token,label,elementIndex,terminalOptions) ::= <<
704
811
  <wildcard(...)>
705
812
  <addToList(elem={<label; format="label">},...)>
706
813
  >>
@@ -710,7 +817,7 @@ wildcardAndListLabel(label,elementIndex) ::= <<
710
817
  * arguments and a return value or values.
711
818
  */
712
819
  ruleRef(rule,label,elementIndex,args,scope) ::= <<
713
- @state.following.push( TOKENS_FOLLOWING_<rule.name>_IN_<ruleName>_<elementIndex> )
820
+ @state.following.push( TOKENS_FOLLOWING_<rule.name; format="tokenLabel">_IN_<ruleName>_<elementIndex> )
714
821
  <if(label)><label; format="label"> = <endif><methodCall(del=scope, n={<rule.name>}, args=args)>
715
822
  @state.following.pop
716
823
  >>
@@ -857,7 +964,7 @@ end
857
964
  >>
858
965
 
859
966
  dfaEdgeSwitch(labels, targetState) ::= <<
860
- when <labels:{<it>}; separator=", "> then <targetState>
967
+ when <labels:{it|<it; format="tokenLabel">}; separator=", "> then <targetState>
861
968
  >>
862
969
 
863
970
  /** The code to initiate execution of a cyclic DFA; this is used
@@ -887,15 +994,15 @@ class DFA<dfa.decisionNumber> \< ANTLR3::DFA
887
994
  TRANSITION = [
888
995
  <dfa.javaCompressedTransition:{s|unpack( <s; wrap="\n", anchor, separator=", "> )}; separator=",\n">
889
996
  ].freeze
890
-
997
+
891
998
  ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
892
- if a \> 0 and z \< 0
999
+ if a > 0 and z \< 0
893
1000
  MAX[ i ] %= 0x10000
894
1001
  end
895
1002
  end
896
-
1003
+
897
1004
  @decision = <dfa.decisionNumber>
898
-
1005
+
899
1006
  <@errorMethod()>
900
1007
  <if(dfa.description)>
901
1008
 
@@ -935,7 +1042,7 @@ cyclicDFAInit(dfa) ::= <<
935
1042
  <dfa.specialStateSTs:{state|when <i0>
936
1043
  <state>}; separator="\n">
937
1044
  end
938
-
1045
+
939
1046
  if s \< 0
940
1047
  <if(backtracking)>
941
1048
  @state.backtracking > 0 and raise ANTLR3::Error::BacktrackingFailed<\n>
@@ -944,7 +1051,7 @@ cyclicDFAInit(dfa) ::= <<
944
1051
  @dfa<dfa.decisionNumber>.error( nva )
945
1052
  raise nva
946
1053
  end
947
-
1054
+
948
1055
  s
949
1056
  end<\n>
950
1057
  <else>
@@ -988,15 +1095,15 @@ e
988
1095
 
989
1096
  andPredicates(left,right) ::= "( <left> ) and ( <right> )"
990
1097
 
991
- orPredicates(operands) ::= "( <first(operands)> )<rest(operands):{o| or ( <o> )}>"
1098
+ orPredicates(operands) ::= "<operands:{o|( <o> )}; separator=\" or \">"
992
1099
 
993
1100
  notPredicate(pred) ::= "not ( <pred> )"
994
1101
 
995
1102
  evalPredicate(pred,description) ::= "( <pred> )"
996
1103
 
997
- evalSynPredicate(pred,description) ::= <<
998
- syntactic_predicate?( :<pred:{<it>}> )
999
- >>
1104
+ evalSynPredicate(pred,description) ::= <%
1105
+ syntactic_predicate?( :<pred:{it | <it>}> )
1106
+ %>
1000
1107
 
1001
1108
  lookaheadTest(atom, k, atomAsInt) ::= "look_<decisionNumber>_<stateNumber> == <atom>"
1002
1109
 
@@ -1006,23 +1113,23 @@ lookaheadTest(atom, k, atomAsInt) ::= "look_<decisionNumber>_<stateNumber> == <a
1006
1113
  */
1007
1114
  isolatedLookaheadTest(atom, k, atomAsInt) ::= "@input.peek(<k>) == <atom>"
1008
1115
 
1009
- lookaheadRangeTest(lower, upper, k, rangeNumber, lowerAsInt, upperAsInt) ::= <<
1116
+ lookaheadRangeTest(lower, upper, k, rangeNumber, lowerAsInt, upperAsInt) ::= <%
1010
1117
  look_<decisionNumber>_<stateNumber>.between?( <lower>, <upper> )
1011
- >>
1118
+ %>
1012
1119
 
1013
- isolatedLookaheadRangeTest(lower, upper, k, rangeNumber, lowerAsInt, upperAsInt) ::= <<
1120
+ isolatedLookaheadRangeTest(lower, upper, k, rangeNumber, lowerAsInt, upperAsInt) ::= <%
1014
1121
  @input.peek( <k> ).between?( <lower>, <upper> )
1015
- >>
1122
+ %>
1016
1123
 
1017
- setTest(ranges) ::= <<
1124
+ setTest(ranges) ::= <%
1018
1125
  <ranges; separator=" || ">
1019
- >>
1126
+ %>
1020
1127
 
1021
1128
  parameterAttributeRef(attr) ::= "<attr.name>"
1022
1129
 
1023
1130
  parameterSetAttributeRef(attr,expr) ::= "<attr.name> = <expr>"
1024
1131
 
1025
- scopeAttributeRef(scope, attr, index, negIndex) ::= <<
1132
+ scopeAttributeRef(scope, attr, index, negIndex) ::= <%
1026
1133
  <if(negIndex)>
1027
1134
  @<scope>_stack[ -<negIndex> ].<attr.name>
1028
1135
  <else>
@@ -1032,10 +1139,10 @@ scopeAttributeRef(scope, attr, index, negIndex) ::= <<
1032
1139
  @<scope>_stack.last.<attr.name>
1033
1140
  <endif>
1034
1141
  <endif>
1035
- >>
1142
+ %>
1036
1143
 
1037
1144
 
1038
- scopeSetAttributeRef(scope, attr, expr, index, negIndex) ::= <<
1145
+ scopeSetAttributeRef(scope, attr, expr, index, negIndex) ::= <%
1039
1146
  <if(negIndex)>
1040
1147
  @<scope>_stack[ -<negIndex> ].<attr.name> = <expr>
1041
1148
  <else>
@@ -1045,7 +1152,7 @@ scopeSetAttributeRef(scope, attr, expr, index, negIndex) ::= <<
1045
1152
  @<scope>_stack.last.<attr.name> = <expr>
1046
1153
  <endif>
1047
1154
  <endif>
1048
- >>
1155
+ %>
1049
1156
 
1050
1157
 
1051
1158
  /** $x is either global scope or x is rule with dynamic scope;
@@ -1058,29 +1165,29 @@ isolatedDynamicScopeRef(scope) ::= "@<scope>_stack"
1058
1165
  /** reference an attribute of rule; might only have single
1059
1166
  * return value
1060
1167
  */
1061
- ruleLabelRef(referencedRule, scope, attr) ::= <<
1168
+ ruleLabelRef(referencedRule, scope, attr) ::= <%
1062
1169
  <if(referencedRule.hasMultipleReturnValues)>
1063
1170
  ( <scope; format="label">.nil? ? nil : <scope; format="label">.<attr.name> )
1064
1171
  <else>
1065
1172
  <scope; format="label">
1066
1173
  <endif>
1067
- >>
1174
+ %>
1068
1175
 
1069
- returnAttributeRef(ruleDescriptor, attr) ::= <<
1176
+ returnAttributeRef(ruleDescriptor, attr) ::= <%
1070
1177
  <if(ruleDescriptor.hasMultipleReturnValues)>
1071
1178
  return_value.<attr.name>
1072
1179
  <else>
1073
1180
  <attr.name>
1074
1181
  <endif>
1075
- >>
1182
+ %>
1076
1183
 
1077
- returnSetAttributeRef(ruleDescriptor, attr, expr) ::= <<
1184
+ returnSetAttributeRef(ruleDescriptor, attr, expr) ::= <%
1078
1185
  <if(ruleDescriptor.hasMultipleReturnValues)>
1079
1186
  return_value.<attr.name> = <expr>
1080
1187
  <else>
1081
1188
  <attr.name> = <expr>
1082
1189
  <endif>
1083
- >>
1190
+ %>
1084
1191
 
1085
1192
  /** How to translate $tokenLabel */
1086
1193
  tokenLabelRef(label) ::= "<label; format=\"label\">"
@@ -1100,7 +1207,7 @@ ruleLabelPropertyRef_start(scope, attr) ::= "<scope; format=\"label\">.start"
1100
1207
  ruleLabelPropertyRef_stop(scope, attr) ::= "<scope; format=\"label\">.stop"
1101
1208
  ruleLabelPropertyRef_tree(scope, attr) ::= "<scope; format=\"label\">.tree"
1102
1209
 
1103
- ruleLabelPropertyRef_text(scope, attr) ::= <<
1210
+ ruleLabelPropertyRef_text(scope, attr) ::= <%
1104
1211
  <if(TREE_PARSER)>
1105
1212
  (
1106
1213
  @input.token_stream.to_s(
@@ -1111,7 +1218,7 @@ ruleLabelPropertyRef_text(scope, attr) ::= <<
1111
1218
  <else>
1112
1219
  ( <scope; format="label"> && @input.to_s( <scope; format="label">.start, <scope; format="label">.stop ) )
1113
1220
  <endif>
1114
- >>
1221
+ %>
1115
1222
  ruleLabelPropertyRef_st(scope, attr) ::= "( <scope; format=\"label\"> && <scope; format=\"label\">.template )"
1116
1223
 
1117
1224
  /******************************************************************************
@@ -1120,7 +1227,7 @@ ruleLabelPropertyRef_st(scope, attr) ::= "( <scope; format=\"label\"> && <scope;
1120
1227
 
1121
1228
  lexerSynpred(name) ::= ""
1122
1229
 
1123
- lexer(grammar, name, tokens, scopes, rules, numRules, labelType="ANTLR3::Token", filterMode, superClass="ANTLR3::Lexer") ::= <<
1230
+ lexer(grammar, name, tokens, scopes, rules, numRules, filterMode, labelType="ANTLR3::Token", superClass="ANTLR3::Lexer") ::= <<
1124
1231
  <if(grammar.grammarIsRoot)><autoloadDelegates()><endif>
1125
1232
 
1126
1233
  class <if(grammar.delegator)><grammar.name><else>Lexer<endif> \< <superClass>
@@ -1132,14 +1239,14 @@ class <if(grammar.delegator)><grammar.name><else>Lexer<endif> \< <superClass>
1132
1239
  <if(filterMode)>
1133
1240
  include ANTLR3::FilterMode<\n>
1134
1241
  <endif>
1135
- <scopes:{<if(it.isDynamicGlobalScope)><globalAttributeScopeClass(scope=it)><\n><endif>}>
1136
-
1242
+ <scopes:{it | <if(it.isDynamicGlobalScope)><globalAttributeScopeClass(scope=it)><\n><endif>}>
1243
+
1137
1244
  begin
1138
1245
  generated_using( "<fileName>", "<ANTLRVersion>", "<runtimeLibraryVersion()>" )
1139
1246
  rescue NoMethodError => error
1140
1247
  # ignore
1141
1248
  end
1142
-
1249
+
1143
1250
  RULE_NAMES = [ <trunc(rules):{r|"<r.ruleName>"}; separator=", ", wrap="\n", anchor> ].freeze
1144
1251
  RULE_METHODS = [ <trunc(rules):{r|:<r.ruleName; format="lexerRule">}; separator=", ", wrap="\n", anchor> ].freeze
1145
1252
 
@@ -1149,7 +1256,7 @@ class <if(grammar.delegator)><grammar.name><else>Lexer<endif> \< <superClass>
1149
1256
  <if(grammar.directDelegates)>
1150
1257
  imports( <grammar.directDelegates:{d|:<d.name>}; separator=", "> )<\n>
1151
1258
  <endif>
1152
-
1259
+
1153
1260
  def initialize( <grammar.delegators:{g|<g:delegateName()>, }>input=nil, options = {} )
1154
1261
  super( input, options )
1155
1262
  <if(memoize)>
@@ -1157,25 +1264,25 @@ class <if(grammar.delegator)><grammar.name><else>Lexer<endif> \< <superClass>
1157
1264
  @state.rule_memory = {}<\n>
1158
1265
  <endif>
1159
1266
  <endif>
1160
- <grammar.delegators:{g|@<g:delegateName()> = <g:delegateName()><\n>}><grammar.directDelegates:{g|@<g:delegateName()> = <newDelegate(g)><\n>}><last(grammar.delegators):{g|@parent = @<g:delegateName()><\n>}><placeAction(scope="lexer",name="init")>
1267
+ <grammar.delegators:{g|@<g:delegateName()> = <g:delegateName()><\n>}><grammar.directDelegates:{g|@<g:delegateName()> = <newDelegate(g)><\n>}><last(grammar.delegators):{g|@parent = @<g:delegateName()><\n>}><placeAction(scope="lexer", name="init", ...)>
1161
1268
  end
1162
-
1163
- <placeAction(scope="lexer",name="members")>
1164
-
1269
+
1270
+ <placeAction(scope="lexer", name="members", ...)>
1271
+
1165
1272
  # - - - - - - - - - - - lexer rules - - - - - - - - - - - -
1166
- <rules:{<it><\n>}>
1273
+ <rules:{it | <it><\n>}>
1167
1274
  <if(grammar.delegatedRules)>
1168
-
1275
+
1169
1276
  # - - - - - - - - - - delegated rules - - - - - - - - - - -
1170
1277
  <grammar.delegatedRules:{ruleDescriptor|<delegateLexerRule(ruleDescriptor)><\n><\n>}>
1171
1278
  <endif>
1172
1279
  <if(cyclicDFAs)>
1173
-
1280
+
1174
1281
  # - - - - - - - - - - DFA definitions - - - - - - - - - - -
1175
1282
  <cyclicDFAs:cyclicDFA()>
1176
-
1283
+
1177
1284
  private
1178
-
1285
+
1179
1286
  def initialize_dfas
1180
1287
  super rescue nil
1181
1288
  <cyclicDFAs:cyclicDFAInit()>
@@ -1193,8 +1300,8 @@ at_exit { <if(grammar.delegator)><grammar.name><else>Lexer<endif>.main( ARGV ) }
1193
1300
  lexerRuleLabelDefs() ::= <<
1194
1301
  <if([ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels,ruleDescriptor.ruleLabels,ruleDescriptor.charLabels,ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels])>
1195
1302
  # - - - - label initialization - - - -
1196
- <[ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels,ruleDescriptor.ruleLabels,ruleDescriptor.charLabels]:{<it.label.text; format="label"> = nil<\n>}>
1197
- <[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]:{list_of_<it.label.text; format="label"> = [] unless defined?(list_of_<it.label.text; format="label">)<\n>}>
1303
+ <[ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels,ruleDescriptor.ruleLabels,ruleDescriptor.charLabels]:{it | <it.label.text; format="label"> = nil<\n>}>
1304
+ <[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]:{it | list_of_<it.label.text; format="label"> = [] unless defined?(list_of_<it.label.text; format="label">)<\n>}>
1198
1305
  <endif>
1199
1306
  >>
1200
1307
 
@@ -1205,17 +1312,17 @@ lexerRuleLabelDefs() ::= <<
1205
1312
  lexerRule(ruleName,nakedBlock,ruleDescriptor,block,memoize) ::= <<
1206
1313
  # lexer rule <ruleName; format="lexerRule"> (<ruleName>)
1207
1314
  # (in <fileName>)
1208
- def <ruleName; format="lexerRule"><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope(scope=it)> )<endif>
1209
- <traceIn()><ruleScopeSetUp()><ruleDeclarations()><if(memoize)>
1315
+ def <ruleName; format="lexerRule"><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope()> )<endif>
1316
+ <traceIn(...)><ruleScopeSetUp(...)><ruleDeclarations(...)><if(memoize)>
1210
1317
  <if(backtracking)>
1211
-
1318
+
1212
1319
  # backtracking success
1213
1320
  success = false<\n>
1214
1321
  <endif>
1215
1322
  <endif>
1216
1323
  <if(nakedBlock)>
1217
1324
  <ruleMemoization({<ruleName; format="lexerRule">})><lexerRuleLabelDefs()><action(name="init", code=ruleDescriptor.actions.init)>
1218
-
1325
+
1219
1326
  # - - - - main rule block - - - -
1220
1327
  <block>
1221
1328
  <else>
@@ -1223,11 +1330,11 @@ def <ruleName; format="lexerRule"><if(ruleDescriptor.parameterScope)>( <ruleDesc
1223
1330
  type = <ruleName>
1224
1331
  channel = ANTLR3::DEFAULT_CHANNEL
1225
1332
  <ruleMemoization(ruleName)><lexerRuleLabelDefs()><action(name="init", code=ruleDescriptor.actions.init)>
1226
-
1333
+
1227
1334
  # - - - - main rule block - - - -
1228
1335
  <block>
1229
1336
  <ruleCleanUp()>
1230
-
1337
+
1231
1338
  @state.type = type
1232
1339
  @state.channel = channel
1233
1340
  <(ruleDescriptor.actions.after):execAction()>
@@ -1262,7 +1369,7 @@ tokensRule(ruleName,nakedBlock,args,block,ruleDescriptor) ::= <<
1262
1369
  # main rule used to study the input at the current position,
1263
1370
  # and choose the proper lexer rule to call in order to
1264
1371
  # fetch the next token
1265
- #
1372
+ #
1266
1373
  # usually, you don't make direct calls to this method,
1267
1374
  # but instead use the next_token method, which will
1268
1375
  # build and emit the actual next token
@@ -1376,6 +1483,13 @@ match( ANTLR3::EOF )<\n>
1376
1483
  <endif>
1377
1484
  >>
1378
1485
 
1486
+ // used for left-recursive rules
1487
+ recRuleDefArg() ::= "int <recRuleArg()>"
1488
+ recRuleArg() ::= "_p"
1489
+ recRuleAltPredicate(ruleName,opPrec) ::= "<recRuleArg()> \<= <opPrec>"
1490
+ recRuleSetResultAction() ::= "root_0=$<ruleName>_primary.tree;"
1491
+ recRuleSetReturnAction(src,name) ::= "$<name>=$<src>.<name>;"
1492
+
1379
1493
  /** $start in parser rule */
1380
1494
  rulePropertyRef_start(scope, attr) ::= "return_value.start"
1381
1495
 
@@ -1413,50 +1527,5 @@ end
1413
1527
 
1414
1528
  codeFileExtension() ::= ".rb"
1415
1529
 
1416
- true() ::= "true"
1417
- false() ::= "false"
1418
-
1419
- action(name, code) ::= <<
1420
- <if(code)>
1421
- # - - - - @<name> action - - - -
1422
- <code><\n>
1423
- <endif>
1424
- >>
1425
-
1426
- autoloadDelegates() ::= <<
1427
- <if(grammar.directDelegates)>
1428
- <grammar.directDelegates:{autoload :<it.name>, "<it.recognizerName>"<\n>}>
1429
- <endif>
1430
- >>
1431
-
1432
- delegateLexerRule(ruleDescriptor) ::= <<
1433
- # delegated lexer rule <ruleDescriptor.name; format="lexerRule"> (<ruleDescriptor.name> in the grammar)
1434
- def <ruleDescriptor.name; format="lexerRule"><if(ruleDescriptor.parameterScope)>( <ruleDescriptor.parameterScope:parameterScope(scope=it)> )<endif>
1435
- <methodCall(del=ruleDescriptor.grammar, n={<ruleDescriptor.name; format="lexerRule">}, args=ruleDescriptor.parameterScope.attributes)>
1436
- end
1437
- >>
1438
-
1439
- rootClassName() ::= <<
1440
- <if(grammar.grammarIsRoot)><grammar.name><else><grammar.composite.rootGrammar.name><endif>::<if(TREE_PARSER)>TreeParser<elseif(PARSER)>Parser<else>Lexer<endif>
1441
- >>
1442
-
1443
- grammarClassName() ::= <<
1444
- <gram.name>::<if(TREE_PARSER)>TreeParser<elseif(PARSER)>Parser<else>Lexer<endif>
1445
- >>
1446
-
1447
- newDelegate(gram) ::= <<
1448
- <gram.name>.new( <trunc(gram.delegators):{p|<p:delegateName()>, }>
1449
- self, @input, :state => @state<@delegateOptions()>
1450
- )
1451
- >>
1452
-
1453
- placeAction(scope, name) ::= <<
1454
- <if(actions.(scope).(name))>
1455
- # - - - - - - begin action @<scope>::<name> - - - - - -
1456
- <if(fileName)># <fileName><\n><endif>
1457
- <actions.(scope).(name)>
1458
- # - - - - - - end action @<scope>::<name> - - - - - - -<\n>
1459
- <endif>
1460
- >>
1461
-
1462
- runtimeLibraryVersion() ::= "1.8.13"
1530
+ true_value() ::= "true"
1531
+ false_value() ::= "false"