antlr3 1.8.13 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -59,10 +59,8 @@ module Constants
59
59
  MEMO_RULE_UNKNOWN = -1
60
60
 
61
61
  # built-in token types used internally by ANTLR3
62
-
63
- INVALID_TOKEN_TYPE = 0
64
-
65
- EOF = -1
62
+ INVALID = INVALID_TOKEN_TYPE = 0
63
+ EOF = -1
66
64
 
67
65
 
68
66
  # Imaginary tree-navigation token type indicating the ascent after moving through the
@@ -86,12 +84,10 @@ module Constants
86
84
  end
87
85
 
88
86
  BUILT_IN_TOKEN_NAMES.update(
89
- 0 => "<invalid>".freeze, 1 => "<EOR>".freeze,
90
- 2 => "<DOWN>".freeze, 3 => "<UP>".freeze,
87
+ 0 => "<invalid>".freeze, 1 => "<EOR>".freeze,
88
+ 2 => "<DOWN>".freeze, 3 => "<UP>".freeze,
91
89
  -1 => "<EOF>".freeze
92
90
  )
93
-
94
-
95
91
  end
96
92
 
97
93
  include Constants
@@ -35,6 +35,7 @@ TODO: finish documentation
35
35
  =end
36
36
 
37
37
  class CompileTask < Rake::TaskLib
38
+ defined?( Rake::DSL ) and include( Rake::DSL )
38
39
  attr_reader :grammar_sets, :options
39
40
  attr_accessor :name
40
41
 
@@ -432,6 +433,7 @@ private
432
433
  end # class Grammar
433
434
 
434
435
  class GrammarFile::Imported < GrammarFile
436
+ defined?( Rake::DSL ) and include( Rake::DSL )
435
437
  def initialize( owner, path )
436
438
  @owner = owner
437
439
  @path = path.to_s
@@ -8,6 +8,7 @@ require 'antlr3/test/call-stack'
8
8
 
9
9
  require 'test/unit'
10
10
  require 'spec'
11
+ require 'spec/interop/test'
11
12
 
12
13
  module ANTLR3
13
14
  module Test
@@ -497,6 +497,15 @@ dynamically-created CommonToken subclass.
497
497
  =end
498
498
 
499
499
  class TokenScheme < ::Module
500
+ #
501
+ # introduced due to deprecation warning of Hash#index in Ruby 1.9.3
502
+ #
503
+ if ::Hash.method_defined?( :key )
504
+ FETCH_KEY = proc { | h, v | h.key( v ) }
505
+ else
506
+ FETCH_KEY = proc { | h, v | h.index( v ) }
507
+ end
508
+
500
509
  include TokenFactory
501
510
 
502
511
  def self.new( tk_class = nil, &body )
@@ -640,7 +649,7 @@ class TokenScheme < ::Module
640
649
  def []( name_or_value )
641
650
  case name_or_value
642
651
  when Integer then token_names.fetch( name_or_value, nil )
643
- else const_get( name_or_value.to_s ) rescue token_names.index( name_or_value )
652
+ else const_get( name_or_value.to_s ) rescue FETCH_KEY.call( token_names, name_or_value )
644
653
  end
645
654
  end
646
655
 
@@ -8,8 +8,8 @@ module ANTLR3
8
8
  # testing the current version of this library
9
9
  #
10
10
  ANTLR_MAJOR_VERSION = 3
11
- ANTLR_MINOR_VERSION = 2
12
- ANTLR_PATCH_VERSION = 1
11
+ ANTLR_MINOR_VERSION = 5
12
+ ANTLR_PATCH_VERSION = 0
13
13
  ANTLR_VERSION = [ ANTLR_MAJOR_VERSION, ANTLR_MINOR_VERSION, ANTLR_PATCH_VERSION ].freeze
14
14
  ANTLR_VERSION_STRING = ANTLR_VERSION.join( '.' )
15
15
  ANTLR_VERSION_STRING.chomp!( '.0' ) # versioning drops minor version at 0
@@ -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 = 8
23
- PATCH_VERSION = 13
22
+ MINOR_VERSION = 9
23
+ PATCH_VERSION = 0
24
24
  VERSION = [ MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION ]
