mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/ripper/ripper.rb.in: new const Ripper::PARSER_EVENT_TABLE.
* ext/ripper/ripper.rb.in: new const Ripper::SCANNER_EVENT_TABLE. * ext/ripper/lib/ripper.rb: sync with ripper.rb.in. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f43e22190c
commit
c2c7f4c186
4 changed files with 259 additions and 220 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon Sep 20 04:49:22 2004 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* ext/ripper/ripper.rb.in: new const Ripper::PARSER_EVENT_TABLE.
|
||||
|
||||
* ext/ripper/ripper.rb.in: new const Ripper::SCANNER_EVENT_TABLE.
|
||||
|
||||
* ext/ripper/lib/ripper.rb: sync with ripper.rb.in.
|
||||
|
||||
Mon Sep 20 04:13:00 2004 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* test/ripper/test_scanner_events.rb: test spaces before heredoc
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#
|
||||
# This file is automatically generated from ripper.rb.in and parse.y.
|
||||
# This file is automatically generated from /home/aamine/c/ruby/ext/ripper/ripper.rb.in and parse.y.
|
||||
# DO NOT MODIFY!!!!!!
|
||||
#
|
||||
|
||||
#
|
||||
# ripper.rb
|
||||
#
|
||||
|
@ -12,10 +11,199 @@
|
|||
require 'ripper.so'
|
||||
|
||||
class Ripper
|
||||
def Ripper.parse(str, *args)
|
||||
new(str, *args).parse
|
||||
# Parses Ruby program read from _src_.
|
||||
# _src_ must be a String or a IO or a object which has #gets method.
|
||||
def Ripper.parse(src, filename = '(ripper)', lineno = 1)
|
||||
new(src, filename, lineno).parse
|
||||
end
|
||||
|
||||
# This table contains name of parser events and its arity.
|
||||
PARSER_EVENT_TABLE = {
|
||||
:BEGIN => 1,
|
||||
:END => 1,
|
||||
:alias => 2,
|
||||
:alias_error => 1,
|
||||
:aref => 2,
|
||||
:aref_field => 2,
|
||||
:arg_ambiguous => 0,
|
||||
:arg_paren => 1,
|
||||
:arglist_add => 2,
|
||||
:arglist_add_block => 2,
|
||||
:arglist_add_star => 2,
|
||||
:arglist_new => 0,
|
||||
:arglist_prepend => 2,
|
||||
:array => 1,
|
||||
:assign => 2,
|
||||
:assign_error => 1,
|
||||
:assoc_new => 2,
|
||||
:assoclist_from_args => 1,
|
||||
:bare_assoc_hash => 1,
|
||||
:begin => 1,
|
||||
:binary => 3,
|
||||
:blockvar_add_block => 2,
|
||||
:blockvar_add_star => 2,
|
||||
:blockvar_new => 1,
|
||||
:bodystmt => 4,
|
||||
:brace_block => 2,
|
||||
:break => 1,
|
||||
:call => 3,
|
||||
:case => 2,
|
||||
:class => 3,
|
||||
:class_name_error => 1,
|
||||
:command => 2,
|
||||
:command_call => 4,
|
||||
:const_ref => 1,
|
||||
:constpath_field => 2,
|
||||
:constpath_ref => 2,
|
||||
:def => 3,
|
||||
:defined => 1,
|
||||
:defs => 5,
|
||||
:do_block => 2,
|
||||
:dot2 => 2,
|
||||
:dot3 => 2,
|
||||
:dyna_symbol => 1,
|
||||
:else => 1,
|
||||
:elsif => 3,
|
||||
:ensure => 1,
|
||||
:fcall => 1,
|
||||
:field => 3,
|
||||
:for => 3,
|
||||
:hash => 1,
|
||||
:if => 3,
|
||||
:if_mod => 2,
|
||||
:ifop => 3,
|
||||
:iter_block => 2,
|
||||
:massign => 2,
|
||||
:method_add_arg => 2,
|
||||
:mlhs_add => 2,
|
||||
:mlhs_add_star => 2,
|
||||
:mlhs_new => 0,
|
||||
:mlhs_paren => 1,
|
||||
:module => 2,
|
||||
:mrhs_add => 2,
|
||||
:mrhs_add_star => 2,
|
||||
:mrhs_new => 0,
|
||||
:mrhs_new_from_arglist => 1,
|
||||
:next => 1,
|
||||
:opassign => 3,
|
||||
:param_error => 1,
|
||||
:params => 4,
|
||||
:paren => 1,
|
||||
:parse_error => 1,
|
||||
:program => 1,
|
||||
:qwords_add => 2,
|
||||
:qwords_new => 0,
|
||||
:redo => 0,
|
||||
:regexp_literal => 1,
|
||||
:rescue => 4,
|
||||
:rescue_mod => 2,
|
||||
:restparam => 1,
|
||||
:retry => 0,
|
||||
:return => 1,
|
||||
:return0 => 0,
|
||||
:sclass => 2,
|
||||
:space => 1,
|
||||
:stmts_add => 2,
|
||||
:stmts_new => 0,
|
||||
:string_add => 2,
|
||||
:string_concat => 2,
|
||||
:string_content => 0,
|
||||
:string_dvar => 1,
|
||||
:string_embexpr => 1,
|
||||
:string_literal => 1,
|
||||
:super => 1,
|
||||
:symbol => 1,
|
||||
:symbol_literal => 1,
|
||||
:topconst_field => 1,
|
||||
:topconst_ref => 1,
|
||||
:unary => 2,
|
||||
:undef => 1,
|
||||
:unless => 3,
|
||||
:unless_mod => 2,
|
||||
:until => 2,
|
||||
:until_mod => 2,
|
||||
:var_alias => 2,
|
||||
:var_field => 1,
|
||||
:var_ref => 1,
|
||||
:void_stmt => 0,
|
||||
:when => 3,
|
||||
:while => 2,
|
||||
:while_mod => 2,
|
||||
:word_add => 2,
|
||||
:word_new => 0,
|
||||
:words_add => 2,
|
||||
:words_new => 0,
|
||||
:xstring_add => 2,
|
||||
:xstring_literal => 1,
|
||||
:xstring_new => 0,
|
||||
:yield => 1,
|
||||
:yield0 => 0,
|
||||
:zsuper => 0
|
||||
}
|
||||
|
||||
# This array contains name of parser events.
|
||||
PARSER_EVENTS = PARSER_EVENT_TABLE.keys
|
||||
|
||||
# This table contains name of scanner events and its arity
|
||||
# (arity is always 1 for all scanner events).
|
||||
# on__scan is NOT a scanner event.
|
||||
SCANNER_EVENT_TABLE = {
|
||||
:CHAR => 1,
|
||||
:__end__ => 1,
|
||||
:backref => 1,
|
||||
:backtick => 1,
|
||||
:comma => 1,
|
||||
:comment => 1,
|
||||
:const => 1,
|
||||
:cvar => 1,
|
||||
:embdoc => 1,
|
||||
:embdoc_beg => 1,
|
||||
:embdoc_end => 1,
|
||||
:embexpr_beg => 1,
|
||||
:embexpr_end => 1,
|
||||
:embvar => 1,
|
||||
:float => 1,
|
||||
:gvar => 1,
|
||||
:heredoc_beg => 1,
|
||||
:heredoc_content => 1,
|
||||
:heredoc_end => 1,
|
||||
:ident => 1,
|
||||
:ignored_nl => 1,
|
||||
:int => 1,
|
||||
:ivar => 1,
|
||||
:kw => 1,
|
||||
:lbrace => 1,
|
||||
:lbracket => 1,
|
||||
:lparen => 1,
|
||||
:nl => 1,
|
||||
:op => 1,
|
||||
:period => 1,
|
||||
:qwords_beg => 1,
|
||||
:rbrace => 1,
|
||||
:rbracket => 1,
|
||||
:regexp_beg => 1,
|
||||
:regexp_end => 1,
|
||||
:rparen => 1,
|
||||
:semicolon => 1,
|
||||
:sp => 1,
|
||||
:symbeg => 1,
|
||||
:tstring_beg => 1,
|
||||
:tstring_content => 1,
|
||||
:tstring_end => 1,
|
||||
:words_beg => 1,
|
||||
:words_sep => 1
|
||||
}
|
||||
|
||||
# This array contains name of scanner events.
|
||||
SCANNER_EVENTS = SCANNER_EVENT_TABLE.keys
|
||||
|
||||
# This table contains name of all ripper events, except on__scan.
|
||||
EVENTS = PARSER_EVENTS + SCANNER_EVENTS
|
||||
|
||||
### ###
|
||||
### Event Handlers ###
|
||||
### ###
|
||||
|
||||
private
|
||||
|
||||
def warn(fmt, *args)
|
||||
|
@ -27,181 +215,6 @@ class Ripper
|
|||
def compile_error(msg)
|
||||
end
|
||||
|
||||
PARSER_EVENTS = [
|
||||
|
||||
:BEGIN,
|
||||
:END,
|
||||
:alias,
|
||||
:alias_error,
|
||||
:aref,
|
||||
:aref_field,
|
||||
:arg_ambiguous,
|
||||
:arg_paren,
|
||||
:arglist_add,
|
||||
:arglist_add_block,
|
||||
:arglist_add_star,
|
||||
:arglist_new,
|
||||
:arglist_prepend,
|
||||
:array,
|
||||
:assign,
|
||||
:assign_error,
|
||||
:assoc_new,
|
||||
:assoclist_from_args,
|
||||
:bare_assoc_hash,
|
||||
:begin,
|
||||
:binary,
|
||||
:blockvar_add_block,
|
||||
:blockvar_add_star,
|
||||
:blockvar_new,
|
||||
:bodystmt,
|
||||
:brace_block,
|
||||
:break,
|
||||
:call,
|
||||
:case,
|
||||
:class,
|
||||
:class_name_error,
|
||||
:command,
|
||||
:command_call,
|
||||
:const_ref,
|
||||
:constpath_field,
|
||||
:constpath_ref,
|
||||
:def,
|
||||
:defined,
|
||||
:defs,
|
||||
:do_block,
|
||||
:dot2,
|
||||
:dot3,
|
||||
:dyna_symbol,
|
||||
:else,
|
||||
:elsif,
|
||||
:ensure,
|
||||
:fcall,
|
||||
:field,
|
||||
:for,
|
||||
:hash,
|
||||
:if,
|
||||
:if_mod,
|
||||
:ifop,
|
||||
:iter_block,
|
||||
:massign,
|
||||
:method_add_arg,
|
||||
:mlhs_add,
|
||||
:mlhs_add_star,
|
||||
:mlhs_new,
|
||||
:mlhs_paren,
|
||||
:module,
|
||||
:mrhs_add,
|
||||
:mrhs_add_star,
|
||||
:mrhs_new,
|
||||
:mrhs_new_from_arglist,
|
||||
:next,
|
||||
:opassign,
|
||||
:param_error,
|
||||
:params,
|
||||
:paren,
|
||||
:parse_error,
|
||||
:program,
|
||||
:qwords_add,
|
||||
:qwords_new,
|
||||
:redo,
|
||||
:regexp_literal,
|
||||
:rescue,
|
||||
:rescue_mod,
|
||||
:restparam,
|
||||
:retry,
|
||||
:return,
|
||||
:return0,
|
||||
:sclass,
|
||||
:space,
|
||||
:stmts_add,
|
||||
:stmts_new,
|
||||
:string_add,
|
||||
:string_concat,
|
||||
:string_content,
|
||||
:string_dvar,
|
||||
:string_embexpr,
|
||||
:string_literal,
|
||||
:super,
|
||||
:symbol,
|
||||
:symbol_literal,
|
||||
:topconst_field,
|
||||
:topconst_ref,
|
||||
:unary,
|
||||
:undef,
|
||||
:unless,
|
||||
:unless_mod,
|
||||
:until,
|
||||
:until_mod,
|
||||
:var_alias,
|
||||
:var_field,
|
||||
:var_ref,
|
||||
:void_stmt,
|
||||
:when,
|
||||
:while,
|
||||
:while_mod,
|
||||
:word_add,
|
||||
:word_new,
|
||||
:words_add,
|
||||
:words_new,
|
||||
:xstring_add,
|
||||
:xstring_literal,
|
||||
:xstring_new,
|
||||
:yield,
|
||||
:yield0,
|
||||
:zsuper
|
||||
]
|
||||
|
||||
SCANNER_EVENTS = [
|
||||
|
||||
:CHAR,
|
||||
:__end__,
|
||||
:backref,
|
||||
:backtick,
|
||||
:comma,
|
||||
:comment,
|
||||
:const,
|
||||
:cvar,
|
||||
:embdoc,
|
||||
:embdoc_beg,
|
||||
:embdoc_end,
|
||||
:embexpr_beg,
|
||||
:embexpr_end,
|
||||
:embvar,
|
||||
:float,
|
||||
:gvar,
|
||||
:heredoc_beg,
|
||||
:heredoc_content,
|
||||
:heredoc_end,
|
||||
:ident,
|
||||
:ignored_nl,
|
||||
:int,
|
||||
:ivar,
|
||||
:kw,
|
||||
:lbrace,
|
||||
:lbracket,
|
||||
:lparen,
|
||||
:nl,
|
||||
:op,
|
||||
:period,
|
||||
:qwords_beg,
|
||||
:rbrace,
|
||||
:rbracket,
|
||||
:regexp_beg,
|
||||
:regexp_end,
|
||||
:rparen,
|
||||
:semicolon,
|
||||
:sp,
|
||||
:symbeg,
|
||||
:tstring_beg,
|
||||
:tstring_content,
|
||||
:tstring_end,
|
||||
:words_beg,
|
||||
:words_sep
|
||||
]
|
||||
LEXER_EVENTS = SCANNER_EVENTS
|
||||
|
||||
EVENTS = PARSER_EVENTS + SCANNER_EVENTS
|
||||
|
||||
#
|
||||
# Parser Events
|
||||
#
|
||||
|
@ -230,7 +243,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__arg_ambiguous()
|
||||
def on__arg_ambiguous
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -250,7 +263,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__arglist_new()
|
||||
def on__arglist_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -438,7 +451,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__mlhs_new()
|
||||
def on__mlhs_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -458,7 +471,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__mrhs_new()
|
||||
def on__mrhs_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -498,11 +511,11 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__qwords_new()
|
||||
def on__qwords_new
|
||||
nil
|
||||
end
|
||||
|
||||
def on__redo()
|
||||
def on__redo
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -522,7 +535,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__retry()
|
||||
def on__retry
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -530,7 +543,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__return0()
|
||||
def on__return0
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -546,7 +559,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__stmts_new()
|
||||
def on__stmts_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -558,7 +571,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__string_content()
|
||||
def on__string_content
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -630,7 +643,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__void_stmt()
|
||||
def on__void_stmt
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -650,7 +663,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__word_new()
|
||||
def on__word_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -658,7 +671,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__words_new()
|
||||
def on__words_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -670,7 +683,7 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__xstring_new()
|
||||
def on__xstring_new
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -678,11 +691,11 @@ class Ripper
|
|||
a
|
||||
end
|
||||
|
||||
def on__yield0()
|
||||
def on__yield0
|
||||
nil
|
||||
end
|
||||
|
||||
def on__zsuper()
|
||||
def on__zsuper
|
||||
nil
|
||||
end
|
||||
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
#
|
||||
# This file is automatically generated from ripper.rb.in and parse.y.
|
||||
# DO NOT MODIFY!!!!!!
|
||||
#
|
||||
|
||||
#
|
||||
# ripper.rb
|
||||
#
|
||||
|
@ -12,10 +7,37 @@
|
|||
require 'ripper.so'
|
||||
|
||||
class Ripper
|
||||
def Ripper.parse(str, *args)
|
||||
new(str, *args).parse
|
||||
# Parses Ruby program read from _src_.
|
||||
# _src_ must be a String or a IO or a object which has #gets method.
|
||||
def Ripper.parse(src, filename = '(ripper)', lineno = 1)
|
||||
new(src, filename, lineno).parse
|
||||
end
|
||||
|
||||
# This table contains name of parser events and its arity.
|
||||
PARSER_EVENT_TABLE = {
|
||||
#include ids1
|
||||
}
|
||||
|
||||
# This array contains name of parser events.
|
||||
PARSER_EVENTS = PARSER_EVENT_TABLE.keys
|
||||
|
||||
# This table contains name of scanner events and its arity
|
||||
# (arity is always 1 for all scanner events).
|
||||
# on__scan is NOT a scanner event.
|
||||
SCANNER_EVENT_TABLE = {
|
||||
#include ids2
|
||||
}
|
||||
|
||||
# This array contains name of scanner events.
|
||||
SCANNER_EVENTS = SCANNER_EVENT_TABLE.keys
|
||||
|
||||
# This table contains name of all ripper events, except on__scan.
|
||||
EVENTS = PARSER_EVENTS + SCANNER_EVENTS
|
||||
|
||||
### ###
|
||||
### Event Handlers ###
|
||||
### ###
|
||||
|
||||
private
|
||||
|
||||
def warn(fmt, *args)
|
||||
|
@ -27,17 +49,6 @@ class Ripper
|
|||
def compile_error(msg)
|
||||
end
|
||||
|
||||
PARSER_EVENTS = [
|
||||
#include ids1
|
||||
]
|
||||
|
||||
SCANNER_EVENTS = [
|
||||
#include ids2
|
||||
]
|
||||
LEXER_EVENTS = SCANNER_EVENTS
|
||||
|
||||
EVENTS = PARSER_EVENTS + SCANNER_EVENTS
|
||||
|
||||
#
|
||||
# Parser Events
|
||||
#
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
def main
|
||||
template, ids1, ids2 = *ARGV
|
||||
print <<header
|
||||
#
|
||||
# This file is automatically generated from #{template} and parse.y.
|
||||
# DO NOT MODIFY!!!!!!
|
||||
#
|
||||
header
|
||||
File.foreach(template) do |line|
|
||||
case line
|
||||
when /\A\#include ids1/
|
||||
|
@ -13,7 +19,7 @@ def main
|
|||
id, arity = line.split
|
||||
arity = arity.to_i
|
||||
puts
|
||||
puts " def on__#{id}(#{argdecl(arity)})"
|
||||
puts " def on__#{id}#{paramdecl(arity)}"
|
||||
puts " #{arity == 0 ? 'nil' : 'a'}"
|
||||
puts " end"
|
||||
end
|
||||
|
@ -35,20 +41,21 @@ def main
|
|||
end
|
||||
|
||||
def print_items(ids)
|
||||
comma = "\n"
|
||||
ids.each do |id|
|
||||
comma = ''
|
||||
ids.each do |id, arity|
|
||||
print comma; comma = ",\n"
|
||||
print " #{id.intern.inspect}"
|
||||
print " #{id.intern.inspect} => #{arity}"
|
||||
end
|
||||
puts
|
||||
end
|
||||
|
||||
def read_ids(path)
|
||||
File.readlines(path).map {|line| line.split[0] }
|
||||
File.readlines(path).map {|line| line.split }
|
||||
end
|
||||
|
||||
def argdecl(n)
|
||||
%w(a b c d e f g h i j k l m)[0, n].join(', ')
|
||||
def paramdecl(n)
|
||||
return '' if n == 0
|
||||
'(' + %w(a b c d e f g h i j k l m)[0, n].join(', ') + ')'
|
||||
end
|
||||
|
||||
main
|
||||
|
|
Loading…
Reference in a new issue