class ANTLR3::Template::GroupFile::Parser
Constants
- RULE_METHODS
- TOKENS_FOLLOWING_CONSTANT_IN_group_name_144
- TOKENS_FOLLOWING_CONSTANT_IN_group_name_169
- TOKENS_FOLLOWING_ID_IN_member_199
- TOKENS_FOLLOWING_ID_IN_member_220
- TOKENS_FOLLOWING_ID_IN_parameter_346
- TOKENS_FOLLOWING_ID_IN_parameter_358
- TOKENS_FOLLOWING_ID_IN_parameter_368
- TOKENS_FOLLOWING_STRING_IN_member_242
- TOKENS_FOLLOWING_STRING_IN_parameter_386
- TOKENS_FOLLOWING_TEMPLATE_IN_member_230
- TOKENS_FOLLOWING_T__10_IN_group_name_128
- TOKENS_FOLLOWING_T__11_IN_group_name_146
- TOKENS_FOLLOWING_T__12_IN_group_name_177
- TOKENS_FOLLOWING_T__13_IN_member_210
- TOKENS_FOLLOWING_T__14_IN_parameter_declaration_276
- TOKENS_FOLLOWING_T__15_IN_parameter_declaration_287
- TOKENS_FOLLOWING_T__16_IN_parameters_322
- TOKENS_FOLLOWING_T__17_IN_parameter_342
- TOKENS_FOLLOWING_T__18_IN_parameter_354
- TOKENS_FOLLOWING_T__19_IN_parameter_382
- TOKENS_FOLLOWING_group_name_IN_group_spec_85
- TOKENS_FOLLOWING_member_IN_group_spec_108
- TOKENS_FOLLOWING_parameter_IN_parameters_317
- TOKENS_FOLLOWING_parameter_IN_parameters_324
- TOKENS_FOLLOWING_parameter_declaration_IN_member_203
- TOKENS_FOLLOWING_parameters_IN_parameter_declaration_280
- TOKENS_FOLLOWING_parameters_IN_parameter_declaration_293
Public Class Methods
ANTLR3::Parser::new
# File lib/antlr3/template/group-file-parser.rb, line 111 def initialize( input, options = {} ) super( input, options ) end
Public Instance Methods
# File lib/antlr3/template/group-file-parser.rb, line 151 def extract_template( token ) case token.type when TEMPLATE token.text.gsub( /\A<<<\r?\n?|\r?\n?>>>\Z/, '' ) when STRING unescape( token.text[1...-1] ) end end
# File lib/antlr3/template/group-file-parser.rb, line 117 def fetch_group( namespace, name ) if namespace.const_defined?( name ) group = namespace.const_get( name ) unless group.is_a?( ANTLR3::Template::Group ) end else group = ANTLR3::Template::Group.new namespace.const_set( name, group ) end return( group ) end
# File lib/antlr3/template/group-file-parser.rb, line 160 def group( namespace = ::Object ) group_spec( namespace ) end
parser rule group_name
(in GroupFile.g) 86:1: group_name
[ namespace ] returns [ group ] : ‘group’ (mod= CONSTANT ‘::’ )* name= CONSTANT ( ‘;’ )? ;
# File lib/antlr3/template/group-file-parser.rb, line 249 def group_name( namespace ) # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 2 ) group = nil mod = nil name = nil begin # at line 87:5: 'group' (mod= CONSTANT '::' )* name= CONSTANT ( ';' )? match( T__10, TOKENS_FOLLOWING_T__10_IN_group_name_128 ) # at line 88:5: (mod= CONSTANT '::' )* while true # decision 3 alt_3 = 2 look_3_0 = @input.peek( 1 ) if ( look_3_0 == CONSTANT ) look_3_1 = @input.peek( 2 ) if ( look_3_1 == T__11 ) alt_3 = 1 end end case alt_3 when 1 # at line 89:7: mod= CONSTANT '::' mod = match( CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_144 ) match( T__11, TOKENS_FOLLOWING_T__11_IN_group_name_146 ) # --> action namespace = namespace.const_get( mod.text ) # <-- action else break # out of loop for decision 3 end end # loop for decision 3 name = match( CONSTANT, TOKENS_FOLLOWING_CONSTANT_IN_group_name_169 ) # --> action group = fetch_group( namespace, name.text ) # <-- action # at line 93:5: ( ';' )? alt_4 = 2 look_4_0 = @input.peek( 1 ) if ( look_4_0 == T__12 ) alt_4 = 1 end case alt_4 when 1 # at line 93:5: ';' match( T__12, TOKENS_FOLLOWING_T__12_IN_group_name_177 ) end 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 group end
parser rule group_spec
(in GroupFile.g) 79:1: group_spec
[ namespace ] returns [ group ] : ( group_name
[ $namespace ] | ) ( member[ $group ] )* ;
# File lib/antlr3/template/group-file-parser.rb, line 172 def group_spec( namespace ) # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 1 ) group = nil group_name1 = nil begin # at line 80:5: ( group_name[ $namespace ] | ) ( member[ $group ] )* # at line 80:5: ( group_name[ $namespace ] | ) alt_1 = 2 look_1_0 = @input.peek( 1 ) if ( look_1_0 == T__10 ) alt_1 = 1 elsif ( look_1_0 == EOF || look_1_0 == ID ) alt_1 = 2 else raise NoViableAlternative( "", 1, 0 ) end case alt_1 when 1 # at line 80:7: group_name[ $namespace ] @state.following.push( TOKENS_FOLLOWING_group_name_IN_group_spec_85 ) group_name1 = group_name( namespace ) @state.following.pop # --> action group = group_name1 # <-- action when 2 # at line 81:7: # --> action group = ANTLR3::Template::Group.new # <-- action end # at line 83:5: ( member[ $group ] )* while true # decision 2 alt_2 = 2 look_2_0 = @input.peek( 1 ) if ( look_2_0 == ID ) alt_2 = 1 end case alt_2 when 1 # at line 83:5: member[ $group ] @state.following.push( TOKENS_FOLLOWING_member_IN_group_spec_108 ) member( group ) @state.following.pop 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__, 1 ) end return group end
parser rule member
(in GroupFile.g) 96:1: member[ group ] : name= ID ( parameter_declaration
)? ‘::=’ (aliased= ID | TEMPLATE | STRING ) ;
# File lib/antlr3/template/group-file-parser.rb, line 324 def member( group ) # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 3 ) name = nil aliased = nil __TEMPLATE3__ = nil __STRING4__ = nil parameter_declaration2 = nil # - - - - @init action - - - - params = nil begin # at line 98:5: name= ID ( parameter_declaration )? '::=' (aliased= ID | TEMPLATE | STRING ) name = match( ID, TOKENS_FOLLOWING_ID_IN_member_199 ) # at line 98:13: ( parameter_declaration )? alt_5 = 2 look_5_0 = @input.peek( 1 ) if ( look_5_0 == ID || look_5_0 == T__14 || look_5_0.between?( T__17, T__18 ) ) alt_5 = 1 end case alt_5 when 1 # at line 98:15: parameter_declaration @state.following.push( TOKENS_FOLLOWING_parameter_declaration_IN_member_203 ) parameter_declaration2 = parameter_declaration @state.following.pop # --> action params = parameter_declaration2 # <-- action end match( T__13, TOKENS_FOLLOWING_T__13_IN_member_210 ) # at line 99:5: (aliased= ID | TEMPLATE | STRING ) alt_6 = 3 case look_6 = @input.peek( 1 ) when ID then alt_6 = 1 when TEMPLATE then alt_6 = 2 when STRING then alt_6 = 3 else raise NoViableAlternative( "", 6, 0 ) end case alt_6 when 1 # at line 99:7: aliased= ID aliased = match( ID, TOKENS_FOLLOWING_ID_IN_member_220 ) # --> action group.alias_template( name.text, aliased.text ) # <-- action when 2 # at line 100:7: TEMPLATE __TEMPLATE3__ = match( TEMPLATE, TOKENS_FOLLOWING_TEMPLATE_IN_member_230 ) # --> action group.define_template( name.text, extract_template( __TEMPLATE3__ ), params ) # <-- action when 3 # at line 101:7: STRING __STRING4__ = match( STRING, TOKENS_FOLLOWING_STRING_IN_member_242 ) # --> action group.define_template( name.text, extract_template( __STRING4__ ), params ) # <-- 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__, 3 ) end return end
parser rule parameter
(in GroupFile.g) 116:1: parameter[ parameters ] : ( ‘*’ name= ID | ‘&’ name= ID | name= ID ( ‘=’ v= STRING )? );
# File lib/antlr3/template/group-file-parser.rb, line 539 def parameter( parameters ) # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 6 ) name = nil v = nil begin # at line 117:3: ( '*' name= ID | '&' name= ID | name= ID ( '=' v= STRING )? ) alt_11 = 3 case look_11 = @input.peek( 1 ) when T__17 then alt_11 = 1 when T__18 then alt_11 = 2 when ID then alt_11 = 3 else raise NoViableAlternative( "", 11, 0 ) end case alt_11 when 1 # at line 117:5: '*' name= ID match( T__17, TOKENS_FOLLOWING_T__17_IN_parameter_342 ) name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_346 ) # --> action parameters.splat = name.text # <-- action when 2 # at line 118:5: '&' name= ID match( T__18, TOKENS_FOLLOWING_T__18_IN_parameter_354 ) name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_358 ) # --> action parameters.block = name.text # <-- action when 3 # at line 119:5: name= ID ( '=' v= STRING )? name = match( ID, TOKENS_FOLLOWING_ID_IN_parameter_368 ) # --> action param = ANTLR3::Template::Parameter.new( name.text ) # <-- action # at line 120:5: ( '=' v= STRING )? alt_10 = 2 look_10_0 = @input.peek( 1 ) if ( look_10_0 == T__19 ) alt_10 = 1 end case alt_10 when 1 # at line 120:7: '=' v= STRING match( T__19, TOKENS_FOLLOWING_T__19_IN_parameter_382 ) v = match( STRING, TOKENS_FOLLOWING_STRING_IN_parameter_386 ) # --> action param.default = v.text # <-- action end # --> action parameters.add( param ) # <-- 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__, 6 ) end return end
parser rule parameter_declaration
(in GroupFile.g) 105:1: parameter_declaration
returns [ list ] : ( ‘(’ ( parameters )? ‘)’ | parameters );
# File lib/antlr3/template/group-file-parser.rb, line 410 def parameter_declaration # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 4 ) list = nil parameters5 = nil parameters6 = nil # - - - - @init action - - - - list = nil begin # at line 107:3: ( '(' ( parameters )? ')' | parameters ) alt_8 = 2 look_8_0 = @input.peek( 1 ) if ( look_8_0 == T__14 ) alt_8 = 1 elsif ( look_8_0 == ID || look_8_0.between?( T__17, T__18 ) ) alt_8 = 2 else raise NoViableAlternative( "", 8, 0 ) end case alt_8 when 1 # at line 107:5: '(' ( parameters )? ')' match( T__14, TOKENS_FOLLOWING_T__14_IN_parameter_declaration_276 ) # at line 107:9: ( parameters )? alt_7 = 2 look_7_0 = @input.peek( 1 ) if ( look_7_0 == ID || look_7_0.between?( T__17, T__18 ) ) alt_7 = 1 end case alt_7 when 1 # at line 107:11: parameters @state.following.push( TOKENS_FOLLOWING_parameters_IN_parameter_declaration_280 ) parameters5 = parameters @state.following.pop # --> action list = parameters5 # <-- action end match( T__15, TOKENS_FOLLOWING_T__15_IN_parameter_declaration_287 ) when 2 # at line 108:5: parameters @state.following.push( TOKENS_FOLLOWING_parameters_IN_parameter_declaration_293 ) parameters6 = parameters @state.following.pop # --> action list = parameters6 # <-- 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__, 4 ) end return list end
parser rule parameters
(in GroupFile.g) 111:1: parameters returns [ list ] : parameter[ $list ] ( ‘,’ parameter[ $list ] )* ;
# File lib/antlr3/template/group-file-parser.rb, line 485 def parameters # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 5 ) list = nil # - - - - @init action - - - - list = ANTLR3::Template::ParameterList.new begin # at line 113:5: parameter[ $list ] ( ',' parameter[ $list ] )* @state.following.push( TOKENS_FOLLOWING_parameter_IN_parameters_317 ) parameter( list ) @state.following.pop # at line 113:24: ( ',' parameter[ $list ] )* while true # decision 9 alt_9 = 2 look_9_0 = @input.peek( 1 ) if ( look_9_0 == T__16 ) alt_9 = 1 end case alt_9 when 1 # at line 113:26: ',' parameter[ $list ] match( T__16, TOKENS_FOLLOWING_T__16_IN_parameters_322 ) @state.following.push( TOKENS_FOLLOWING_parameter_IN_parameters_324 ) parameter( list ) @state.following.pop else break # out of loop for decision 9 end end # loop for decision 9 rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 5 ) end return list end
# File lib/antlr3/template/group-file-parser.rb, line 130 def unescape( text ) text.gsub( /\\(?:([abefnrstv])|([0-7]{3})|x([0-9a-fA-F]{2})|(.))/ ) do if $1 case $1[0] when ?a then "\a" when ?b then "\b" when ?e then "\e" when ?f then "\f" when ?n then "\n" when ?r then "\r" when ?s then "\s" when ?t then "\t" when ?v then "\v" end elsif $2 then $2.to_i( 8 ).chr elsif $3 then $3.to_i( 16 ).chr elsif $4 then $4 end end end