25
25
  VERSION_STRING = VERSION.join( '.' ).freeze
26
26
 
data/rakefile CHANGED
@@ -15,45 +15,45 @@ Hoe.spec "antlr3" do
15
15
  )
16
16
 
17
17
  self.test_globs = [
18
+ "test/unit/test-exceptions.rb",
19
+ "test/unit/test-trees.rb",
18
20
  "test/unit/test-scope.rb",
19
- "test/unit/test-template.rb",
20
21
  "test/unit/test-tree-wizard.rb",
21
- "test/unit/test-unicode-stream.rb",
22
- "test/unit/test-scheme.rb",
23
- "test/unit/test-trees.rb",
24
22
  "test/unit/test-streams.rb",
25
- "test/unit/test-dfa.rb",
26
23
  "test/unit/test-recognizers.rb",
27
- "test/unit/test-exceptions.rb",
28
- "test/functional/ast-output/auto-ast.rb",
29
- "test/functional/ast-output/hetero-nodes.rb",
30
- "test/functional/ast-output/construction.rb",
31
- "test/functional/ast-output/rewrites.rb",
32
- "test/functional/ast-output/tree-rewrite.rb",
33
- "test/functional/token-rewrite/via-parser.rb",
34
- "test/functional/token-rewrite/basic.rb",
35
- "test/functional/main/main-scripts.rb",
24
+ "test/unit/test-template.rb",
25
+ "test/unit/test-unicode-stream.rb",
26
+ "test/unit/test-dfa.rb",
27
+ "test/unit/test-scheme.rb",
36
28
  "test/functional/tree-parser/basic.rb",
37
- "test/functional/parser/nuances.rb",
38
- "test/functional/parser/backtracking.rb",
39
- "test/functional/parser/properties.rb",
40
- "test/functional/parser/scopes.rb",
41
- "test/functional/parser/rule-methods.rb",
29
+ "test/functional/parser/actions.rb",
42
30
  "test/functional/parser/predicates.rb",
43
31
  "test/functional/parser/calc.rb",
44
32
  "test/functional/parser/basic.rb",
33
+ "test/functional/parser/rule-methods.rb",
34
+ "test/functional/parser/properties.rb",
35
+ "test/functional/parser/scopes.rb",
36
+ "test/functional/parser/nuances.rb",
37
+ "test/functional/parser/backtracking.rb",
45
38
  "test/functional/parser/ll-star.rb",
46
- "test/functional/parser/actions.rb",
47
- "test/functional/lexer/filter-mode.rb",
48
- "test/functional/lexer/nuances.rb",
49
- "test/functional/lexer/properties.rb",
50
- "test/functional/lexer/basic.rb",
51
- "test/functional/lexer/syn-pred.rb",
52
- "test/functional/lexer/xml.rb",
53
39
  "test/functional/debugging/rule-tracing.rb",
54
40
  "test/functional/debugging/profile-mode.rb",
55
41
  "test/functional/debugging/debug-mode.rb",
42
+ "test/functional/main/main-scripts.rb",
43
+ "test/functional/lexer/filter-mode.rb",
44
+ "test/functional/lexer/basic.rb",
45
+ "test/functional/lexer/properties.rb",
46
+ "test/functional/lexer/xml.rb",
47
+ "test/functional/lexer/nuances.rb",
48
+ "test/functional/lexer/syn-pred.rb",
49
+ "test/functional/ast-output/construction.rb",
50
+ "test/functional/ast-output/hetero-nodes.rb",
51
+ "test/functional/ast-output/tree-rewrite.rb",
52
+ "test/functional/ast-output/auto-ast.rb",
53
+ "test/functional/ast-output/rewrites.rb",
56
54
  "test/functional/delegation/import.rb",
55
+ "test/functional/token-rewrite/basic.rb",
56
+ "test/functional/token-rewrite/via-parser.rb",
57
57
  "test/functional/template-output/template-output.rb"
58
58
  ]
59
59
 
@@ -20,14 +20,14 @@ ruleDeclarations() ::= <<
20
20
  root_0 = nil<\n>
21
21
  >>
22
22
 
