Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

version 1.8.5: fixed bug in InteractiveStringStream and updated sampl…

…e JavaScript grammar

1.  Fixed ANTLR3::InteractiveStringStream to work with Ruby 1.9
    files:
      - modified: lib/antlr3/streams/interactive.rb
    notes:
      - the InteractiveStringStream class is used to implement
        the interactive mode of the lexer Main programs
      - after updating StringStream to work with Ruby 1.9, I never
        updated this class to reflect the change in structure
      - updated the class to mirror the structural changes in StringStream

2.  Updated sample JavaScript grammar to correct a few issues
    files:
      - modified: samples/JavaScript.g
  • Loading branch information...
commit 2cd528224a891a2034e65e272ba086707b7a029f 1 parent 9fc3bf4
Kyle Yetter authored
View
6 History.txt
@@ -1,3 +1,9 @@
+=== 1.8.5 / 10-21-10
+
+* 1 Bug Fix
+ - fixed ANTLR3::InteractiveStringStream to work with Ruby 1.9. The lexer main script
+ should function in interactive mode for Ruby 1.9 now.
+
=== 1.8.4 / 10-08-10
* 1 Bug Fix
View
2  config/antlr3.yaml
@@ -4,7 +4,7 @@
#
name: antlr3
-version: "1.8.4"
+version: "1.8.5"
antlr_version: "3.2.1"
summary: |-
View
102 lib/antlr3/streams/interactive.rb
@@ -11,17 +11,82 @@ module ANTLR3
=end
class InteractiveStringStream < StringStream
- def initialize( options = {}, &block )
- @data = ''
- @position = @column = @mark_depth = 0
- @line = 1
- @markers = []
- mark
- @initialized = @eof = false
- @readline = block or raise( ArgumentError, "no line-reading block was provided" )
- @name = options.fetch( :name, '(interactive)' )
+
+ if RUBY_VERSION =~ /^1\.9/
+
+ # creates a new StringStream object where +data+ is the string data to stream.
+ # accepts the following options in a symbol-to-value hash:
+ #
+ # [:file or :name] the (file) name to associate with the stream; default: <tt>'(string)'</tt>
+ # [:line] the initial line number; default: +1+
+ # [:column] the initial column number; default: +0+
+ #
+ def initialize( options = {}, &block ) # for 1.9
+ @string = ''
+ @data = []
+ @position = options.fetch :position, 0
+ @line = options.fetch :line, 1
+ @column = options.fetch :column, 0
+ @markers = []
+ mark
+ @initialized = @eof = false
+ @readline = block or raise( ArgumentError, "no line-reading block was provided" )
+ @name ||= options[ :file ] || options[ :name ] || '(interactive)'
+ end
+
+ def readline
+ @initialized = true
+ unless @eof
+ if line = @readline.call
+ line = line.to_s.encode( Encoding::UTF_8 )
+ @string << line
+ @data.concat( line.codepoints.to_a )
+ return true
+ else
+ @eof = true
+ return false
+ end
+ end
+ end
+
+ else
+
+ # creates a new StringStream object where +data+ is the string data to stream.
+ # accepts the following options in a symbol-to-value hash:
+ #
+ # [:file or :name] the (file) name to associate with the stream; default: <tt>'(string)'</tt>
+ # [:line] the initial line number; default: +1+
+ # [:column] the initial column number; default: +0+
+ #
+ def initialize( options = {}, &block )
+ @string = @data = ''
+ @position = options.fetch :position, 0
+ @line = options.fetch :line, 1
+ @column = options.fetch :column, 0
+ @markers = []
+ mark
+ @initialized = @eof = false
+ @readline = block or raise( ArgumentError, "no line-reading block was provided" )
+ @name ||= options[ :file ] || options[ :name ] || '(interactive)'
+ end
+
+ def readline
+ @initialized = true
+ unless @eof
+ if line = @readline.call
+ @data << line.to_s
+ return true
+ else
+ @eof = true
+ return false
+ end
+ end
+ end
+
end
+ private :readline
+
def consume
@position < @data.size and return( super )
unless @eof
@@ -50,28 +115,15 @@ def look( i = 1 )
def substring( start, stop )
fill_through( stop )
- @data[ start..stop ]
+ @string[ start .. stop ]
end
private
def fill_through( position )
@eof and return
- if position < 0 then fill_out
- else readline until ( @data.size > position or @eof )
- end
- end
-
- def readline
- @initialized = true
- unless @eof
- if line = @readline.call
- @data << line.to_s
- return true
- else
- @eof = true
- return false
- end
+ if @position < 0 then fill_out
+ else readline until ( @data.size > @position or @eof )
end
end
View
2  lib/antlr3/task.rb
@@ -377,7 +377,7 @@ def define_tasks( shared_depends )
depends = shared_depends + depends
target_files.each do | target |
- file( target => depends ) do
+ file( target => ( depends - [ target ] ) ) do # prevents recursive .tokens file dependencies
@group.compile( self )
end
end
View
2  lib/antlr3/version.rb
@@ -20,7 +20,7 @@ module ANTLR3
#
MAJOR_VERSION = 1
MINOR_VERSION = 8
- PATCH_VERSION = 4
+ PATCH_VERSION = 5
VERSION = [ MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION ]
VERSION_STRING = VERSION.join( '.' ).freeze
View
733 samples/JavaScript.g
@@ -1,108 +1,64 @@
-/**
-[The "BSD licence"]
-Copyright (c) 2010 Kyle Yetter
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-**/
-
grammar JavaScript;
-options
-{
+options {
language = Ruby;
- output = AST;
+ output = AST;
}
tokens {
- ABSTRACT='abstract'; GET='get'; POST_DECR;
- AMP='&'; GOTO='goto'; POST_INCR;
- AMP_ASGN='&='; GREATER='>'; PRIVATE='private';
- AND='&&'; HAT='^'; PROGRAM;
- AREF; HAT_ASGN='^='; PROTECTED='protected';
- ARGUMENTS; IF='if'; PUBLIC='public';
- ARRAY; IMPLEMENTS='implements'; QMARK='?';
- AS='as'; IMPORT='import'; RBRACE='}';
- ASGN='='; IN='in'; RBRACK=']';
- BLOCK; INCR='++'; REGEX;
- BOOLEAN='boolean'; INSTANCEOF='instanceof'; RETURN='return';
- BREAK='break'; INT='int'; RPAREN=')';
- BYTE='byte'; INTERFACE='interface'; RSHIFT3='>>>';
- CALL; IS='is'; RSHIFT3_ASGN='>>>=';
- CASE='case'; LABEL; RSHIFT='>>';
- CATCH='catch'; LBRACE='{'; RSHIFT_ASGN='>>=';
- CHAR='char'; LBRACK='['; SEMI=';'; //]
- CLASS='class'; LEQ='<='; SET='set';
- COLON=':'; LESS='<'; SHORT='short';
- COMMA=','; LET='let'; SLASH;
- COMMENT; LINE_COMMENT; SLASH_ASGN;
- CONST='const'; LITERAL; STAR='*';
- CONTINUE='continue'; LONG='long'; STAR_ASGN='*=';
- DEBUGGER='debugger'; LPAREN='('; STATIC='static';
- DECR='--'; LSHIFT='<<'; SUPER='super';
- DEFAULT='default'; LSHIFT_ASGN='<<='; SWITCH='switch';
- DELETE='delete'; MINUS='-'; SYNCHRONIZED='synchronized';
- DO='do'; MINUS_ASGN='-='; THIS='this';
- DOT='.'; MOD='%'; THROW='throw';
- DOUBLE='double'; MOD_ASGN='%='; THROWS='throws';
- EACH='each'; NAMESPACE='namespace'; TILDE='~';
- ELSE='else'; NATIVE='native'; TRANSIENT='transient';
- ENUM='enum'; NEQ='!='; TRUE='true';
- EQ='=='; NEQQ='!=='; TRY='try';
- EQQ='==='; NEW='new'; TYPEOF='typeof';
- EXPORT='export'; NOT='!'; UNDEFINED='undefined';
- EXTENDS='extends'; NULL='null'; USE='use';
- FALSE='false'; OBJECT; VAR='var';
- FINAL='final'; OR='||'; VOID='void';
- FINALLY='finally'; PACKAGE='package'; VOLATILE='volatile';
- FLOAT='float'; PARAMS; WHILE='while';
- FOR='for'; PIPE='|'; WITH='with';
- FOR_IN; PIPE_ASGN='|='; YIELD='yield';
- FUNCTION='function'; PLUS='+';
- GEQ='>='; PLUS_ASGN='+=';
+ AMP='&'; HAT='^'; PROGRAM;
+ AMP_ASGN='&='; HAT_ASGN='^='; QMARK='?';
+ AND='&&'; IF='if'; RBRACE='}';
+ AREF; IN='in'; RBRACK=']';
+ ARGUMENTS; INCR='++'; REGEX;
+ ARRAY; INSTANCEOF='instanceof'; RETURN='return';
+ ARROW='->'; ITER; RPAREN=')';
+ ASGN='='; LABEL; RSHIFT='>>';
+ BLOCK; LBRACE='{'; RSHIFT3='>>>';
+ BL_END='end'; LBRACK='['; RSHIFT3_ASGN='>>>=';
+ BREAK='break'; LEQ='<='; RSHIFT_ASGN='>>=';
+ CALL; LESS='<'; SEMI=';';
+ CASE='case'; LET='let'; SET='set';
+ CATCH='catch'; LINE_COMMENT; SLASH;
+ COLON=':'; LITERAL; SLASH_ASGN;
+ COMMA=','; LPAREN='('; SPLAT;
+ COMMENT; LSHIFT='<<'; STAR='*';
+ CONTINUE='continue'; LSHIFT_ASGN='<<='; STAR_ASGN='*=';
+ DECR='--'; MINUS='-'; SWITCH='switch';
+ DEFAULT='default'; MINUS_ASGN='-='; THIS='this';
+ DELETE='delete'; MOD='%'; THROW='throw';
+ DO='do'; MOD_ASGN='%='; TILDE='~';
+ DOT='.'; NEQ='!='; TRUE='true';
+ DO_UNTIL; NEQQ='!=='; TRY='try';
+ DO_WHILE; NEW='new'; TYPEOF='typeof';
+ EACH='each'; NOT='!'; UMINUS;
+ ELSE='else'; NULL='null'; UNDEFINED='undefined';
+ EQ='=='; OBJECT; UNLESS='unless';
+ EQQ='==='; OR='||'; UNTIL='until';
+ FALSE='false'; OR_ASGN='||='; UPLUS;
+ FINALLY='finally'; PARAMS; VAR='var';
+ FOR='for'; PIPE='|'; VOID='void';
+ FOR_IN; PIPE_ASGN='|='; WHILE='while';
+ FUNCTION='function'; PLUS='+'; WITH='with';
+ GEQ='>='; PLUS_ASGN='+='; WORDS;
+ GET='get'; POST_DECR; YAML;
+ GREATER='>'; POST_INCR; YIELD='yield';
+ CONST='const';
}
-scope InFor {
- active;
-}
+scope InFor { active; }
@parser::members {
def auto_semicolon?( error )
- if ANTLR3::Error::NoViableAlternative === error
- ( input.position - 1 ).downto( 0 ) do | i |
- token = input[ i ] or break
- token.hidden? or break
- token.type == NEWLINE and return true
- end
+ if NoViableAlternative === error
+ return( @auto_semicolon = error ) unless same_line?
end
return false
end
def recover( error = $! )
- auto_semicolon?( error ) and return
+ @auto_semicolon == error and return( @auto_semicolon = nil )
super
end
@@ -111,35 +67,72 @@ scope InFor {
super
end
+ def newline?( from = 1 )
+ to = from == -1 ? 1 : from + 1
+ start = @input.future?( from )
+ stop = @input.future?( to )
+
+ start.upto( stop ) do | i |
+ @input.at( i ).type == NEWLINE and return( true )
+ end
+
+ return( false )
+ end
+
+ def same_line?
+ stop = @input.future? || @input.length
+ start = @input.past? || 0
+
+ start.upto( stop ) do | i |
+ @input.at( i ).type == NEWLINE and return( false )
+ end
+
+ return( true )
+ end
+
+ def prepend_tree( root, child )
+ child = @adaptor.rule_post_processing( child )
+ root.unshift( child )
+ root.start_index > child.start_index and root.start_index = child.start_index
+ root.stop_index < child.stop_index and root.stop_index = child.stop_index
+ return @adaptor.rule_post_processing( root )
+ end
}
@lexer::members {
- attr_accessor :regex_possible
+ attr_accessor :value_expected
- NO_REGEX_FOLLOWS = Set[
+ NO_VALUE_FOLLOWS = Set[
ID, REGEX, STRING, NUMBER, THIS,
- TRUE, FALSE, NULL,
- RPAREN, RBRACK, RBRACE, UNDEFINED
+ TRUE, FALSE, NULL, UNDEFINED,
+ RPAREN, RBRACK, RBRACE,
+ IVAR, DOC, YAML, WORDS
]
def next_token
token = super
unless token.hidden?
- @regex_possible =
- NO_REGEX_FOLLOWS.include?( token.type ) ? false : true
- @last_type = token.type
+ @value_expected =
+ NO_VALUE_FOLLOWS.include?( token.type ) ? false : true
end
return( token )
end
}
@lexer::init {
- @regex_possible = true
- @last_type = nil
+ @value_expected = true
+ @token_buffer = []
+ @buffer_depth = 0
}
+
+/********************************************************************************
+ **************************** Top-Level Structure *****************************
+ ********************************************************************************/
+
program
- : source_elements
+ : source_elements -> source_elements
+ | -> ^( UNDEFINED )
;
source_elements
@@ -152,24 +145,36 @@ block
;
statement_block
- : '{' ( statement_list )? '}' -> ^( BLOCK statement_list? )
+ : '{' statement_list? '}' -> ^( BLOCK statement_list? )
;
statement_list
- : statement ( statement )* -> statement+
+ : statement+ -> statement+
+ ;
+
+clause
+ : '(' expression_list ')' -> expression_list
;
+/********************************************************************************
+ ******************************** Statements **********************************
+ ********************************************************************************/
+
statement
: variable_statement
+ | const_statement
| empty_statement
+ | ( 'function' )=> function
| ( ID ':' )=> labelled_statement
| ( 'let' )=> let_statement
- | expression_statement
+ | expression_statement
| if_statement
- | iteration_statement
+ | while_statement
+ | do_while_statement
+ | for_loop
| continue_statement
| break_statement
- | yield_statement
+ | yield_statement
| return_statement
| with_statement
| switch_statement
@@ -177,92 +182,163 @@ statement
| try_statement
;
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Simple Statements
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+empty_statement
+ : ';' ->
+ ;
+
+expression_statement
+ : expression_list statement_end!
+ ;
+
+labelled_statement
+ : ID ':' block -> ^( LABEL ID block )
+ ;
+
+statement_end
+ : ';'
+ | ( '}' )=>
+ | EOF
+ ;
+
+blank
+ : -> ^( UNDEFINED )
+ ;
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Block-ish Statements
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+try_statement
+ : 'try'
+ ( statement_block -> statement_block )
+ ( f=finally_clause -> { prepend_tree( $f.tree, $tree ) }
+ | ( catch_clause -> { prepend_tree( $catch_clause.tree, $tree ) } )
+ ( f2=finally_clause -> { prepend_tree( $f2.tree, $tree ) } )?
+ )
+ ;
+
+catch_clause
+ : 'catch' '(' ID ')' statement_block
+ -> ^( 'catch' ID statement_block )
+ ;
+
+finally_clause
+ : 'finally' statement_block
+ -> ^( 'finally' statement_block )
+ ;
+
+with_statement
+ : 'with' clause block -> ^( 'with' clause block )
+ ;
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Variable Declarations
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
variable_statement
- : 'var' variable_declaration_list statement_end -> ^( 'var' variable_declaration_list )
+ : 'var'^ variable_declaration_list statement_end!
;
-
+
+const_statement
+ : 'const'^ variable_declaration_list statement_end!
+ ;
+
+let_statement
+ : 'let'^ '('! variable_declaration_list ')'! block
+ ;
+
variable_declaration_list
- : variable_declaration ( ',' variable_declaration )*
- -> variable_declaration+
+ : variable_declaration ( ','! variable_declaration )*
;
-
+
variable_declaration
: declaration_target ( '='^ expression )?
;
declaration_target
: '[' declaration_target ( ',' declaration_target )* ']' -> ^( ARRAY declaration_target+ )
- | '{' declaration_key ( ',' declaration_key )* '}' -> ^( OBJECT declaration_key+ )
- | variable_name -> variable_name
- ;
-
+ | '{' declaration_key ( ',' declaration_key )* '}' -> ^( OBJECT declaration_key+ )
+ | variable_name -> variable_name
+ ;
+
declaration_key
: property_name ':'^ declaration_target
- ;
-
-empty_statement
- : ';' ->
;
-
-expression_statement
- : expression_list statement_end! ;
-
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Branching Statements
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
if_statement
- : 'if' '(' expression_list ')'
- when_true=block
- ( 'else' when_false=block )?
- -> ^( 'if' expression_list $when_true $when_false? )
+ : 'if'^ clause block ( 'else'! block )?
;
-let_statement
- : 'let' '(' variable_declaration_list ')' block
- -> ^( 'let' variable_declaration_list block )
- ;
-
-iteration_statement
- : do_while_statement
- | while_statement
- | ( 'for' 'each' '(' )=> for_each_in_statement
- | ( 'for' '(' for_in_statement_initialiser_part 'in' )=> for_in_statement
- | for_statement
+switch_statement
+ : 'switch' '(' expression_list ')'
+ '{'
+ ( case_clause )*
+ ( default_clause ( case_clause )* )?
+ '}'
+ -> ^( 'switch' expression_list case_clause* default_clause? )
;
-do_while_statement
- : 'do' block 'while' '(' expression_list ')' statement_end -> ^( 'do' expression_list block )
+case_clause
+ : 'case'^ expression_list ':'! statement_list?
;
+default_clause
+ : 'default'^ ':'! statement_list?
+ ;
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// While Loops
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+do_while_statement
+ : 'do' block 'while' clause statement_end
+ -> ^( 'do' clause block )
+ ;
+
while_statement
- : 'while' '(' expression_list ')' block
- -> ^( 'while' expression_list block )
+ : 'while'^ clause block
;
-
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// For Loops
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+for_loop
+ : { @input.peek( 2 ) == EACH }?=> for_each_in_statement
+ | ( 'for' '(' ~( ')' | ';' | 'in' )* 'in' )=> for_in_statement
+ | for_statement
+ ;
+
for_statement
- : 'for'
- '('
- ( for_statement_initialiser_part )? ';'
- ( cond=expression_list )? ';'
- ( step=expression_list )?
- ')'
+ : 'for'^
+ '('!
+ ( for_statement_initialiser_part | blank ) ';'!
+ ( expression_list | blank ) ';'!
+ ( expression_list | blank )
+ ')'!
block
- -> ^( 'for' for_statement_initialiser_part? $cond? $step? block )
;
for_statement_initialiser_part
scope InFor;
- @before {
- $InFor::active = true
- }
- @after {
- $InFor::active = false
- }
+ @before { $InFor::active = true }
+ @after { $InFor::active = false }
: expression_list
| 'var'^ variable_declaration_list
;
for_each_in_statement
: 'for' 'each' '(' for_in_statement_initialiser_part 'in' expression ')' block
- -> ^( 'each' for_in_statement_initialiser_part expression block )
- ;
+ -> ^( 'each' for_in_statement_initialiser_part expression block )
+ ;
for_in_statement
: f='for' '(' for_in_statement_initialiser_part 'in' expression ')' block
@@ -271,80 +347,34 @@ for_in_statement
for_in_statement_initialiser_part
scope InFor;
- @before {
- $InFor::active = true
- }
- @after {
- $InFor::active = false
- }
+ @before { $InFor::active = true }
+ @after { $InFor::active = false }
: 'var'^ variable_declaration
| member
;
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Flow Control
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
continue_statement
- : 'continue'^ ID? statement_end!
+ : 'continue'^ ( { same_line? }?=> ID )? statement_end!
;
break_statement
- : 'break'^ ID? statement_end!
+ : 'break'^ ( { same_line? }?=> ID )? statement_end!
;
return_statement
- : 'return'^ expression_list? statement_end!
+ : 'return'^ ( { same_line? }?=> expression_list )? statement_end!
;
yield_statement
- : 'yield'^ expression_list? statement_end!
- ;
-
-
-with_statement
- : 'with' '(' expression_list ')' block
- -> ^( 'with' expression_list block )
- ;
-
-labelled_statement
- : ID ':' block
- -> ^( LABEL ID block )
- ;
-
-switch_statement
- : 'switch' '(' expression_list ')'
- '{'
- ( case_clause )*
- ( default_clause ( case_clause )* )?
- '}'
- -> ^( 'switch' expression_list case_clause* default_clause? )
- ;
-
-case_clause
- : 'case'^ expression_list ':'! statement_list?
- ;
-
-default_clause
- : 'default'^ ':'! statement_list?
+ : 'yield'^ ( { same_line? }?=> expression_list )? statement_end!
;
throw_statement
- : 'throw'^ expression_list statement_end!
- ;
-
-try_statement
- : 'try' ( statement_block -> statement_block )
- ( f=finally_clause -> { $f.tree.unshift( $tree ) }
- | ( catch_clause -> { $catch_clause.tree.unshift( $tree ) } )
- ( f2=finally_clause -> { $f2.tree.unshift( $tree ) } )?
- )
- ;
-
-catch_clause
- : 'catch' '(' ID ')' statement_block
- -> ^( 'catch' ID statement_block )
- ;
-
-finally_clause
- : 'finally' statement_block
- -> ^( 'finally' statement_block )
+ : 'throw'^ ( { same_line? }?=> expression_list )? statement_end!
;
/********************************************************************************
@@ -356,10 +386,10 @@ expression_list
;
expression
- : ( member assignment_op )=> member assignment_op^ expression
+ : ( member assignment_op )=> member assignment_op^ expression
| conditional
;
-
+
assignment_op
: '='
| '*='
@@ -384,11 +414,11 @@ logical_or
;
logical_and
- : bit_or ( '&&'^ bit_or )*
+ : bit_or ( '&&'^ bit_or )*
;
bit_or
- : bit_xor ( '|'^ bit_xor )*
+ : bit_xor ( '|'^ bit_xor )*
;
bit_xor
@@ -433,30 +463,36 @@ mult
;
unary
- : 'delete'^ unary
- | 'void'^ unary
- | 'typeof'^ unary
- | '++'^ unary
- | '--'^ unary
- | '+'^ unary
- | '-'^ unary
- | '~'^ unary
- | '!'^ unary
- | postfix
+ : 'delete' unary -> ^( 'delete' unary )
+ | 'void' unary -> ^( 'void' unary )
+ | 'typeof' unary -> ^( 'typeof' unary )
+ | '++' unary -> ^( '++' unary )
+ | '--' unary -> ^( '--' unary )
+ | '+' unary -> ^( UPLUS[ '+' ] unary )
+ | '-' unary -> ^( UMINUS[ '-' ] unary )
+ | '~' unary -> ^( '~' unary )
+ | '!' unary -> ^( '!' unary )
+ | postfix -> postfix
;
postfix
: member
- ( '++' -> ^( POST_INCR[ '++' ] member )
- | '--' -> ^( POST_DECR[ '--' ] member )
- | -> member
+ ( { same_line? }?=>
+ ( '++' -> ^( POST_INCR[ '++' ] member )
+ | '--' -> ^( POST_DECR[ '--' ] member )
+ )
+ | -> member
)
;
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Atomic Expressions
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
member
- : ( receiver -> receiver )
- ( accessor -> { $accessor.tree.unshift( $tree ) }
- | arguments -> ^( CALL $member arguments )
+ : ( receiver -> receiver )
+ ( accessor -> { prepend_tree( $accessor.tree, $tree ) }
+ | arguments -> ^( CALL $member arguments )
)*
;
@@ -466,30 +502,48 @@ accessor
;
receiver
- : primary
- | function
+ : primary -> primary
+ | function -> function
| ( 'new' new_target arguments? )=>
'new' new_target arguments? -> ^( 'new' new_target arguments? )
;
new_target
: ( receiver -> receiver )
- ( accessor -> { $accessor.tree.unshift( $tree ) } )*
+ ( accessor -> { prepend_tree( $accessor.tree, $tree ) } )*
;
arguments
- : '(' ')' -> ^( ARGUMENTS )
- | '(' expression ( ',' expression )* ')'
- -> ^( ARGUMENTS expression+ )
+ : '(' ( expression ( ',' expression )* )? ')' -> ^( ARGUMENTS expression* )
+ ;
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Functions / Blocks
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+function
+ : 'function'^ variable_name? function_parameters statement_block
+ ;
+
+function_parameters
+ : '(' parameters? ')' -> ^( PARAMS parameters? )
+ ;
+
+parameters
+ : variable_name ( ',' variable_name )* -> variable_name+
;
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Literals
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
primary
: 'this'^
- | variable_name^
| 'null'^
| 'true'^
| 'false'^
| 'undefined'^
+ | variable_name^
| NUMBER^
| STRING^
| REGEX^
@@ -498,31 +552,16 @@ primary
| '('! expression_list ')'!
;
-function
- : 'function'^ ( ID )? formal_parameter_list block
- ;
-
-formal_parameter_list
- : '(' ( ID ( ',' ID )* )? ')'
- -> ^( PARAMS ID* )
- ;
-
-literal
- : 'null'^ | 'true'^ | 'false'^ | NUMBER^ | STRING^ | REGEX^
- ;
-
-
array_literal
- : '[' ']' -> ^( ARRAY )
- | '[' expression ( ',' expression? )* ']' -> ^( ARRAY expression+ )
+ : '[' ']' -> ^( ARRAY )
+ | '[' list_item ( ',' list_item )* ']' -> ^( ARRAY list_item* )
;
-list_element
- : ( ',' )=> -> ^( UNDEFINED )
+list_item
+ : ( ',' )=> -> ^( UNDEFINED )
| expression -> expression
;
-
object_literal
: '{' '}' -> ^( OBJECT )
| '{' property_definition ( ',' property_definition )* '}'
@@ -530,173 +569,75 @@ object_literal
;
property_definition
- : 'get'^ ID formal_parameter_list block
- | 'set'^ ID formal_parameter_list block
- | property_name ':'^ expression
+ : 'get'^ ID function_parameters block
+ | 'set'^ ID function_parameters block
+ | property_name ':'^ expression
;
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// Names and Words
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
property_name
: ID
- | reserved { $reserved.tree.token.type = ID }
- | STRING
+ | STRING
| NUMBER
- ;
-
-statement_end
- : ';'
- | ( '}' )=>
- | EOF
+ | reserved { $reserved.tree.token.type = ID }
;
variable_name
: ID
- | t=pseudokeyword { $t.tree.token.type = ID }
- ;
+ | t=pseudokeyword { $t.tree.token.type = ID }
+ ;
pseudokeyword
- : 'abstract'
- | 'as'
- | 'boolean'
- | 'byte'
- | 'char'
- | 'class'
- | 'debugger'
- | 'double'
- | 'each'
- | 'enum'
- | 'export'
- | 'extends'
- | 'final'
- | 'float'
- | 'get'
- | 'set'
- | 'goto'
- | 'implements'
- | 'import'
- | 'int'
- | 'interface'
- | 'is'
- | 'long'
- | 'namespace'
- | 'native'
- | 'package'
- | 'private'
- | 'protected'
- | 'public'
- | 'short'
- | 'static'
- | 'super'
- | 'synchronized'
- | 'throws'
- | 'transient'
- | 'use'
- | 'volatile'
+ : 'each'
+ | 'get'
+ | 'set'
;
reserved
- : 'abstract'
- | 'as'
- | 'boolean'
- | 'break'
- | 'byte'
- | 'case'
- | 'catch'
- | 'char'
- | 'class'
- | 'const'
- | 'continue'
- | 'debugger'
- | 'default'
- | 'delete'
- | 'do'
- | 'double'
- | 'each'
- | 'else'
- | 'enum'
- | 'export'
- | 'extends'
- | 'false'
- | 'final'
- | 'finally'
- | 'float'
- | 'for'
- | 'function'
- | 'get'
- | 'goto'
- | 'if'
- | 'implements'
- | 'import'
- | 'in'
- | 'instanceof'
- | 'int'
- | 'interface'
- | 'is'
- | 'let'
- | 'long'
- | 'namespace'
- | 'native'
- | 'new'
- | 'null'
- | 'package'
- | 'private'
- | 'protected'
- | 'public'
- | 'return'
- | 'set'
- | 'short'
- | 'static'
- | 'super'
- | 'switch'
- | 'synchronized'
- | 'this'
- | 'throw'
- | 'throws'
- | 'transient'
- | 'true'
- | 'try'
- | 'typeof'
- | 'undefined'
- | 'use'
- | 'var'
- | 'void'
- | 'volatile'
- | 'while'
- | 'with'
- | 'yield'
+ : 'break' | 'do' | 'function' | 'new' | 'throw' | 'until'
+ | 'case' | 'each' | 'get' | 'null' | 'true' | 'var'
+ | 'catch' | 'else' | 'if' | 'return' | 'try' | 'void'
+ | 'continue' | 'false' | 'in' | 'set' | 'typeof' | 'while'
+ | 'default' | 'finally' | 'instanceof' | 'switch' | 'undefined' | 'with'
+ | 'delete' | 'for' | 'let' | 'this' | 'unless' | 'yield'
;
-
+
/********************************************************************************
*********************************** Lexer ************************************
********************************************************************************/
SLASH
- : '//' ~( '\n' | '\r' | '\u2028' | '\u2029' )* { skip }
- | '/*' .* '*/' { skip }
- | { @regex_possible }?=> '/' ( ~( '/' | '*' | '\\' | '\r' | '\n' ) | '\\' . ) ( ~( '/' | '\\' | '\n' | '\r' ) | '\\' . )* '/' ( 'a'..'z' )* { $type = REGEX }
- | { !@regex_possible }?=> '/' ( '=' { $type = SLASH_ASGN } | { $type = SLASH } )
+ : '//' ~( '\n' | '\r' )* { $type = LINE_COMMENT; $channel = HIDDEN }
+ | '/*' .* '*/' { $type = COMMENT; $channel = HIDDEN }
+ | { @value_expected }?=> '/' ( ~( '/' | '*' | '\\' | '\r' | '\n' ) | '\\' . ) ( ~( '/' | '\\' | '\n' | '\r' ) | '\\' . )* '/' ( 'a'..'z' )* { $type = REGEX }
+ | { !@value_expected }?=> '/' ( '=' { $type = SLASH_ASGN } | { $type = SLASH } )
;
STRING
- : '"' ( ~( '"' | '\\' | '\n' | '\r' ) | '\\' . )* '"'
- | '\'' ( ~( '\'' | '\\' | '\n' | '\r' ) | '\\' . )* '\''
- ;
+ : '\'' ( ~( '\'' | '\\' ) | '\\' . )* '\''
+ | '"' ( ~( '"' | '\\' ) | '\\' . )* '"'
+ ;
NUMBER
- : ('0'..'9')+ '.' ('0'..'9')* ( ('e' | 'E') ('+' | '-')? ('0'..'9')+ )?
- | '.'? ('0'..'9')+ ( ('e' | 'E') ('+' | '-')? ('0'..'9')+ )?
- | '0' ('x' | 'X') ( '0'..'9' | 'a'..'f' | 'A'..'F' )+
- ;
+ : ('0'..'9')+ '.' ('0'..'9')* ( ('e' | 'E') ('+' | '-')? ('0'..'9')+ )?
+ | '.'? ('0'..'9')+ ( ('e' | 'E') ('+' | '-')? ('0'..'9')+ )?
+ | '0' ('x' | 'X') ( '0'..'9' | 'a'..'f' | 'A'..'F' )+
+ ;
NEWLINE
- : ( '\n' | '\r' )+
- { $channel = HIDDEN }
- ;
+ : ( '\n' | '\r' )+ { $channel = HIDDEN }
+ ;
ID
- : ( '$' | '_' | 'a'..'z' | 'A'..'Z' )
+ : ( '$' | '_' | 'a'..'z' | 'A'..'Z' )
( 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '$' )*
- ;
+ ;
WS // Tab, vertical tab, form feed, space, non-breaking space and any other unicode "space separator".
- : ( '\t' | '\f' | ' ' | '\u00A0' )+ { $channel = HIDDEN }
- ;
+ : ( '\t' | '\f' | ' ' | '\u00A0' )+ { $channel = HIDDEN }
+ ;
+
+
View
2  templates/Ruby.stg
@@ -1459,4 +1459,4 @@ placeAction(scope, name) ::= <<
<endif>
>>
-runtimeLibraryVersion() ::= "1.8.4"
+runtimeLibraryVersion() ::= "1.8.5"
View
40 test/bugs/delegate-warnings/ModuleDefinition.g
@@ -0,0 +1,40 @@
+grammar ModuleDefinition;
+options { language = Ruby; }
+
+/* Lexer definitions */
+
+WS : (' '|'\t'|'\r'|'\n') { skip } ;
+
+BLOCK_COMMENT : '/*' .* '*/' { $channel=HIDDEN; } ;
+LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' { $channel=HIDDEN; } ;
+
+DEC_NUMBER : '0'..'9'+ ;
+HEX_NUMBER : '0' ('x'|'X') ('0'..'9'|'a'..'f'|'A'..'F')+ ;
+
+ID : 'a'..'z' IdTail;
+CID : 'A'..'Z' IdTail;
+
+fragment IdTail : ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
+
+/* Primitives */
+
+number returns[value]
+ : DEC_NUMBER { $value = $DEC_NUMBER.text.to_i }
+ | HEX_NUMBER { $value = $HEX_NUMBER.text[2..-1].to_i(16) };
+
+/* Grammar */
+
+expr1 returns[value]
+ : e=number { $value = $e.value }
+ ( '*' e=number { $value *= $e.value }
+ | '/' e=number { $value /= $e.value }
+ )*
+ ;
+
+expr returns[value]
+ : e=expr1 { $value = $e.value }
+ ( '+' e=expr1 { $value += $e.value }
+ | '-' e=expr1 { $value -= $e.value }
+ )*
+ ;
+
View
678 test/bugs/delegate-warnings/ModuleDefinitionLexer.rb
@@ -0,0 +1,678 @@
+#!/usr/bin/env ruby
+#
+# ModuleDefinition.g
+# --
+# Generated using ANTLR version: 3.2.1-SNAPSHOT Jul 31, 2010 19:34:52
+# Ruby runtime library version: 1.8.1
+# Input grammar file: ModuleDefinition.g
+# Generated at: 2010-10-22 01:19:46
+#
+
+# ~~~> start load path setup
+this_directory = File.expand_path( File.dirname( __FILE__ ) )
+$LOAD_PATH.unshift( this_directory ) unless $LOAD_PATH.include?( this_directory )
+
+antlr_load_failed = proc do
+ load_path = $LOAD_PATH.map { |dir| ' - ' << dir }.join( $/ )
+ raise LoadError, <<-END.strip!
+
+Failed to load the ANTLR3 runtime library (version 1.8.1):
+
+Ensure the library has been installed on your system and is available
+on the load path. If rubygems is available on your system, this can
+be done with the command:
+
+ gem install antlr3
+
+Current load path:
+#{ load_path }
+
+ END
+end
+
+defined?( ANTLR3 ) or begin
+
+ # 1: try to load the ruby antlr3 runtime library from the system path
+ require 'antlr3'
+
+rescue LoadError
+
+ # 2: try to load rubygems if it isn't already loaded
+ defined?( Gem ) or begin
+ require 'rubygems'
+ rescue LoadError
+ antlr_load_failed.call
+ end
+
+ # 3: try to activate the antlr3 gem
+ begin
+ Gem.activate( 'antlr3', '~> 1.8.1' )
+ rescue Gem::LoadError
+ antlr_load_failed.call
+ end
+
+ require 'antlr3'
+
+end
+# <~~~ end load path setup
+
+
+module ModuleDefinition
+ # TokenData defines all of the token type integer values
+ # as constants, which will be included in all
+ # ANTLR-generated recognizers.
+ const_defined?( :TokenData ) or TokenData = ANTLR3::TokenScheme.new
+
+ module TokenData
+
+ # define the token constants
+ define_tokens( :WS => 4, :T__15 => 15, :LINE_COMMENT => 6, :T__12 => 12,
+ :T__14 => 14, :T__13 => 13, :CID => 11, :BLOCK_COMMENT => 5,
+ :IdTail => 9, :DEC_NUMBER => 7, :HEX_NUMBER => 8, :ID => 10,
+ :EOF => -1 )
+
+ end
+
+
+ class Lexer < ANTLR3::Lexer
+ @grammar_home = ModuleDefinition
+ include TokenData
+
+
+ begin
+ generated_using( "ModuleDefinition.g", "3.2.1-SNAPSHOT Jul 31, 2010 19:34:52", "1.8.1" )
+ rescue NoMethodError => error
+ # ignore
+ end
+
+ RULE_NAMES = [ "T__12", "T__13", "T__14", "T__15", "WS", "BLOCK_COMMENT",
+ "LINE_COMMENT", "DEC_NUMBER", "HEX_NUMBER", "ID", "CID",
+ "IdTail" ].freeze
+ RULE_METHODS = [ :t__12!, :t__13!, :t__14!, :t__15!, :ws!, :block_comment!,
+ :line_comment!, :dec_number!, :hex_number!, :id!, :cid!,
+ :id_tail! ].freeze
+
+
+ def initialize( input=nil, options = {} )
+ super( input, options )
+
+ end
+
+
+ # - - - - - - - - - - - lexer rules - - - - - - - - - - - -
+ # lexer rule t__12! (T__12)
+ # (in ModuleDefinition.g)
+ def t__12!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 1 )
+
+ type = T__12
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 7:9: '*'
+ match( 0x2a )
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 1 )
+
+ end
+
+ # lexer rule t__13! (T__13)
+ # (in ModuleDefinition.g)
+ def t__13!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 2 )
+
+ type = T__13
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 8:9: '/'
+ match( 0x2f )
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 2 )
+
+ end
+
+ # lexer rule t__14! (T__14)
+ # (in ModuleDefinition.g)
+ def t__14!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 3 )
+
+ type = T__14
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 9:9: '+'
+ match( 0x2b )
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 3 )
+
+ end
+
+ # lexer rule t__15! (T__15)
+ # (in ModuleDefinition.g)
+ def t__15!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 4 )
+
+ type = T__15
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 10:9: '-'
+ match( 0x2d )
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 4 )
+
+ end
+
+ # lexer rule ws! (WS)
+ # (in ModuleDefinition.g)
+ def ws!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 5 )
+
+ type = WS
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 6:6: ( ' ' | '\\t' | '\\r' | '\\n' )
+ if @input.peek( 1 ).between?( 0x9, 0xa ) || @input.peek(1) == 0xd || @input.peek(1) == 0x20
+ @input.consume
+ else
+ mse = MismatchedSet( nil )
+ recover mse
+ raise mse
+ end
+
+
+ # --> action
+ skip
+ # <-- action
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 5 )
+
+ end
+
+ # lexer rule block_comment! (BLOCK_COMMENT)
+ # (in ModuleDefinition.g)
+ def block_comment!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 6 )
+
+ type = BLOCK_COMMENT
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 8:17: '/*' ( . )* '*/'
+ match( "/*" )
+ # at line 8:22: ( . )*
+ while true # decision 1
+ alt_1 = 2
+ look_1_0 = @input.peek( 1 )
+
+ if ( look_1_0 == 0x2a )
+ look_1_1 = @input.peek( 2 )
+
+ if ( look_1_1 == 0x2f )
+ alt_1 = 2
+ elsif ( look_1_1.between?( 0x0, 0x2e ) || look_1_1.between?( 0x30, 0xffff ) )
+ alt_1 = 1
+
+ end
+ elsif ( look_1_0.between?( 0x0, 0x29 ) || look_1_0.between?( 0x2b, 0xffff ) )
+ alt_1 = 1
+
+ end
+ case alt_1
+ when 1
+ # at line 8:22: .
+ match_any
+
+ else
+ break # out of loop for decision 1
+ end
+ end # loop for decision 1
+ match( "*/" )
+ # --> action
+ channel=HIDDEN;
+ # <-- action
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 6 )
+
+ end
+
+ # lexer rule line_comment! (LINE_COMMENT)
+ # (in ModuleDefinition.g)
+ def line_comment!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 7 )
+
+ type = LINE_COMMENT
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 9:16: '//' (~ ( '\\n' | '\\r' ) )* ( '\\r' )? '\\n'
+ match( "//" )
+ # at line 9:21: (~ ( '\\n' | '\\r' ) )*
+ while true # decision 2
+ alt_2 = 2
+ look_2_0 = @input.peek( 1 )
+
+ if ( look_2_0.between?( 0x0, 0x9 ) || look_2_0.between?( 0xb, 0xc ) || look_2_0.between?( 0xe, 0xffff ) )
+ alt_2 = 1
+
+ end
+ case alt_2
+ when 1
+ # at line 9:21: ~ ( '\\n' | '\\r' )
+ if @input.peek( 1 ).between?( 0x0, 0x9 ) || @input.peek( 1 ).between?( 0xb, 0xc ) || @input.peek( 1 ).between?( 0xe, 0xff )
+ @input.consume
+ else
+ mse = MismatchedSet( nil )
+ recover mse
+ raise mse
+ end
+
+
+
+ else
+ break # out of loop for decision 2
+ end
+ end # loop for decision 2
+ # at line 9:35: ( '\\r' )?
+ alt_3 = 2
+ look_3_0 = @input.peek( 1 )
+
+ if ( look_3_0 == 0xd )
+ alt_3 = 1
+ end
+ case alt_3
+ when 1
+ # at line 9:35: '\\r'
+ match( 0xd )
+
+ end
+ match( 0xa )
+ # --> action
+ channel=HIDDEN;
+ # <-- action
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 7 )
+
+ end
+
+ # lexer rule dec_number! (DEC_NUMBER)
+ # (in ModuleDefinition.g)
+ def dec_number!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 8 )
+
+ type = DEC_NUMBER
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 11:14: ( '0' .. '9' )+
+ # at file 11:14: ( '0' .. '9' )+
+ match_count_4 = 0
+ while true
+ alt_4 = 2
+ look_4_0 = @input.peek( 1 )
+
+ if ( look_4_0.between?( 0x30, 0x39 ) )
+ alt_4 = 1
+
+ end
+ case alt_4
+ when 1
+ # at line 11:14: '0' .. '9'
+ match_range( 0x30, 0x39 )
+
+ else
+ match_count_4 > 0 and break
+ eee = EarlyExit(4)
+
+
+ raise eee
+ end
+ match_count_4 += 1
+ end
+
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 8 )
+
+ end
+
+ # lexer rule hex_number! (HEX_NUMBER)
+ # (in ModuleDefinition.g)
+ def hex_number!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 9 )
+
+ type = HEX_NUMBER
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 12:14: '0' ( 'x' | 'X' ) ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+
+ match( 0x30 )
+ if @input.peek(1) == 0x58 || @input.peek(1) == 0x78
+ @input.consume
+ else
+ mse = MismatchedSet( nil )
+ recover mse
+ raise mse
+ end
+
+
+ # at file 12:28: ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+
+ match_count_5 = 0
+ while true
+ alt_5 = 2
+ look_5_0 = @input.peek( 1 )
+
+ if ( look_5_0.between?( 0x30, 0x39 ) || look_5_0.between?( 0x41, 0x46 ) || look_5_0.between?( 0x61, 0x66 ) )
+ alt_5 = 1
+
+ end
+ case alt_5
+ when 1
+ # at line
+ if @input.peek( 1 ).between?( 0x30, 0x39 ) || @input.peek( 1 ).between?( 0x41, 0x46 ) || @input.peek( 1 ).between?( 0x61, 0x66 )
+ @input.consume
+ else
+ mse = MismatchedSet( nil )
+ recover mse
+ raise mse
+ end
+
+
+
+ else
+ match_count_5 > 0 and break
+ eee = EarlyExit(5)
+
+
+ raise eee
+ end
+ match_count_5 += 1
+ end
+
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 9 )
+
+ end
+
+ # lexer rule id! (ID)
+ # (in ModuleDefinition.g)
+ def id!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 10 )
+
+ type = ID
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 14:7: 'a' .. 'z' IdTail
+ match_range( 0x61, 0x7a )
+ id_tail!
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 10 )
+
+ end
+
+ # lexer rule cid! (CID)
+ # (in ModuleDefinition.g)
+ def cid!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 11 )
+
+ type = CID
+ channel = ANTLR3::DEFAULT_CHANNEL
+
+
+ # - - - - main rule block - - - -
+ # at line 15:7: 'A' .. 'Z' IdTail
+ match_range( 0x41, 0x5a )
+ id_tail!
+
+
+ @state.type = type
+ @state.channel = channel
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 11 )
+
+ end
+
+ # lexer rule id_tail! (IdTail)
+ # (in ModuleDefinition.g)
+ def id_tail!
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 12 )
+
+
+ # - - - - main rule block - - - -
+ # at line 17:19: ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' )*
+ # at line 17:19: ( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' )*
+ while true # decision 6
+ alt_6 = 2
+ look_6_0 = @input.peek( 1 )
+
+ if ( look_6_0.between?( 0x30, 0x39 ) || look_6_0.between?( 0x41, 0x5a ) || look_6_0 == 0x5f || look_6_0.between?( 0x61, 0x7a ) )
+ alt_6 = 1
+
+ end
+ case alt_6
+ when 1
+ # at line
+ if @input.peek( 1 ).between?( 0x30, 0x39 ) || @input.peek( 1 ).between?( 0x41, 0x5a ) || @input.peek(1) == 0x5f || @input.peek( 1 ).between?( 0x61, 0x7a )
+ @input.consume
+ else
+ mse = MismatchedSet( nil )
+ recover mse
+ raise mse
+ end
+
+
+
+ else
+ break # out of loop for decision 6
+ end
+ end # loop for decision 6
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 12 )
+
+ end
+
+ # main rule used to study the input at the current position,
+ # and choose the proper lexer rule to call in order to
+ # fetch the next token
+ #
+ # usually, you don't make direct calls to this method,
+ # but instead use the next_token method, which will
+ # build and emit the actual next token
+ def token!
+ # at line 1:8: ( T__12 | T__13 | T__14 | T__15 | WS | BLOCK_COMMENT | LINE_COMMENT | DEC_NUMBER | HEX_NUMBER | ID | CID )
+ alt_7 = 11
+ alt_7 = @dfa7.predict( @input )
+ case alt_7
+ when 1
+ # at line 1:10: T__12
+ t__12!
+
+ when 2
+ # at line 1:16: T__13
+ t__13!
+
+ when 3
+ # at line 1:22: T__14
+ t__14!
+
+ when 4
+ # at line 1:28: T__15
+ t__15!
+
+ when 5
+ # at line 1:34: WS
+ ws!
+
+ when 6
+ # at line 1:37: BLOCK_COMMENT
+ block_comment!
+
+ when 7
+ # at line 1:51: LINE_COMMENT
+ line_comment!
+
+ when 8
+ # at line 1:64: DEC_NUMBER
+ dec_number!
+
+ when 9
+ # at line 1:75: HEX_NUMBER
+ hex_number!
+
+ when 10
+ # at line 1:86: ID
+ id!
+
+ when 11
+ # at line 1:89: CID
+ cid!
+
+ end
+ end
+
+
+ # - - - - - - - - - - DFA definitions - - - - - - - - - - -
+ class DFA7 < ANTLR3::DFA
+ EOT = unpack( 2, -1, 1, 12, 3, -1, 1, 7, 7, -1 )
+ EOF = unpack( 14, -1 )
+ MIN = unpack( 1, 9, 1, -1, 1, 42, 3, -1, 1, 88, 7, -1 )
+ MAX = unpack( 1, 122, 1, -1, 1, 47, 3, -1, 1, 120, 7, -1 )
+ ACCEPT = unpack( 1, -1, 1, 1, 1, -1, 1, 3, 1, 4, 1, 5, 1, -1, 1, 8,
+ 1, 10, 1, 11, 1, 6, 1, 7, 1, 2, 1, 9 )
+ SPECIAL = unpack( 14, -1 )
+ TRANSITION = [
+ unpack( 2, 5, 2, -1, 1, 5, 18, -1, 1, 5, 9, -1, 1, 1, 1, 3, 1, -1,
+ 1, 4, 1, -1, 1, 2, 1, 6, 9, 7, 7, -1, 26, 9, 6, -1, 26,
+ 8 ),
+ unpack( ),
+ unpack( 1, 10, 4, -1, 1, 11 ),
+ unpack( ),
+ unpack( ),
+ unpack( ),
+ unpack( 1, 13, 31, -1, 1, 13 ),
+ unpack( ),
+ unpack( ),
+ unpack( ),
+ unpack( ),
+ unpack( ),
+ unpack( ),
+ unpack( )
+ ].freeze
+
+ ( 0 ... MIN.length ).zip( MIN, MAX ) do | i, a, z |
+ if a > 0 and z < 0
+ MAX[ i ] %= 0x10000
+ end
+ end
+
+ @decision = 7
+
+
+ def description
+ <<-'__dfa_description__'.strip!
+ 1:1: Tokens : ( T__12 | T__13 | T__14 | T__15 | WS | BLOCK_COMMENT | LINE_COMMENT | DEC_NUMBER | HEX_NUMBER | ID | CID );
+ __dfa_description__
+ end
+ end
+
+
+ private
+
+ def initialize_dfas
+ super rescue nil
+ @dfa7 = DFA7.new( self, 7 )
+
+ end
+ end # class Lexer < ANTLR3::Lexer
+
+ at_exit { Lexer.main( ARGV ) } if __FILE__ == $0
+end
+
View
323 test/bugs/delegate-warnings/ModuleDefinitionParser.rb
@@ -0,0 +1,323 @@
+#!/usr/bin/env ruby
+#
+# ModuleDefinition.g
+# --
+# Generated using ANTLR version: 3.2.1-SNAPSHOT Jul 31, 2010 19:34:52
+# Ruby runtime library version: 1.8.1
+# Input grammar file: ModuleDefinition.g
+# Generated at: 2010-10-22 01:19:45
+#
+
+# ~~~> start load path setup
+this_directory = File.expand_path( File.dirname( __FILE__ ) )
+$LOAD_PATH.unshift( this_directory ) unless $LOAD_PATH.include?( this_directory )
+
+antlr_load_failed = proc do
+ load_path = $LOAD_PATH.map { |dir| ' - ' << dir }.join( $/ )
+ raise LoadError, <<-END.strip!
+
+Failed to load the ANTLR3 runtime library (version 1.8.1):
+
+Ensure the library has been installed on your system and is available
+on the load path. If rubygems is available on your system, this can
+be done with the command:
+
+ gem install antlr3
+
+Current load path:
+#{ load_path }
+
+ END
+end
+
+defined?( ANTLR3 ) or begin
+
+ # 1: try to load the ruby antlr3 runtime library from the system path
+ require 'antlr3'
+
+rescue LoadError
+
+ # 2: try to load rubygems if it isn't already loaded
+ defined?( Gem ) or begin
+ require 'rubygems'
+ rescue LoadError
+ antlr_load_failed.call
+ end
+
+ # 3: try to activate the antlr3 gem
+ begin
+ Gem.activate( 'antlr3', '~> 1.8.1' )
+ rescue Gem::LoadError
+ antlr_load_failed.call
+ end
+
+ require 'antlr3'
+
+end
+# <~~~ end load path setup
+
+
+module ModuleDefinition
+ # TokenData defines all of the token type integer values
+ # as constants, which will be included in all
+ # ANTLR-generated recognizers.
+ const_defined?( :TokenData ) or TokenData = ANTLR3::TokenScheme.new
+
+ module TokenData
+
+ # define the token constants
+ define_tokens( :WS => 4, :T__15 => 15, :LINE_COMMENT => 6, :T__12 => 12,
+ :T__14 => 14, :T__13 => 13, :CID => 11, :BLOCK_COMMENT => 5,
+ :IdTail => 9, :DEC_NUMBER => 7, :ID => 10, :HEX_NUMBER => 8,
+ :EOF => -1 )
+
+ # register the proper human-readable name or literal value
+ # for each token type
+ #
+ # this is necessary because anonymous tokens, which are
+ # created from literal values in the grammar, do not
+ # have descriptive names
+ register_names( "WS", "BLOCK_COMMENT", "LINE_COMMENT", "DEC_NUMBER",
+ "HEX_NUMBER", "IdTail", "ID", "CID", "'*'", "'/'", "'+'",
+ "'-'" )
+
+ end
+
+
+ class Parser < ANTLR3::Parser
+ @grammar_home = ModuleDefinition
+
+ RULE_METHODS = [ :number, :expr1, :expr ].freeze
+
+
+ include TokenData
+
+ begin
+ generated_using( "ModuleDefinition.g", "3.2.1-SNAPSHOT Jul 31, 2010 19:34:52", "1.8.1" )
+ rescue NoMethodError => error
+ # ignore
+ end
+
+ def initialize( input, options = {} )
+ super( input, options )
+
+
+ end
+ # - - - - - - - - - - - - Rules - - - - - - - - - - - - -
+
+ #
+ # parser rule number
+ #
+ # (in ModuleDefinition.g)
+ # 21:1: number returns [value] : ( DEC_NUMBER | HEX_NUMBER );
+ #
+ def number
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 1 )
+ value = nil
+ __DEC_NUMBER1__ = nil
+ __HEX_NUMBER2__ = nil
+
+ begin
+ # at line 22:2: ( DEC_NUMBER | HEX_NUMBER )
+ alt_1 = 2
+ look_1_0 = @input.peek( 1 )
+
+ if ( look_1_0 == DEC_NUMBER )
+ alt_1 = 1
+ elsif ( look_1_0 == HEX_NUMBER )
+ alt_1 = 2
+ else
+ raise NoViableAlternative( "", 1, 0 )
+ end
+ case alt_1
+ when 1
+ # at line 22:4: DEC_NUMBER
+ __DEC_NUMBER1__ = match( DEC_NUMBER, TOKENS_FOLLOWING_DEC_NUMBER_IN_number_180 )
+ # --> action
+ value = __DEC_NUMBER1__.text.to_i
+ # <-- action
+
+ when 2
+ # at line 23:4: HEX_NUMBER
+ __HEX_NUMBER2__ = match( HEX_NUMBER, TOKENS_FOLLOWING_HEX_NUMBER_IN_number_187 )
+ # --> action
+ value = __HEX_NUMBER2__.text[2..-1].to_i(16)
+ # <-- action
+
+ end
+ rescue ANTLR3::Error::RecognitionError => re
+ report_error(re)
+ recover(re)
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 1 )
+
+ end
+
+ return value
+ end
+
+
+ #
+ # parser rule expr1
+ #
+ # (in ModuleDefinition.g)
+ # 27:1: expr1 returns [value] : e= number ( '*' e= number | '/' e= number )* ;
+ #
+ def expr1
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 2 )
+ value = nil
+ e = nil
+
+ begin
+ # at line 28:5: e= number ( '*' e= number | '/' e= number )*
+ @state.following.push( TOKENS_FOLLOWING_number_IN_expr1_207 )
+ e = number
+ @state.following.pop
+ # --> action
+ value = e
+ # <-- action
+ # at line 29:5: ( '*' e= number | '/' e= number )*
+ while true # decision 2
+ alt_2 = 3
+ look_2_0 = @input.peek( 1 )
+
+ if ( look_2_0 == T__12 )
+ alt_2 = 1
+ elsif ( look_2_0 == T__13 )
+ alt_2 = 2
+
+ end
+ case alt_2
+ when 1
+ # at line 29:7: '*' e= number
+ match( T__12, TOKENS_FOLLOWING_T__12_IN_expr1_217 )
+ @state.following.push( TOKENS_FOLLOWING_number_IN_expr1_221 )
+ e = number
+ @state.following.pop
+ # --> action
+ value *= e
+ # <-- action
+
+ when 2
+ # at line 30:7: '/' e= number
+ match( T__13, TOKENS_FOLLOWING_T__13_IN_expr1_231 )
+ @state.following.push( TOKENS_FOLLOWING_number_IN_expr1_235 )
+ e = number
+ @state.following.pop
+ # --> action
+ value /= e
+ # <-- action
+
+ else
+ break # out of loop for decision 2
+ end
+ end # loop for decision 2
+
+ rescue ANTLR3::Error::RecognitionError => re
+ report_error(re)
+ recover(re)
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 2 )
+
+ end
+
+ return value
+ end
+
+
+ #
+ # parser rule expr
+ #
+ # (in ModuleDefinition.g)
+ # 34:1: expr returns [value] : e= expr1 ( '+' e= expr1 | '-' e= expr1 )* ;
+ #
+ def expr
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_in( __method__, 3 )
+ value = nil
+ e = nil
+
+ begin
+ # at line 35:5: e= expr1 ( '+' e= expr1 | '-' e= expr1 )*
+ @state.following.push( TOKENS_FOLLOWING_expr1_IN_expr_262 )
+ e = expr1
+ @state.following.pop
+ # --> action
+ value = e
+ # <-- action
+ # at line 36:5: ( '+' e= expr1 | '-' e= expr1 )*
+ while true # decision 3
+ alt_3 = 3
+ look_3_0 = @input.peek( 1 )
+
+ if ( look_3_0 == T__14 )
+ alt_3 = 1
+ elsif ( look_3_0 == T__15 )
+ alt_3 = 2
+
+ end
+ case alt_3
+ when 1
+ # at line 36:7: '+' e= expr1
+ match( T__14, TOKENS_FOLLOWING_T__14_IN_expr_272 )
+ @state.following.push( TOKENS_FOLLOWING_expr1_IN_expr_276 )
+ e = expr1
+ @state.following.pop
+ # --> action
+ value += e
+ # <-- action
+
+ when 2
+ # at line 37:7: '-' e= expr1
+ match( T__15, TOKENS_FOLLOWING_T__15_IN_expr_286 )
+ @state.following.push( TOKENS_FOLLOWING_expr1_IN_expr_290 )
+ e = expr1
+ @state.following.pop
+ # --> action
+ value -= e
+ # <-- action
+
+ else
+ break # out of loop for decision 3
+ end
+ end # loop for decision 3
+
+ rescue ANTLR3::Error::RecognitionError => re
+ report_error(re)
+ recover(re)
+
+ ensure
+ # -> uncomment the next line to manually enable rule tracing
+ # trace_out( __method__, 3 )
+
+ end
+
+ return value
+ end
+
+
+
+ TOKENS_FOLLOWING_DEC_NUMBER_IN_number_180 = Set[ 1 ]
+ TOKENS_FOLLOWING_HEX_NUMBER_IN_number_187 = Set[ 1 ]
+ TOKENS_FOLLOWING_number_IN_expr1_207 = Set[ 1, 12, 13 ]
+ TOKENS_FOLLOWING_T__12_IN_expr1_217 = Set[ 7, 8 ]
+ TOKENS_FOLLOWING_number_IN_expr1_221 = Set[ 1, 12, 13 ]
+ TOKENS_FOLLOWING_T__13_IN_expr1_231 = Set[ 7, 8 ]
+ TOKENS_FOLLOWING_number_IN_expr1_235 = Set[ 1, 12, 13 ]
+ TOKENS_FOLLOWING_expr1_IN_expr_262 = Set[ 1, 14, 15 ]
+ TOKENS_FOLLOWING_T__14_IN_expr_272 = Set[ 7, 8 ]
+ TOKENS_FOLLOWING_expr1_IN_expr_276 = Set[ 1, 14, 15 ]
+ TOKENS_FOLLOWING_T__15_IN_expr_286 = Set[ 7, 8 ]
+ TOKENS_FOLLOWING_expr1_IN_expr_290 = Set[ 1, 14, 15 ]
+
+ end # class Parser < ANTLR3::Parser
+
+ at_exit { Parser.main( ARGV ) } if __FILE__ == $0
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.