antlr3 1.8.2 → 1.8.5
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/History.txt +18 -0
- data/lib/antlr3/error.rb +6 -0
- data/lib/antlr3/main.rb +2 -0
- data/lib/antlr3/profile.rb +10 -1
- data/lib/antlr3/recognizers.rb +4 -0
- data/lib/antlr3/streams/interactive.rb +77 -25
- data/lib/antlr3/streams/rewrite.rb +1 -1
- data/lib/antlr3/task.rb +4 -3
- data/lib/antlr3/token.rb +8 -7
- data/lib/antlr3/tree.rb +1 -0
- data/lib/antlr3/version.rb +1 -1
- data/samples/JavaScript.g +337 -396
- data/templates/Ruby.stg +1 -1
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
=== 1.8.5 / 10-21-10
|
2
|
+
|
3
|
+
* 1 Bug Fix
|
4
|
+
- fixed ANTLR3::InteractiveStringStream to work with Ruby 1.9. The lexer main script
|
5
|
+
should function in interactive mode for Ruby 1.9 now.
|
6
|
+
|
7
|
+
=== 1.8.4 / 10-08-10
|
8
|
+
|
9
|
+
* 1 Bug Fix
|
10
|
+
- removed directory dependency from tasks created by ANTLR3::Task, which caused
|
11
|
+
compilation to be performed twice in some situations
|
12
|
+
|
13
|
+
=== 1.8.3 / 10-08-10
|
14
|
+
|
15
|
+
* 2 Bug Fixes
|
16
|
+
- fixed typo in TokenRewriteStream#cast_range
|
17
|
+
- added work-around code to handle the lack of support for StopIteration in Rubinius
|
18
|
+
|
1
19
|
=== 1.8.2 / 10-02-10
|
2
20
|
|
3
21
|
* Bug Fix: removed references to Parser#token_stream
|
data/lib/antlr3/error.rb
CHANGED
@@ -36,6 +36,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
36
36
|
# - ported from the ANTLR3 Python Runtime library by
|
37
37
|
# Kyle Yetter (kcy5b@yahoo.com)
|
38
38
|
module ANTLR3
|
39
|
+
|
40
|
+
# for compatibility with rubinius, which does not implement StopIteration yet
|
41
|
+
unless defined?( StopIteration )
|
42
|
+
StopIteration = Class.new( StandardError )
|
43
|
+
end
|
44
|
+
|
39
45
|
module Error
|
40
46
|
|
41
47
|
=begin rdoc ANTLR3::Error::BacktrackingFailed
|
data/lib/antlr3/main.rb
CHANGED
@@ -382,6 +382,7 @@ class ParserMain < Main
|
|
382
382
|
@port = options.fetch( :port, ANTLR3::Debug::DEFAULT_PORT )
|
383
383
|
@log = options.fetch( :log, @error )
|
384
384
|
end
|
385
|
+
@profile = ( @parser_class.profile? rescue false )
|
385
386
|
end
|
386
387
|
|
387
388
|
def setup_options( opt )
|
@@ -456,6 +457,7 @@ class ParserMain < Main
|
|
456
457
|
# token_stream = CommonTokenStream.new( lexer )
|
457
458
|
parser = @parser_class.new( lexer, parser_options )
|
458
459
|
result = parser.send( @parser_rule ) and present( result )
|
460
|
+
@profile and puts( parser.generate_report )
|
459
461
|
end
|
460
462
|
|
461
463
|
def present( return_value )
|
data/lib/antlr3/profile.rb
CHANGED
@@ -44,6 +44,15 @@ switch.
|
|
44
44
|
module ParserEvents
|
45
45
|
include ANTLR3::Debug::ParserEvents
|
46
46
|
|
47
|
+
def self.included( klass )
|
48
|
+
super
|
49
|
+
if klass.is_a?( ::Class )
|
50
|
+
def klass.profile?
|
51
|
+
true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
47
56
|
def initialize( stream, options = {} )
|
48
57
|
options[ :debug_listener ] ||= Profiler.new( self )
|
49
58
|
super( stream, options )
|
@@ -319,7 +328,7 @@ class Profiler
|
|
319
328
|
@profile.hidden_characters_matched = hidden_tokens.inject( 0 ) do |count, token|
|
320
329
|
count + token.text.length rescue count
|
321
330
|
end
|
322
|
-
@profile.characters_matched = ( @last_token || input.tokens.last ).stop + 1
|
331
|
+
@profile.characters_matched = ( @last_token || input.tokens.last ).stop + 1 rescue 0
|
323
332
|
write_report
|
324
333
|
end
|
325
334
|
|
data/lib/antlr3/recognizers.rb
CHANGED
@@ -11,17 +11,82 @@ uses Readline (if available) or standard IO#gets to fetch data on demand.
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
class InteractiveStringStream < StringStream
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
|
15
|
+
if RUBY_VERSION =~ /^1\.9/
|
16
|
+
|
17
|
+
# creates a new StringStream object where +data+ is the string data to stream.
|
18
|
+
# accepts the following options in a symbol-to-value hash:
|
19
|
+
#
|
20
|
+
# [:file or :name] the (file) name to associate with the stream; default: <tt>'(string)'</tt>
|
21
|
+
# [:line] the initial line number; default: +1+
|
22
|
+
# [:column] the initial column number; default: +0+
|
23
|
+
#
|
24
|
+
def initialize( options = {}, &block ) # for 1.9
|
25
|
+
@string = ''
|
26
|
+
@data = []
|
27
|
+
@position = options.fetch :position, 0
|
28
|
+
@line = options.fetch :line, 1
|
29
|
+
@column = options.fetch :column, 0
|
30
|
+
@markers = []
|
31
|
+
mark
|
32
|
+
@initialized = @eof = false
|
33
|
+
@readline = block or raise( ArgumentError, "no line-reading block was provided" )
|
34
|
+
@name ||= options[ :file ] || options[ :name ] || '(interactive)'
|
35
|
+
end
|
36
|
+
|
37
|
+
def readline
|
38
|
+
@initialized = true
|
39
|
+
unless @eof
|
40
|
+
if line = @readline.call
|
41
|
+
line = line.to_s.encode( Encoding::UTF_8 )
|
42
|
+
@string << line
|
43
|
+
@data.concat( line.codepoints.to_a )
|
44
|
+
return true
|
45
|
+
else
|
46
|
+
@eof = true
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
else
|
53
|
+
|
54
|
+
# creates a new StringStream object where +data+ is the string data to stream.
|
55
|
+
# accepts the following options in a symbol-to-value hash:
|
56
|
+
#
|
57
|
+
# [:file or :name] the (file) name to associate with the stream; default: <tt>'(string)'</tt>
|
58
|
+
# [:line] the initial line number; default: +1+
|
59
|
+
# [:column] the initial column number; default: +0+
|
60
|
+
#
|
61
|
+
def initialize( options = {}, &block )
|
62
|
+
@string = @data = ''
|
63
|
+
@position = options.fetch :position, 0
|
64
|
+
@line = options.fetch :line, 1
|
65
|
+
@column = options.fetch :column, 0
|
66
|
+
@markers = []
|
67
|
+
mark
|
68
|
+
@initialized = @eof = false
|
69
|
+
@readline = block or raise( ArgumentError, "no line-reading block was provided" )
|
70
|
+
@name ||= options[ :file ] || options[ :name ] || '(interactive)'
|
71
|
+
end
|
72
|
+
|
73
|
+
def readline
|
74
|
+
@initialized = true
|
75
|
+
unless @eof
|
76
|
+
if line = @readline.call
|
77
|
+
@data << line.to_s
|
78
|
+
return true
|
79
|
+
else
|
80
|
+
@eof = true
|
81
|
+
return false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
23
86
|
end
|
24
87
|
|
88
|
+
private :readline
|
89
|
+
|
25
90
|
def consume
|
26
91
|
@position < @data.size and return( super )
|
27
92
|
unless @eof
|
@@ -50,28 +115,15 @@ class InteractiveStringStream < StringStream
|
|
50
115
|
|
51
116
|
def substring( start, stop )
|
52
117
|
fill_through( stop )
|
53
|
-
@
|
118
|
+
@string[ start .. stop ]
|
54
119
|
end
|
55
120
|
|
56
121
|
private
|
57
122
|
|
58
123
|
def fill_through( position )
|
59
124
|
@eof and return
|
60
|
-
if position < 0 then fill_out
|
61
|
-
else readline until ( @data.size > position or @eof )
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def readline
|
66
|
-
@initialized = true
|
67
|
-
unless @eof
|
68
|
-
if line = @readline.call
|
69
|
-
@data << line.to_s
|
70
|
-
return true
|
71
|
-
else
|
72
|
-
@eof = true
|
73
|
-
return false
|
74
|
-
end
|
125
|
+
if @position < 0 then fill_out
|
126
|
+
else readline until ( @data.size > @position or @eof )
|
75
127
|
end
|
76
128
|
end
|
77
129
|
|
@@ -323,7 +323,7 @@ and do not add any text to the rewrite buffer
|
|
323
323
|
|
324
324
|
if loc.is_a?( Range )
|
325
325
|
first, last = loc.first.to_i, loc.last.to_i
|
326
|
-
loc.
|
326
|
+
loc.exclude_end? and last -= 1
|
327
327
|
return cast_range( args.unshift( first, last ), extra )
|
328
328
|
else
|
329
329
|
loc = loc.to_i
|
data/lib/antlr3/task.rb
CHANGED
@@ -158,11 +158,10 @@ class GrammarSet
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def define_tasks
|
161
|
-
directory( @output_directory )
|
162
161
|
file( @antlr_jar )
|
163
162
|
|
164
163
|
for grammar in @grammars
|
165
|
-
deps = [ @
|
164
|
+
deps = [ @antlr_jar ]
|
166
165
|
if vocab = grammar.token_vocab and
|
167
166
|
tfile = find_tokens_file( vocab, grammar )
|
168
167
|
file( tfile )
|
@@ -200,6 +199,8 @@ class GrammarSet
|
|
200
199
|
end
|
201
200
|
|
202
201
|
def compile( grammar )
|
202
|
+
dir = output_directory
|
203
|
+
test( ?d, dir ) or FileUtils.mkpath( dir )
|
203
204
|
sh( build_command( grammar ) )
|
204
205
|
end
|
205
206
|
|
@@ -376,7 +377,7 @@ class GrammarFile
|
|
376
377
|
depends = shared_depends + depends
|
377
378
|
|
378
379
|
target_files.each do | target |
|
379
|
-
file( target => depends ) do
|
380
|
+
file( target => ( depends - [ target ] ) ) do # prevents recursive .tokens file dependencies
|
380
381
|
@group.compile( self )
|
381
382
|
end
|
382
383
|
end
|
data/lib/antlr3/token.rb
CHANGED
@@ -316,6 +316,14 @@ module TokenSource
|
|
316
316
|
return token
|
317
317
|
end
|
318
318
|
|
319
|
+
def each
|
320
|
+
block_given? or return enum_for( :each )
|
321
|
+
while token = next_token and token.type != EOF
|
322
|
+
yield( token )
|
323
|
+
end
|
324
|
+
return self
|
325
|
+
end
|
326
|
+
|
319
327
|
def to_stream( options = {} )
|
320
328
|
if block_given?
|
321
329
|
CommonTokenStream.new( self, options ) { | t, stream | yield( t, stream ) }
|
@@ -323,13 +331,6 @@ module TokenSource
|
|
323
331
|
CommonTokenStream.new( self, options )
|
324
332
|
end
|
325
333
|
end
|
326
|
-
|
327
|
-
def each
|
328
|
-
block_given? or return enum_for( :each )
|
329
|
-
loop { yield( self.next ) }
|
330
|
-
rescue StopIteration
|
331
|
-
return self
|
332
|
-
end
|
333
334
|
end
|
334
335
|
|
335
336
|
|
data/lib/antlr3/tree.rb
CHANGED
data/lib/antlr3/version.rb
CHANGED
data/samples/JavaScript.g
CHANGED
@@ -1,108 +1,64 @@
|
|
1
|
-
/**
|
2
|
-
[The "BSD licence"]
|
3
|
-
Copyright (c) 2010 Kyle Yetter
|
4
|
-
All rights reserved.
|
5
|
-
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
7
|
-
modification, are permitted provided that the following conditions
|
8
|
-
are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright
|
11
|
-
notice, this list of conditions and the following disclaimer.
|
12
|
-
2. Redistributions in binary form must reproduce the above copyright
|
13
|
-
notice, this list of conditions and the following disclaimer in the
|
14
|
-
documentation and/or other materials provided with the distribution.
|
15
|
-
3. The name of the author may not be used to endorse or promote products
|
16
|
-
derived from this software without specific prior written permission.
|
17
|
-
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
19
|
-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
20
|
-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
21
|
-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
22
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
23
|
-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
27
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
-
|
29
|
-
**/
|
30
|
-
|
31
1
|
grammar JavaScript;
|
32
2
|
|
33
|
-
options
|
34
|
-
{
|
3
|
+
options {
|
35
4
|
language = Ruby;
|
36
|
-
|
5
|
+
output = AST;
|
37
6
|
}
|
38
7
|
|
39
8
|
tokens {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
FINAL='final'; OR='||'; VOID='void';
|
79
|
-
FINALLY='finally'; PACKAGE='package'; VOLATILE='volatile';
|
80
|
-
FLOAT='float'; PARAMS; WHILE='while';
|
81
|
-
FOR='for'; PIPE='|'; WITH='with';
|
82
|
-
FOR_IN; PIPE_ASGN='|='; YIELD='yield';
|
83
|
-
FUNCTION='function'; PLUS='+';
|
84
|
-
GEQ='>='; PLUS_ASGN='+=';
|
9
|
+
AMP='&'; HAT='^'; PROGRAM;
|
10
|
+
AMP_ASGN='&='; HAT_ASGN='^='; QMARK='?';
|
11
|
+
AND='&&'; IF='if'; RBRACE='}';
|
12
|
+
AREF; IN='in'; RBRACK=']';
|
13
|
+
ARGUMENTS; INCR='++'; REGEX;
|
14
|
+
ARRAY; INSTANCEOF='instanceof'; RETURN='return';
|
15
|
+
ARROW='->'; ITER; RPAREN=')';
|
16
|
+
ASGN='='; LABEL; RSHIFT='>>';
|
17
|
+
BLOCK; LBRACE='{'; RSHIFT3='>>>';
|
18
|
+
BL_END='end'; LBRACK='['; RSHIFT3_ASGN='>>>=';
|
19
|
+
BREAK='break'; LEQ='<='; RSHIFT_ASGN='>>=';
|
20
|
+
CALL; LESS='<'; SEMI=';';
|
21
|
+
CASE='case'; LET='let'; SET='set';
|
22
|
+
CATCH='catch'; LINE_COMMENT; SLASH;
|
23
|
+
COLON=':'; LITERAL; SLASH_ASGN;
|
24
|
+
COMMA=','; LPAREN='('; SPLAT;
|
25
|
+
COMMENT; LSHIFT='<<'; STAR='*';
|
26
|
+
CONTINUE='continue'; LSHIFT_ASGN='<<='; STAR_ASGN='*=';
|
27
|
+
DECR='--'; MINUS='-'; SWITCH='switch';
|
28
|
+
DEFAULT='default'; MINUS_ASGN='-='; THIS='this';
|
29
|
+
DELETE='delete'; MOD='%'; THROW='throw';
|
30
|
+
DO='do'; MOD_ASGN='%='; TILDE='~';
|
31
|
+
DOT='.'; NEQ='!='; TRUE='true';
|
32
|
+
DO_UNTIL; NEQQ='!=='; TRY='try';
|
33
|
+
DO_WHILE; NEW='new'; TYPEOF='typeof';
|
34
|
+
EACH='each'; NOT='!'; UMINUS;
|
35
|
+
ELSE='else'; NULL='null'; UNDEFINED='undefined';
|
36
|
+
EQ='=='; OBJECT; UNLESS='unless';
|
37
|
+
EQQ='==='; OR='||'; UNTIL='until';
|
38
|
+
FALSE='false'; OR_ASGN='||='; UPLUS;
|
39
|
+
FINALLY='finally'; PARAMS; VAR='var';
|
40
|
+
FOR='for'; PIPE='|'; VOID='void';
|
41
|
+
FOR_IN; PIPE_ASGN='|='; WHILE='while';
|
42
|
+
FUNCTION='function'; PLUS='+'; WITH='with';
|
43
|
+
GEQ='>='; PLUS_ASGN='+='; WORDS;
|
44
|
+
GET='get'; POST_DECR; YAML;
|
45
|
+
GREATER='>'; POST_INCR; YIELD='yield';
|
46
|
+
CONST='const';
|
85
47
|
}
|
86
48
|
|
87
|
-
scope InFor {
|
88
|
-
active;
|
89
|
-
}
|
49
|
+
scope InFor { active; }
|
90
50
|
|
91
51
|
@parser::members {
|
92
52
|
|
93
53
|
def auto_semicolon?( error )
|
94
|
-
if
|
95
|
-
(
|
96
|
-
token = input[ i ] or break
|
97
|
-
token.hidden? or break
|
98
|
-
token.type == NEWLINE and return true
|
99
|
-
end
|
54
|
+
if NoViableAlternative === error
|
55
|
+
return( @auto_semicolon = error ) unless same_line?
|
100
56
|
end
|
101
57
|
return false
|
102
58
|
end
|
103
59
|
|
104
60
|
def recover( error = $! )
|
105
|
-
auto_semicolon
|
61
|
+
@auto_semicolon == error and return( @auto_semicolon = nil )
|
106
62
|
super
|
107
63
|
end
|
108
64
|
|
@@ -111,35 +67,72 @@ scope InFor {
|
|
111
67
|
super
|
112
68
|
end
|
113
69
|
|
70
|
+
def newline?( from = 1 )
|
71
|
+
to = from == -1 ? 1 : from + 1
|
72
|
+
start = @input.future?( from )
|
73
|
+
stop = @input.future?( to )
|
74
|
+
|
75
|
+
start.upto( stop ) do | i |
|
76
|
+
@input.at( i ).type == NEWLINE and return( true )
|
77
|
+
end
|
78
|
+
|
79
|
+
return( false )
|
80
|
+
end
|
81
|
+
|
82
|
+
def same_line?
|
83
|
+
stop = @input.future? || @input.length
|
84
|
+
start = @input.past? || 0
|
85
|
+
|
86
|
+
start.upto( stop ) do | i |
|
87
|
+
@input.at( i ).type == NEWLINE and return( false )
|
88
|
+
end
|
89
|
+
|
90
|
+
return( true )
|
91
|
+
end
|
92
|
+
|
93
|
+
def prepend_tree( root, child )
|
94
|
+
child = @adaptor.rule_post_processing( child )
|
95
|
+
root.unshift( child )
|
96
|
+
root.start_index > child.start_index and root.start_index = child.start_index
|
97
|
+
root.stop_index < child.stop_index and root.stop_index = child.stop_index
|
98
|
+
return @adaptor.rule_post_processing( root )
|
99
|
+
end
|
114
100
|
}
|
115
101
|
|
116
102
|
@lexer::members {
|
117
|
-
attr_accessor :
|
103
|
+
attr_accessor :value_expected
|
118
104
|
|
119
|
-
|
105
|
+
NO_VALUE_FOLLOWS = Set[
|
120
106
|
ID, REGEX, STRING, NUMBER, THIS,
|
121
|
-
TRUE, FALSE, NULL,
|
122
|
-
RPAREN, RBRACK, RBRACE,
|
107
|
+
TRUE, FALSE, NULL, UNDEFINED,
|
108
|
+
RPAREN, RBRACK, RBRACE,
|
109
|
+
IVAR, DOC, YAML, WORDS
|
123
110
|
]
|
124
111
|
|
125
112
|
def next_token
|
126
113
|
token = super
|
127
114
|
unless token.hidden?
|
128
|
-
@
|
129
|
-
|
130
|
-
@last_type = token.type
|
115
|
+
@value_expected =
|
116
|
+
NO_VALUE_FOLLOWS.include?( token.type ) ? false : true
|
131
117
|
end
|
132
118
|
return( token )
|
133
119
|
end
|
134
120
|
}
|
135
121
|
|
136
122
|
@lexer::init {
|
137
|
-
@
|
138
|
-
@
|
123
|
+
@value_expected = true
|
124
|
+
@token_buffer = []
|
125
|
+
@buffer_depth = 0
|
139
126
|
}
|
140
127
|
|
128
|
+
|
129
|
+
/********************************************************************************
|
130
|
+
**************************** Top-Level Structure *****************************
|
131
|
+
********************************************************************************/
|
132
|
+
|
141
133
|
program
|
142
|
-
:
|
134
|
+
: source_elements -> source_elements
|
135
|
+
| -> ^( UNDEFINED )
|
143
136
|
;
|
144
137
|
|
145
138
|
source_elements
|
@@ -152,24 +145,36 @@ block
|
|
152
145
|
;
|
153
146
|
|
154
147
|
statement_block
|
155
|
-
: '{'
|
148
|
+
: '{' statement_list? '}' -> ^( BLOCK statement_list? )
|
156
149
|
;
|
157
150
|
|
158
151
|
statement_list
|
159
|
-
: statement
|
152
|
+
: statement+ -> statement+
|
153
|
+
;
|
154
|
+
|
155
|
+
clause
|
156
|
+
: '(' expression_list ')' -> expression_list
|
160
157
|
;
|
161
158
|
|
159
|
+
/********************************************************************************
|
160
|
+
******************************** Statements **********************************
|
161
|
+
********************************************************************************/
|
162
|
+
|
162
163
|
statement
|
163
164
|
: variable_statement
|
165
|
+
| const_statement
|
164
166
|
| empty_statement
|
167
|
+
| ( 'function' )=> function
|
165
168
|
| ( ID ':' )=> labelled_statement
|
166
169
|
| ( 'let' )=> let_statement
|
167
|
-
|
170
|
+
| expression_statement
|
168
171
|
| if_statement
|
169
|
-
|
|
172
|
+
| while_statement
|
173
|
+
| do_while_statement
|
174
|
+
| for_loop
|
170
175
|
| continue_statement
|
171
176
|
| break_statement
|
172
|
-
|
177
|
+
| yield_statement
|
173
178
|
| return_statement
|
174
179
|
| with_statement
|
175
180
|
| switch_statement
|
@@ -177,92 +182,163 @@ statement
|
|
177
182
|
| try_statement
|
178
183
|
;
|
179
184
|
|
185
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
186
|
+
// Simple Statements
|
187
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
188
|
+
|
189
|
+
empty_statement
|
190
|
+
: ';' ->
|
191
|
+
;
|
192
|
+
|
193
|
+
expression_statement
|
194
|
+
: expression_list statement_end!
|
195
|
+
;
|
196
|
+
|
197
|
+
labelled_statement
|
198
|
+
: ID ':' block -> ^( LABEL ID block )
|
199
|
+
;
|
200
|
+
|
201
|
+
statement_end
|
202
|
+
: ';'
|
203
|
+
| ( '}' )=>
|
204
|
+
| EOF
|
205
|
+
;
|
206
|
+
|
207
|
+
blank
|
208
|
+
: -> ^( UNDEFINED )
|
209
|
+
;
|
210
|
+
|
211
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
212
|
+
// Block-ish Statements
|
213
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
214
|
+
|
215
|
+
try_statement
|
216
|
+
: 'try'
|
217
|
+
( statement_block -> statement_block )
|
218
|
+
( f=finally_clause -> { prepend_tree( $f.tree, $tree ) }
|
219
|
+
| ( catch_clause -> { prepend_tree( $catch_clause.tree, $tree ) } )
|
220
|
+
( f2=finally_clause -> { prepend_tree( $f2.tree, $tree ) } )?
|
221
|
+
)
|
222
|
+
;
|
223
|
+
|
224
|
+
catch_clause
|
225
|
+
: 'catch' '(' ID ')' statement_block
|
226
|
+
-> ^( 'catch' ID statement_block )
|
227
|
+
;
|
228
|
+
|
229
|
+
finally_clause
|
230
|
+
: 'finally' statement_block
|
231
|
+
-> ^( 'finally' statement_block )
|
232
|
+
;
|
233
|
+
|
234
|
+
with_statement
|
235
|
+
: 'with' clause block -> ^( 'with' clause block )
|
236
|
+
;
|
237
|
+
|
238
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
239
|
+
// Variable Declarations
|
240
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
241
|
+
|
180
242
|
variable_statement
|
181
|
-
: 'var'
|
243
|
+
: 'var'^ variable_declaration_list statement_end!
|
182
244
|
;
|
183
|
-
|
245
|
+
|
246
|
+
const_statement
|
247
|
+
: 'const'^ variable_declaration_list statement_end!
|
248
|
+
;
|
249
|
+
|
250
|
+
let_statement
|
251
|
+
: 'let'^ '('! variable_declaration_list ')'! block
|
252
|
+
;
|
253
|
+
|
184
254
|
variable_declaration_list
|
185
|
-
: variable_declaration (
|
186
|
-
-> variable_declaration+
|
255
|
+
: variable_declaration ( ','! variable_declaration )*
|
187
256
|
;
|
188
|
-
|
257
|
+
|
189
258
|
variable_declaration
|
190
259
|
: declaration_target ( '='^ expression )?
|
191
260
|
;
|
192
261
|
|
193
262
|
declaration_target
|
194
263
|
: '[' declaration_target ( ',' declaration_target )* ']' -> ^( ARRAY declaration_target+ )
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
264
|
+
| '{' declaration_key ( ',' declaration_key )* '}' -> ^( OBJECT declaration_key+ )
|
265
|
+
| variable_name -> variable_name
|
266
|
+
;
|
267
|
+
|
199
268
|
declaration_key
|
200
269
|
: property_name ':'^ declaration_target
|
201
|
-
;
|
202
|
-
|
203
|
-
empty_statement
|
204
|
-
: ';' ->
|
205
270
|
;
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
271
|
+
|
272
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
273
|
+
// Branching Statements
|
274
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
275
|
+
|
210
276
|
if_statement
|
211
|
-
: 'if'
|
212
|
-
when_true=block
|
213
|
-
( 'else' when_false=block )?
|
214
|
-
-> ^( 'if' expression_list $when_true $when_false? )
|
277
|
+
: 'if'^ clause block ( 'else'! block )?
|
215
278
|
;
|
216
279
|
|
217
|
-
|
218
|
-
: '
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
| while_statement
|
225
|
-
| ( 'for' 'each' '(' )=> for_each_in_statement
|
226
|
-
| ( 'for' '(' for_in_statement_initialiser_part 'in' )=> for_in_statement
|
227
|
-
| for_statement
|
280
|
+
switch_statement
|
281
|
+
: 'switch' '(' expression_list ')'
|
282
|
+
'{'
|
283
|
+
( case_clause )*
|
284
|
+
( default_clause ( case_clause )* )?
|
285
|
+
'}'
|
286
|
+
-> ^( 'switch' expression_list case_clause* default_clause? )
|
228
287
|
;
|
229
288
|
|
230
|
-
|
231
|
-
: '
|
289
|
+
case_clause
|
290
|
+
: 'case'^ expression_list ':'! statement_list?
|
232
291
|
;
|
233
292
|
|
293
|
+
default_clause
|
294
|
+
: 'default'^ ':'! statement_list?
|
295
|
+
;
|
296
|
+
|
297
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
298
|
+
// While Loops
|
299
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
300
|
+
|
301
|
+
do_while_statement
|
302
|
+
: 'do' block 'while' clause statement_end
|
303
|
+
-> ^( 'do' clause block )
|
304
|
+
;
|
305
|
+
|
234
306
|
while_statement
|
235
|
-
: 'while'
|
236
|
-
-> ^( 'while' expression_list block )
|
307
|
+
: 'while'^ clause block
|
237
308
|
;
|
238
|
-
|
309
|
+
|
310
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
311
|
+
// For Loops
|
312
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
313
|
+
|
314
|
+
for_loop
|
315
|
+
: { @input.peek( 2 ) == EACH }?=> for_each_in_statement
|
316
|
+
| ( 'for' '(' ~( ')' | ';' | 'in' )* 'in' )=> for_in_statement
|
317
|
+
| for_statement
|
318
|
+
;
|
319
|
+
|
239
320
|
for_statement
|
240
|
-
: 'for'
|
241
|
-
'('
|
242
|
-
(
|
243
|
-
(
|
244
|
-
(
|
245
|
-
')'
|
321
|
+
: 'for'^
|
322
|
+
'('!
|
323
|
+
( for_statement_initialiser_part | blank ) ';'!
|
324
|
+
( expression_list | blank ) ';'!
|
325
|
+
( expression_list | blank )
|
326
|
+
')'!
|
246
327
|
block
|
247
|
-
-> ^( 'for' for_statement_initialiser_part? $cond? $step? block )
|
248
328
|
;
|
249
329
|
|
250
330
|
for_statement_initialiser_part
|
251
331
|
scope InFor;
|
252
|
-
@before {
|
253
|
-
|
254
|
-
}
|
255
|
-
@after {
|
256
|
-
$InFor::active = false
|
257
|
-
}
|
332
|
+
@before { $InFor::active = true }
|
333
|
+
@after { $InFor::active = false }
|
258
334
|
: expression_list
|
259
335
|
| 'var'^ variable_declaration_list
|
260
336
|
;
|
261
337
|
|
262
338
|
for_each_in_statement
|
263
339
|
: 'for' 'each' '(' for_in_statement_initialiser_part 'in' expression ')' block
|
264
|
-
|
265
|
-
|
340
|
+
-> ^( 'each' for_in_statement_initialiser_part expression block )
|
341
|
+
;
|
266
342
|
|
267
343
|
for_in_statement
|
268
344
|
: f='for' '(' for_in_statement_initialiser_part 'in' expression ')' block
|
@@ -271,80 +347,34 @@ for_in_statement
|
|
271
347
|
|
272
348
|
for_in_statement_initialiser_part
|
273
349
|
scope InFor;
|
274
|
-
@before {
|
275
|
-
|
276
|
-
}
|
277
|
-
@after {
|
278
|
-
$InFor::active = false
|
279
|
-
}
|
350
|
+
@before { $InFor::active = true }
|
351
|
+
@after { $InFor::active = false }
|
280
352
|
: 'var'^ variable_declaration
|
281
353
|
| member
|
282
354
|
;
|
283
355
|
|
356
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
357
|
+
// Flow Control
|
358
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
359
|
+
|
284
360
|
continue_statement
|
285
|
-
: 'continue'^ ID? statement_end!
|
361
|
+
: 'continue'^ ( { same_line? }?=> ID )? statement_end!
|
286
362
|
;
|
287
363
|
|
288
364
|
break_statement
|
289
|
-
: 'break'^ ID? statement_end!
|
365
|
+
: 'break'^ ( { same_line? }?=> ID )? statement_end!
|
290
366
|
;
|
291
367
|
|
292
368
|
return_statement
|
293
|
-
: 'return'^ expression_list? statement_end!
|
369
|
+
: 'return'^ ( { same_line? }?=> expression_list )? statement_end!
|
294
370
|
;
|
295
371
|
|
296
372
|
yield_statement
|
297
|
-
: 'yield'^ expression_list? statement_end!
|
298
|
-
;
|
299
|
-
|
300
|
-
|
301
|
-
with_statement
|
302
|
-
: 'with' '(' expression_list ')' block
|
303
|
-
-> ^( 'with' expression_list block )
|
304
|
-
;
|
305
|
-
|
306
|
-
labelled_statement
|
307
|
-
: ID ':' block
|
308
|
-
-> ^( LABEL ID block )
|
309
|
-
;
|
310
|
-
|
311
|
-
switch_statement
|
312
|
-
: 'switch' '(' expression_list ')'
|
313
|
-
'{'
|
314
|
-
( case_clause )*
|
315
|
-
( default_clause ( case_clause )* )?
|
316
|
-
'}'
|
317
|
-
-> ^( 'switch' expression_list case_clause* default_clause? )
|
318
|
-
;
|
319
|
-
|
320
|
-
case_clause
|
321
|
-
: 'case'^ expression_list ':'! statement_list?
|
322
|
-
;
|
323
|
-
|
324
|
-
default_clause
|
325
|
-
: 'default'^ ':'! statement_list?
|
373
|
+
: 'yield'^ ( { same_line? }?=> expression_list )? statement_end!
|
326
374
|
;
|
327
375
|
|
328
376
|
throw_statement
|
329
|
-
: 'throw'^ expression_list statement_end!
|
330
|
-
;
|
331
|
-
|
332
|
-
try_statement
|
333
|
-
: 'try' ( statement_block -> statement_block )
|
334
|
-
( f=finally_clause -> { $f.tree.unshift( $tree ) }
|
335
|
-
| ( catch_clause -> { $catch_clause.tree.unshift( $tree ) } )
|
336
|
-
( f2=finally_clause -> { $f2.tree.unshift( $tree ) } )?
|
337
|
-
)
|
338
|
-
;
|
339
|
-
|
340
|
-
catch_clause
|
341
|
-
: 'catch' '(' ID ')' statement_block
|
342
|
-
-> ^( 'catch' ID statement_block )
|
343
|
-
;
|
344
|
-
|
345
|
-
finally_clause
|
346
|
-
: 'finally' statement_block
|
347
|
-
-> ^( 'finally' statement_block )
|
377
|
+
: 'throw'^ ( { same_line? }?=> expression_list )? statement_end!
|
348
378
|
;
|
349
379
|
|
350
380
|
/********************************************************************************
|
@@ -356,10 +386,10 @@ expression_list
|
|
356
386
|
;
|
357
387
|
|
358
388
|
expression
|
359
|
-
: ( member
|
389
|
+
: ( member assignment_op )=> member assignment_op^ expression
|
360
390
|
| conditional
|
361
391
|
;
|
362
|
-
|
392
|
+
|
363
393
|
assignment_op
|
364
394
|
: '='
|
365
395
|
| '*='
|
@@ -384,11 +414,11 @@ logical_or
|
|
384
414
|
;
|
385
415
|
|
386
416
|
logical_and
|
387
|
-
: bit_or
|
417
|
+
: bit_or ( '&&'^ bit_or )*
|
388
418
|
;
|
389
419
|
|
390
420
|
bit_or
|
391
|
-
: bit_xor (
|
421
|
+
: bit_xor ( '|'^ bit_xor )*
|
392
422
|
;
|
393
423
|
|
394
424
|
bit_xor
|
@@ -433,30 +463,36 @@ mult
|
|
433
463
|
;
|
434
464
|
|
435
465
|
unary
|
436
|
-
: 'delete'^
|
437
|
-
| 'void'^
|
438
|
-
| 'typeof'^
|
439
|
-
| '++'^
|
440
|
-
| '--'^
|
441
|
-
| '+'^
|
442
|
-
| '-'^
|
443
|
-
| '~'^
|
444
|
-
| '!'^
|
445
|
-
| postfix
|
466
|
+
: 'delete' unary -> ^( 'delete' unary )
|
467
|
+
| 'void' unary -> ^( 'void' unary )
|
468
|
+
| 'typeof' unary -> ^( 'typeof' unary )
|
469
|
+
| '++' unary -> ^( '++' unary )
|
470
|
+
| '--' unary -> ^( '--' unary )
|
471
|
+
| '+' unary -> ^( UPLUS[ '+' ] unary )
|
472
|
+
| '-' unary -> ^( UMINUS[ '-' ] unary )
|
473
|
+
| '~' unary -> ^( '~' unary )
|
474
|
+
| '!' unary -> ^( '!' unary )
|
475
|
+
| postfix -> postfix
|
446
476
|
;
|
447
477
|
|
448
478
|
postfix
|
449
479
|
: member
|
450
|
-
(
|
451
|
-
|
452
|
-
|
480
|
+
( { same_line? }?=>
|
481
|
+
( '++' -> ^( POST_INCR[ '++' ] member )
|
482
|
+
| '--' -> ^( POST_DECR[ '--' ] member )
|
483
|
+
)
|
484
|
+
| -> member
|
453
485
|
)
|
454
486
|
;
|
455
487
|
|
488
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
489
|
+
// Atomic Expressions
|
490
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
491
|
+
|
456
492
|
member
|
457
|
-
: ( receiver
|
458
|
-
( accessor
|
459
|
-
| arguments
|
493
|
+
: ( receiver -> receiver )
|
494
|
+
( accessor -> { prepend_tree( $accessor.tree, $tree ) }
|
495
|
+
| arguments -> ^( CALL $member arguments )
|
460
496
|
)*
|
461
497
|
;
|
462
498
|
|
@@ -466,30 +502,48 @@ accessor
|
|
466
502
|
;
|
467
503
|
|
468
504
|
receiver
|
469
|
-
: primary
|
470
|
-
| function
|
505
|
+
: primary -> primary
|
506
|
+
| function -> function
|
471
507
|
| ( 'new' new_target arguments? )=>
|
472
508
|
'new' new_target arguments? -> ^( 'new' new_target arguments? )
|
473
509
|
;
|
474
510
|
|
475
511
|
new_target
|
476
512
|
: ( receiver -> receiver )
|
477
|
-
( accessor -> { $accessor.tree
|
513
|
+
( accessor -> { prepend_tree( $accessor.tree, $tree ) } )*
|
478
514
|
;
|
479
515
|
|
480
516
|
arguments
|
481
|
-
: '(' ')' -> ^( ARGUMENTS )
|
482
|
-
|
483
|
-
|
517
|
+
: '(' ( expression ( ',' expression )* )? ')' -> ^( ARGUMENTS expression* )
|
518
|
+
;
|
519
|
+
|
520
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
521
|
+
// Functions / Blocks
|
522
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
523
|
+
|
524
|
+
function
|
525
|
+
: 'function'^ variable_name? function_parameters statement_block
|
526
|
+
;
|
527
|
+
|
528
|
+
function_parameters
|
529
|
+
: '(' parameters? ')' -> ^( PARAMS parameters? )
|
530
|
+
;
|
531
|
+
|
532
|
+
parameters
|
533
|
+
: variable_name ( ',' variable_name )* -> variable_name+
|
484
534
|
;
|
485
535
|
|
536
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
537
|
+
// Literals
|
538
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
539
|
+
|
486
540
|
primary
|
487
541
|
: 'this'^
|
488
|
-
| variable_name^
|
489
542
|
| 'null'^
|
490
543
|
| 'true'^
|
491
544
|
| 'false'^
|
492
545
|
| 'undefined'^
|
546
|
+
| variable_name^
|
493
547
|
| NUMBER^
|
494
548
|
| STRING^
|
495
549
|
| REGEX^
|
@@ -498,31 +552,16 @@ primary
|
|
498
552
|
| '('! expression_list ')'!
|
499
553
|
;
|
500
554
|
|
501
|
-
function
|
502
|
-
: 'function'^ ( ID )? formal_parameter_list block
|
503
|
-
;
|
504
|
-
|
505
|
-
formal_parameter_list
|
506
|
-
: '(' ( ID ( ',' ID )* )? ')'
|
507
|
-
-> ^( PARAMS ID* )
|
508
|
-
;
|
509
|
-
|
510
|
-
literal
|
511
|
-
: 'null'^ | 'true'^ | 'false'^ | NUMBER^ | STRING^ | REGEX^
|
512
|
-
;
|
513
|
-
|
514
|
-
|
515
555
|
array_literal
|
516
|
-
: '['
|
517
|
-
| '['
|
556
|
+
: '[' ']' -> ^( ARRAY )
|
557
|
+
| '[' list_item ( ',' list_item )* ']' -> ^( ARRAY list_item* )
|
518
558
|
;
|
519
559
|
|
520
|
-
|
521
|
-
: ( ',' )=>
|
560
|
+
list_item
|
561
|
+
: ( ',' )=> -> ^( UNDEFINED )
|
522
562
|
| expression -> expression
|
523
563
|
;
|
524
564
|
|
525
|
-
|
526
565
|
object_literal
|
527
566
|
: '{' '}' -> ^( OBJECT )
|
528
567
|
| '{' property_definition ( ',' property_definition )* '}'
|
@@ -530,173 +569,75 @@ object_literal
|
|
530
569
|
;
|
531
570
|
|
532
571
|
property_definition
|
533
|
-
: 'get'^ ID
|
534
|
-
|
535
|
-
|
572
|
+
: 'get'^ ID function_parameters block
|
573
|
+
| 'set'^ ID function_parameters block
|
574
|
+
| property_name ':'^ expression
|
536
575
|
;
|
537
576
|
|
577
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
578
|
+
// Names and Words
|
579
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
580
|
+
|
538
581
|
property_name
|
539
582
|
: ID
|
540
|
-
|
541
|
-
| STRING
|
583
|
+
| STRING
|
542
584
|
| NUMBER
|
543
|
-
|
544
|
-
|
545
|
-
statement_end
|
546
|
-
: ';'
|
547
|
-
| ( '}' )=>
|
548
|
-
| EOF
|
585
|
+
| reserved { $reserved.tree.token.type = ID }
|
549
586
|
;
|
550
587
|
|
551
588
|
variable_name
|
552
589
|
: ID
|
553
|
-
|
554
|
-
|
590
|
+
| t=pseudokeyword { $t.tree.token.type = ID }
|
591
|
+
;
|
555
592
|
|
556
593
|
pseudokeyword
|
557
|
-
: '
|
558
|
-
| '
|
559
|
-
| '
|
560
|
-
| 'byte'
|
561
|
-
| 'char'
|
562
|
-
| 'class'
|
563
|
-
| 'debugger'
|
564
|
-
| 'double'
|
565
|
-
| 'each'
|
566
|
-
| 'enum'
|
567
|
-
| 'export'
|
568
|
-
| 'extends'
|
569
|
-
| 'final'
|
570
|
-
| 'float'
|
571
|
-
| 'get'
|
572
|
-
| 'set'
|
573
|
-
| 'goto'
|
574
|
-
| 'implements'
|
575
|
-
| 'import'
|
576
|
-
| 'int'
|
577
|
-
| 'interface'
|
578
|
-
| 'is'
|
579
|
-
| 'long'
|
580
|
-
| 'namespace'
|
581
|
-
| 'native'
|
582
|
-
| 'package'
|
583
|
-
| 'private'
|
584
|
-
| 'protected'
|
585
|
-
| 'public'
|
586
|
-
| 'short'
|
587
|
-
| 'static'
|
588
|
-
| 'super'
|
589
|
-
| 'synchronized'
|
590
|
-
| 'throws'
|
591
|
-
| 'transient'
|
592
|
-
| 'use'
|
593
|
-
| 'volatile'
|
594
|
+
: 'each'
|
595
|
+
| 'get'
|
596
|
+
| 'set'
|
594
597
|
;
|
595
598
|
|
596
599
|
reserved
|
597
|
-
: '
|
598
|
-
| '
|
599
|
-
| '
|
600
|
-
| '
|
601
|
-
| '
|
602
|
-
| '
|
603
|
-
| 'catch'
|
604
|
-
| 'char'
|
605
|
-
| 'class'
|
606
|
-
| 'const'
|
607
|
-
| 'continue'
|
608
|
-
| 'debugger'
|
609
|
-
| 'default'
|
610
|
-
| 'delete'
|
611
|
-
| 'do'
|
612
|
-
| 'double'
|
613
|
-
| 'each'
|
614
|
-
| 'else'
|
615
|
-
| 'enum'
|
616
|
-
| 'export'
|
617
|
-
| 'extends'
|
618
|
-
| 'false'
|
619
|
-
| 'final'
|
620
|
-
| 'finally'
|
621
|
-
| 'float'
|
622
|
-
| 'for'
|
623
|
-
| 'function'
|
624
|
-
| 'get'
|
625
|
-
| 'goto'
|
626
|
-
| 'if'
|
627
|
-
| 'implements'
|
628
|
-
| 'import'
|
629
|
-
| 'in'
|
630
|
-
| 'instanceof'
|
631
|
-
| 'int'
|
632
|
-
| 'interface'
|
633
|
-
| 'is'
|
634
|
-
| 'let'
|
635
|
-
| 'long'
|
636
|
-
| 'namespace'
|
637
|
-
| 'native'
|
638
|
-
| 'new'
|
639
|
-
| 'null'
|
640
|
-
| 'package'
|
641
|
-
| 'private'
|
642
|
-
| 'protected'
|
643
|
-
| 'public'
|
644
|
-
| 'return'
|
645
|
-
| 'set'
|
646
|
-
| 'short'
|
647
|
-
| 'static'
|
648
|
-
| 'super'
|
649
|
-
| 'switch'
|
650
|
-
| 'synchronized'
|
651
|
-
| 'this'
|
652
|
-
| 'throw'
|
653
|
-
| 'throws'
|
654
|
-
| 'transient'
|
655
|
-
| 'true'
|
656
|
-
| 'try'
|
657
|
-
| 'typeof'
|
658
|
-
| 'undefined'
|
659
|
-
| 'use'
|
660
|
-
| 'var'
|
661
|
-
| 'void'
|
662
|
-
| 'volatile'
|
663
|
-
| 'while'
|
664
|
-
| 'with'
|
665
|
-
| 'yield'
|
600
|
+
: 'break' | 'do' | 'function' | 'new' | 'throw' | 'until'
|
601
|
+
| 'case' | 'each' | 'get' | 'null' | 'true' | 'var'
|
602
|
+
| 'catch' | 'else' | 'if' | 'return' | 'try' | 'void'
|
603
|
+
| 'continue' | 'false' | 'in' | 'set' | 'typeof' | 'while'
|
604
|
+
| 'default' | 'finally' | 'instanceof' | 'switch' | 'undefined' | 'with'
|
605
|
+
| 'delete' | 'for' | 'let' | 'this' | 'unless' | 'yield'
|
666
606
|
;
|
667
|
-
|
607
|
+
|
668
608
|
/********************************************************************************
|
669
609
|
*********************************** Lexer ************************************
|
670
610
|
********************************************************************************/
|
671
611
|
|
672
612
|
SLASH
|
673
|
-
: '//' ~( '\n' | '\r'
|
674
|
-
| '/*' .* '*/' {
|
675
|
-
| { @
|
676
|
-
| { !@
|
613
|
+
: '//' ~( '\n' | '\r' )* { $type = LINE_COMMENT; $channel = HIDDEN }
|
614
|
+
| '/*' .* '*/' { $type = COMMENT; $channel = HIDDEN }
|
615
|
+
| { @value_expected }?=> '/' ( ~( '/' | '*' | '\\' | '\r' | '\n' ) | '\\' . ) ( ~( '/' | '\\' | '\n' | '\r' ) | '\\' . )* '/' ( 'a'..'z' )* { $type = REGEX }
|
616
|
+
| { !@value_expected }?=> '/' ( '=' { $type = SLASH_ASGN } | { $type = SLASH } )
|
677
617
|
;
|
678
618
|
|
679
619
|
STRING
|
680
|
-
|
681
|
-
|
682
|
-
|
620
|
+
: '\'' ( ~( '\'' | '\\' ) | '\\' . )* '\''
|
621
|
+
| '"' ( ~( '"' | '\\' ) | '\\' . )* '"'
|
622
|
+
;
|
683
623
|
|
684
624
|
NUMBER
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
625
|
+
: ('0'..'9')+ '.' ('0'..'9')* ( ('e' | 'E') ('+' | '-')? ('0'..'9')+ )?
|
626
|
+
| '.'? ('0'..'9')+ ( ('e' | 'E') ('+' | '-')? ('0'..'9')+ )?
|
627
|
+
| '0' ('x' | 'X') ( '0'..'9' | 'a'..'f' | 'A'..'F' )+
|
628
|
+
;
|
689
629
|
|
690
630
|
NEWLINE
|
691
|
-
: ( '\n' | '\r' )+
|
692
|
-
|
693
|
-
;
|
631
|
+
: ( '\n' | '\r' )+ { $channel = HIDDEN }
|
632
|
+
;
|
694
633
|
|
695
634
|
ID
|
696
|
-
|
635
|
+
: ( '$' | '_' | 'a'..'z' | 'A'..'Z' )
|
697
636
|
( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '$' )*
|
698
|
-
|
637
|
+
;
|
699
638
|
|
700
639
|
WS // Tab, vertical tab, form feed, space, non-breaking space and any other unicode "space separator".
|
701
|
-
|
702
|
-
|
640
|
+
: ( '\t' | '\f' | ' ' | '\u00A0' )+ { $channel = HIDDEN }
|
641
|
+
;
|
642
|
+
|
643
|
+
|
data/templates/Ruby.stg
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antlr3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 1.8.
|
9
|
+
- 5
|
10
|
+
version: 1.8.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kyle Yetter
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-22 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|