23
- ruleLabelDefs() ::= <<
24
- <super.ruleLabelDefs()>
23
+ ruleLabelDefs(desc) ::= <<
24
+ <super.ruleLabelDefs(desc)>
25
25
  <[ruleDescriptor.tokenLabels,ruleDescriptor.wildcardTreeLabels,ruleDescriptor.wildcardTreeListLabels,ruleDescriptor.tokenListLabels]
26
- :{tree_for_<it.label.text> = nil}; separator="\n">
26
+ :{it|tree_for_<it.label.text> = nil}; separator="\n">
27
27
  <ruleDescriptor.allTokenRefsInAltsWithRewrites
28
- :{stream_<it> = ANTLR3::AST::RewriteRule<rewriteElementType>Stream.new( @adaptor, "token <it>" )}; separator="\n">
28
+ :{it|stream_<it> = ANTLR3::AST::RewriteRule<rewriteElementType>Stream.new( @adaptor, "token <it>" )}; separator="\n">
29
29
  <ruleDescriptor.allRuleRefsInAltsWithRewrites
30
- :{stream_<it> = ANTLR3::AST::RewriteRuleSubtreeStream.new( @adaptor, "rule <it>" )}; separator="\n">
30
+ :{it|stream_<it> = ANTLR3::AST::RewriteRuleSubtreeStream.new( @adaptor, "rule <it>" )}; separator="\n">
31
31
  >>
32
32
 
33
33
  alt(elements,altNum,description,autoAST,outerAlt,treeLevel,rew) ::= <<
@@ -38,22 +38,22 @@ root_0 = @adaptor.create_flat_list<\n><\n>
38
38
  <elements:element()><rew>
39
39
  >>
40
40
 
41
- tokenRefTrack(token,label,elementIndex,hetero) ::= <<
41
+ tokenRefTrack(token,label,elementIndex,terminalOptions={}) ::= <<
42
42
  <tokenRefBang(...)>
43
43
  <gatedAction({stream_<token>.add( <label; format="label"> )})>
44
44
  >>
45
45
 
46
- tokenRefTrackAndListLabel(token,label,elementIndex,hetero) ::= <<
46
+ tokenRefTrackAndListLabel(token,label,elementIndex,terminalOptions={}) ::= <<
47
47
  <tokenRefTrack(...)>
48
48
  <addToList(elem={<label; format="label">},...)>
49
49
  >>
50
50
 
51
- tokenRefRuleRootTrack(token,label,elementIndex,hetero) ::= <<
51
+ tokenRefRuleRootTrack(token,label,elementIndex,terminalOptions={}) ::= <<
52
52
  <tokenRefBang(...)>
53
53
  <gatedAction({stream_<token>.add( <label; format="label"> )})>
54
54
  >>
55
55
 
56
- tokenRefRuleRootTrackAndListLabel(token,label,elementIndex,hetero) ::= <<
56
+ tokenRefRuleRootTrackAndListLabel(token,label,elementIndex,terminalOptions={}) ::= <<
57
57
  <tokenRefRuleRootTrack(...)>
58
58
  <addToList(elem=label,...)>
59
59
  >>
@@ -129,22 +129,22 @@ root_0 = @adaptor.create_flat_list
129
129
 
130
130
  rewriteCodeLabels() ::= <<
131
131
  <referencedTokenLabels:
132
- {stream_<it> = <rewriteElementType; format="snakecase">_stream( "token <it>", <it; format="label"> )};
132
+ {it | stream_<it> = <rewriteElementType; format="snakecase">_stream( "token <it>", <it; format="label"> )};
133
133
  separator="\n">
134
134
  <referencedTokenListLabels:
135
- {stream_<it> = <rewriteElementType; format="snakecase">_stream( "token <it>", list_of_<it; format="label"> )};
135
+ {it | stream_<it> = <rewriteElementType; format="snakecase">_stream( "token <it>", list_of_<it; format="label"> )};
136
136
  separator="\n">
137
137
  <referencedWildcardLabels:
138
- {stream_<it> = subtree_stream( "wildcard <it>", <it; format="label"> )};
138
+ {it | stream_<it> = subtree_stream( "wildcard <it>", <it; format="label"> )};
139
139
  separator="\n">
140
140
  <referencedWildcardListLabels:
141
- {stream_<it> = subtree_stream( "wildcard <it>", list_of_<it; format="label"> )};
141
+ {it | stream_<it> = subtree_stream( "wildcard <it>", list_of_<it; format="label"> )};
142
142
  separator="\n">
143
143
  <referencedRuleLabels:
144
- {stream_<it> = <it; format="label"> ? subtree_stream( "rule <it>", <it; format="label">.tree ) : subtree_stream( "token <it>" )};
144
+ {it | stream_<it> = <it; format="label"> ? subtree_stream( "rule <it>", <it; format="label">.tree ) : subtree_stream( "token <it>" )};
145
145
  separator="\n">
146
146
  <referencedRuleListLabels:
147
- {stream_<it> = subtree_stream( "token <it>", list_of_<it; format="label"> )};
147
+ {it | stream_<it> = subtree_stream( "token <it>", list_of_<it; format="label"> )};
148
148
  separator="\n">
149
149
  >>
150
150
 
@@ -191,18 +191,18 @@ end
191
191
  <referencedElements:{el|stream_<el>.reset<\n>}>
192
192
  >>
193
193
 
194
- rewriteAltRest(a) ::= <<
194
+ rewriteAltRest(a) ::= <%
195
195
  <if(a.pred)>
196
- if <a.pred>
197
- # <a.description>
196
+ if <a.pred><\n>
197
+ # <a.description><\n>
198
198
  <a.alt>
199
199
  <else>
200
- e
201
- # <a.description>
202
- <a.alt>
203
- end
200
+ e<\n>
201
+ # <a.description><\n>
202
+ <a.alt><\n>
203
+ end<\n>
204
204
  <endif>
205
- >>
205
+ %>
206
206
 
207
207
  rewriteAltFirst(a) ::= <<
208
208
  <if(a.pred)>
@@ -231,7 +231,7 @@ rewriteElement(e) ::= <<
231
231
  <e.el>
232
232
  >>
233
233
 
234
- rewriteTokenRef(token,elementIndex,hetero,args) ::= <<
234
+ rewriteTokenRef(token,elementIndex,args,terminalOptions={}) ::= <<
235
235
  @adaptor.add_child( root_<treeLevel>, <createRewriteNodeFromElement(...)> )<\n>
236
236
  >>
237
237
 
@@ -249,15 +249,15 @@ root_<treeLevel> = @adaptor.become_root( stream_<label>.next_node, root_<treeLev
249
249
 
250
250
  rewriteTokenListLabelRefRoot ::= rewriteTokenLabelRefRoot
251
251
 
252
- rewriteTokenRefRoot(token,elementIndex,hetero,args) ::= <<
252
+ rewriteTokenRefRoot(token,elementIndex,args,terminalOptions={}) ::= <<
253
253
  root_<treeLevel> = @adaptor.become_root( <createRewriteNodeFromElement(...)>, root_<treeLevel> )<\n>
254
254
  >>
255
255
 
256
- rewriteImaginaryTokenRef(args,token,hetero,elementIndex) ::= <<
256
+ rewriteImaginaryTokenRef(args,token,elementIndex,terminalOptions={}) ::= <<
257
257
  @adaptor.add_child( root_<treeLevel>, <createImaginaryNode(tokenType=token, ...)> )<\n>
258
258
  >>
259
259
 
260
- rewriteImaginaryTokenRefRoot(args,token,hetero,elementIndex) ::= <<
260
+ rewriteImaginaryTokenRefRoot(args,token,elementIndex,terminalOptions={}) ::= <<
261
261
  root_<treeLevel> = @adaptor.become_root( <createImaginaryNode(tokenType=token, ...)>, root_<treeLevel> )<\n>
262
262
  >>
263
263
 
@@ -303,27 +303,30 @@ rewriteWildcardLabelRef(label) ::= <<
303
303
  @adaptor.add_child( root_<treeLevel>, stream_<label>.next_tree )<\n>
304
304
  >>
305
305
 
306
- createImaginaryNode(tokenType,hetero,args) ::= <<
307
- <if(hetero)>
308
- <hetero; format="constantPath">.new( create_token( <tokenType> )<if(args)>, <args; separator=", "><endif> )
306
+ createImaginaryNode(tokenType,args,terminalOptions={}) ::= <%
307
+ <if(terminalOptions.node)>
308
+ <terminalOptions.node; format="constantPath">.new( create_token( <tokenType> )<if(args)>, <args; separator=", "><endif> )
309
309
  <else>
310
310
  <if(!args)>@adaptor.create_from_type( <tokenType>, "<tokenType>" )
311
311
  <else>@adaptor.create( <tokenType>, <args; separator=", "> )
312
312
  <endif>
313
313
  <endif>
314
- >>
314
+ %>
315
315
 
316
- createRewriteNodeFromElement(token,hetero,args) ::= <<
317
- <if(hetero)>
318
- <hetero; format="constantPath">.new( stream_<token>.next<if(args)>, <args; separator=", "><endif> )
316
+ createRewriteNodeFromElement(token,args,terminalOptions={}) ::= <%
317
+ <if(terminalOptions.node)>
318
+ <terminalOptions.node; format="constantPath">.new( stream_<token>.next<if(args)>, <args; separator=", "><endif> )
319
319
  <else>
320
320
  <if(args)>
321
- <if(!rest(args))>@adaptor.create_from_token( <token>, <first(args)> )
322
- <else><if(!rest(rest(args)))>@adaptor.create_from_token( <token>, <first(args)>, <first(rest(args))> )
321
+ <if(!rest(args))>
322
+ @adaptor.create_from_token( <token>, <first(args)> )
323
+ <else>
324
+ <if(!rest(rest(args)))>
325
+ @adaptor.create_from_token( <token>, <first(args)>, <first(rest(args))> )
323
326
  <endif>
324
327
  <endif>
325
328
  <else>
326
329
  stream_<token>.next_node
327
330
  <endif>
328
331
  <endif>
329
- >>
332
+ %>
@@ -13,7 +13,7 @@ end
13
13
  return_value.tree = @adaptor.create_error_node( @input, return_value.start, @input.look(-1), re )<\n>
14
14
  >>
15
15
 
16
- tokenRef(token,label,elementIndex,hetero) ::= <<
16
+ tokenRef(token,label,elementIndex,terminalOptions={}) ::= <<
17
17
  <super.tokenRef(...)>
18
18
  <gatedAction({
19
19
  tree_for_<label> = <createNodeFromToken(...)>
@@ -21,9 +21,9 @@ tree_for_<label> = <createNodeFromToken(...)>
21
21
  })>
22
22
  >>
23
23
 
24
- tokenRefBang(token,label,elementIndex) ::= "<super.tokenRef(...)>"
24
+ tokenRefBang(token,label,elementIndex,terminalOptions={}) ::= "<super.tokenRef(...)>"
25
25
 
26
- tokenRefRuleRoot(token,label,elementIndex,hetero) ::= <<
26
+ tokenRefRuleRoot(token,label,elementIndex,terminalOptions={}) ::= <<
27
27
  <super.tokenRef(...)>
28
28
  <gatedAction({
29
29
  tree_for_<label> = <createNodeFromToken(...)>
@@ -31,39 +31,39 @@ root_0 = @adaptor.become_root( tree_for_<label>, root_0 )
31
31
  })>
32
32
  >>
33
33
 
34
- tokenRefBangAndListLabel(token,label,elementIndex,hetero) ::= <<
34
+ tokenRefBangAndListLabel(token,label,elementIndex,terminalOptions={}) ::= <<
35
35
  <tokenRefBang(...)>
36
36
  <addToList(elem={<label; format="label">},...)>
37
37
  >>
38
38
 
39
- tokenRefAndListLabel(token,label,elementIndex,hetero) ::= <<
39
+ tokenRefAndListLabel(token,label,elementIndex,terminalOptions={}) ::= <<
40
40
  <tokenRef(...)>
41
41
  <addToList(elem={<label; format="label">},...)>
42
42
  >>
43
43
 
44
- tokenRefRuleRootAndListLabel(token,label,hetero,elementIndex) ::= <<
44
+ tokenRefRuleRootAndListLabel(token,label,elementIndex,terminalOptions={}) ::= <<
45
45
  <tokenRefRuleRoot(...)>
46
46
  <addToList(elem={<label; format="label">},...)>
47
47
  >>
48
48
 
49
- matchSet(s,label,hetero,elementIndex,postmatchCode) ::= <<
50
- <super.matchSet(..., postmatchCode={<gatedAction({@adaptor.add_child( root_0, <createNodeFromToken(...)> )})>})>
49
+ matchSet(s,label,elementIndex,postmatchCode,terminalOptions={}) ::= <<
50
+ <super.matchSet(postmatchCode={<gatedAction({@adaptor.add_child( root_0, <createNodeFromToken(...)> )})>}, ...)>
51
51
  >>
52
52
 
53
- matchRuleBlockSet(s,label,hetero,elementIndex,postmatchCode,treeLevel="0") ::= <<
53
+ matchRuleBlockSet(s,label,elementIndex,postmatchCode,treeLevel="0",terminalOptions={}) ::= <<
54
54
  <matchSet(...)>
55
55
  >>
56
56
 
57
57
 
58
58
 
59
59
  matchSetBang(s,label,elementIndex,postmatchCode) ::= "<super.matchSet(...)>"
60
- matchSetRuleRoot(s,label,hetero,elementIndex,debug) ::= <<
60
+ matchSetRuleRoot(s,label,elementIndex,debug,terminalOptions={}) ::= <<
61
61
  <if(label)>
62
62
  <label; format="label"> = @input.look<\n>
63
63
  <endif>
64
- <super.matchSet(..., postmatchCode={<gatedAction({root_0 = @adaptor.become_root( <createNodeFromToken(...)>, root_0 )})>})>
64
+ <super.matchSet(postmatchCode={<gatedAction({root_0 = @adaptor.become_root( <createNodeFromToken(...)>, root_0 )})>}, ...)>
65
65
  >>
66
- matchSetRuleRootAndListLabel(s,label,hetero,elementIndex,debug) ::= <<
66
+ matchSetRuleRootAndListLabel(s,label,elementIndex,debug,terminalOptions={}) ::= <<
67
67
  <matchSetRuleRoot(...)>
68
68
  <addToList(elem={<label; format="label">},...)>
69
69
  >>
@@ -107,7 +107,7 @@ ruleRefRuleRootAndListLabel(rule,label,elementIndex,args,scope) ::= <<
107
107
  <addToList(elem={<label; format="label">.tree},...)>
108
108
  >>
109
109
 
110
- wildcard(label,elementIndex) ::= <<
110
+ wildcard(token,label,elementIndex,terminalOptions={}) ::= <<
111
111
  <super.wildcard(...)>
112
112
  <gatedAction({
113
113
  tree_for_<label> = @adaptor.create_with_payload( <label; format="label"> )
@@ -115,9 +115,9 @@ tree_for_<label> = @adaptor.create_with_payload( <label; format="label"> )
115
115
  })>
116
116
  >>
117
117
 
118
- wildcardBang(label,elementIndex) ::= "<super.wildcard(...)>"
118
+ wildcardBang(token,label,elementIndex,terminalOptions={}) ::= "<super.wildcard(...)>"
119
119
 
120
- wildcardRuleRoot(label,elementIndex) ::= <<
120
+ wildcardRuleRoot(token,label,elementIndex,terminalOptions={}) ::= <<
121
121
  <super.wildcard(...)>
122
122
  <gatedAction({
123
123
  tree_for_<label> = @adaptor.create_with_payload( <label; format="label"> )
@@ -125,13 +125,14 @@ root_0 = @adaptor.become_root( tree_for_<label>, root_0 )
125
125
  })>
126
126
  >>
127
127
 
128
- createNodeFromToken(label,hetero) ::= <<
129
- <if(hetero)>
130
- <hetero; format="constantPath">.new( <label; format="label"> )
128
+
129
+ createNodeFromToken(label,terminalOptions={}) ::= <%
130
+ <if(terminalOptions.node)>
131
+ <terminalOptions.node; format="constantPath">.new( <label; format="label"> )
131
132
  <else>
132
133
  @adaptor.create_with_payload( <label; format="label"> )
133
134
  <endif>
134
- >>
135
+ %>
135
136
 
136
137
  ruleCleanUp() ::= <<
137
138
  <super.ruleCleanUp()>