* parse.y [ripper]: space event is on__sp, not on__lwsp. [ruby-dev:24257]

* ext/ripper/eventids2.c: ditto.
* ext/ripper/lib/ripper.rb: ditto.
* ext/ripper/depend (ripper.o): No action is needed. [ruby-dev:24260]
* ext/ripper/depend: Borland make does not accept pipes in Makefile rules. [ruby-dev:24589]
* ext/ripper/depend: separate rules for developpers.
* ext/ripper/Makefile.dev: new file.
* ext/ripper/MANIFEST: add Makefile.dev.
* ext/ripper/tools/generate-eventids1.rb: read from file, not stdin.
* ext/ripper/extconf.rb: clean ripper.E.
* ext/ripper/tools/generate-ripper_rb.rb: #include ids1/ids2 function was lost.
* ext/ripper/tools/generate-ripper_rb.rb: SCANNER_EVENTS wrongly contained parser events.
* ext/ripper/lib/ripper.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2004-09-14 11:27:36 +00:00
parent 26a828a605
commit d3bce8cb5a
11 changed files with 157 additions and 185 deletions

View File

@ -1,3 +1,37 @@
Tue Sep 14 20:24:49 2004 Minero Aoki <aamine@loveruby.net>
* parse.y [ripper]: space event is on__sp, not on__lwsp.
[ruby-dev:24257]
* ext/ripper/eventids2.c: ditto.
* ext/ripper/lib/ripper.rb: ditto.
* ext/ripper/depend (ripper.o): No action is needed.
[ruby-dev:24260]
* ext/ripper/depend: Borland make does not accept pipes in
Makefile rules. [ruby-dev:24589]
* ext/ripper/depend: separate rules for developpers.
* ext/ripper/Makefile.dev: new file.
* ext/ripper/MANIFEST: add Makefile.dev.
* ext/ripper/tools/generate-eventids1.rb: read from file, not
stdin.
* ext/ripper/extconf.rb: clean ripper.E.
* ext/ripper/tools/generate-ripper_rb.rb: #include ids1/ids2
function was lost.
* ext/ripper/tools/generate-ripper_rb.rb: SCANNER_EVENTS wrongly
contained parser events.
* ext/ripper/lib/ripper.rb: ditto.
Tue Sep 14 16:59:37 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Tue Sep 14 16:59:37 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: fix SEGV * ext/tcltklib/tcltklib.c: fix SEGV

4
ext/ripper/.cvsignore Normal file
View File

@ -0,0 +1,4 @@
Makefile
eventids1.c
ripper.c
ripper.y

View File

@ -1,4 +1,5 @@
MANIFEST MANIFEST
Makefile.dev
README README
depend depend
eventids2.c eventids2.c

18
ext/ripper/Makefile.dev Normal file
View File

@ -0,0 +1,18 @@
# Makefile for ripper developpers
# !!! This file requires GNU make !!!
include Makefile
lib/ripper.rb: $(srcdir)/ripper.rb.in ids1 ids2 $(srcdir)/tools/generate-ripper_rb.rb
$(RUBY) $(srcdir)/tools/generate-ripper_rb.rb $(srcdir)/ripper.rb.in ids1 ids2 > $@
test:
$(RUBY) test/check-event-arity.rb $(hdrdir)/parse.y
sh test/check-event-coverage.sh
$(RUBY) test/check-scanner-event-coverage.rb
$(RUBY) test/validate.rb > /dev/null
@echo OK
preproc: ripper.E
ripper.E: ripper.c
$(CC) -E $(CPPFLAGS) ripper.c | ruby tools/strip.rb > $@

View File

@ -1,6 +1,4 @@
# Do not remove "./"; nmake requires this. ripper.o: lex.c eventids1.c eventids2.c
ripper.o: ./ripper.c lex.c eventids1.c eventids2.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c ./ripper.c
ripper.c: ripper.y ripper.c: ripper.y
bison -t -v -o$@ ripper.y bison -t -v -o$@ ripper.y
@ -8,31 +6,11 @@ ripper.c: ripper.y
ripper.y: $(hdrdir)/parse.y $(srcdir)/tools/preproc.rb ripper.y: $(hdrdir)/parse.y $(srcdir)/tools/preproc.rb
$(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y > $@ $(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y > $@
eventids1.c: $(hdrdir)/parse.y $(srcdir)/tools/list-parse-event-ids.rb $(srcdir)/tools/generate-eventids1.rb eventids1.c: $(hdrdir)/parse.y $(srcdir)/tools/generate-eventids1.rb ids1
$(RUBY) $(srcdir)/tools/list-parse-event-ids.rb $(hdrdir)/parse.y | $(RUBY) $(srcdir)/tools/generate-eventids1.rb > $@ $(RUBY) $(srcdir)/tools/generate-eventids1.rb ids1 > $@
lex.c: ids1: $(srcdir)/tools/list-parse-event-ids.rb $(hdrdir)/parse.y
cp $(hdrdir)/lex.c . || cp $(srcdir)/lex.c . $(RUBY) $(srcdir)/tools/list-parse-event-ids.rb -a $(hdrdir)/parse.y > $@
# ids2: $(srcdir)/tools/list-scan-event-ids.rb $(srcdir)/eventids2.c
# Entries for ripper developpers (no srcdir/objdir support) $(RUBY) $(srcdir)/tools/list-scan-event-ids.rb -a $(srcdir)/eventids2.c > $@
#
lib/ripper.rb: ripper.rb.in ids1 ids2 tools/generate-ripper_rb.rb
$(RUBY) tools/generate-ripper_rb.rb ripper.rb.in ids1 ids2 > $@
ids1: tools/list-parse-event-ids.rb ../../parse.y
$(RUBY) tools/list-parse-event-ids.rb -a ../../parse.y > $@
ids2: $(srcdir)/tools/list-scan-event-ids.rb eventids2.c
$(RUBY) tools/list-scan-event-ids.rb -a eventids2.c > $@
test: ripper.so test/*.*
$(RUBY) test/check-event-arity.rb $(hdrdir)/parse.y
sh test/check-event-coverage.sh
$(RUBY) test/check-scanner-event-coverage.rb
$(RUBY) test/validate.rb > /dev/null
@echo OK
preproc: ripper.E
ripper.E: ripper.c
$(CC) -E $(CPPFLAGS) ripper.c | ruby tools/strip.rb > $@

View File

@ -1,14 +1,14 @@
#define tIGNORED_NL (tLAST_TOKEN + 1) #define tIGNORED_NL (tLAST_TOKEN + 1)
#define tCOMMENT (tLAST_TOKEN + 2) #define tCOMMENT (tLAST_TOKEN + 2)
#define tEMBDOC_BEG (tLAST_TOKEN + 3) #define tEMBDOC_BEG (tLAST_TOKEN + 3)
#define tEMBDOC (tLAST_TOKEN + 4) #define tEMBDOC (tLAST_TOKEN + 4)
#define tEMBDOC_END (tLAST_TOKEN + 5) #define tEMBDOC_END (tLAST_TOKEN + 5)
#define tLWSP (tLAST_TOKEN + 6) #define tSP (tLAST_TOKEN + 6)
#define tHEREDOC_BEG (tLAST_TOKEN + 7) #define tHEREDOC_BEG (tLAST_TOKEN + 7)
#define tHEREDOC_CONTENT (tLAST_TOKEN + 8) #define tHEREDOC_CONTENT (tLAST_TOKEN + 8)
#define tHEREDOC_END (tLAST_TOKEN + 9) #define tHEREDOC_END (tLAST_TOKEN + 9)
#define k__END__ (tLAST_TOKEN + 10) #define k__END__ (tLAST_TOKEN + 10)
#define tCHAR (tLAST_TOKEN + 11) #define tCHAR (tLAST_TOKEN + 11)
static ID ripper_id_scan; static ID ripper_id_scan;
@ -51,7 +51,7 @@ static ID ripper_id_comment;
static ID ripper_id_embdoc_beg; static ID ripper_id_embdoc_beg;
static ID ripper_id_embdoc; static ID ripper_id_embdoc;
static ID ripper_id_embdoc_end; static ID ripper_id_embdoc_end;
static ID ripper_id_lwsp; static ID ripper_id_sp;
static ID ripper_id_heredoc_beg; static ID ripper_id_heredoc_beg;
static ID ripper_id_heredoc_content; static ID ripper_id_heredoc_content;
static ID ripper_id_heredoc_end; static ID ripper_id_heredoc_end;
@ -102,7 +102,7 @@ ripper_init_eventids2()
ripper_id_embdoc_beg = rb_intern("on__embdoc_beg"); ripper_id_embdoc_beg = rb_intern("on__embdoc_beg");
ripper_id_embdoc = rb_intern("on__embdoc"); ripper_id_embdoc = rb_intern("on__embdoc");
ripper_id_embdoc_end = rb_intern("on__embdoc_end"); ripper_id_embdoc_end = rb_intern("on__embdoc_end");
ripper_id_lwsp = rb_intern("on__sp"); ripper_id_sp = rb_intern("on__sp");
ripper_id_heredoc_beg = rb_intern("on__heredoc_beg"); ripper_id_heredoc_beg = rb_intern("on__heredoc_beg");
ripper_id_heredoc_content = rb_intern("on__heredoc_content"); ripper_id_heredoc_content = rb_intern("on__heredoc_content");
ripper_id_heredoc_end = rb_intern("on__heredoc_end"); ripper_id_heredoc_end = rb_intern("on__heredoc_end");
@ -241,13 +241,14 @@ static struct token_assoc {
{tUPLUS, &ripper_id_op}, {tUPLUS, &ripper_id_op},
{tWORDS_BEG, &ripper_id_words_beg}, {tWORDS_BEG, &ripper_id_words_beg},
{tXSTRING_BEG, &ripper_id_backtick}, {tXSTRING_BEG, &ripper_id_backtick},
/* ripper specific tokens */
/* ripper specific tokens */
{tIGNORED_NL, &ripper_id_ignored_nl}, {tIGNORED_NL, &ripper_id_ignored_nl},
{tCOMMENT, &ripper_id_comment}, {tCOMMENT, &ripper_id_comment},
{tEMBDOC_BEG, &ripper_id_embdoc_beg}, {tEMBDOC_BEG, &ripper_id_embdoc_beg},
{tEMBDOC, &ripper_id_embdoc}, {tEMBDOC, &ripper_id_embdoc},
{tEMBDOC_END, &ripper_id_embdoc_end}, {tEMBDOC_END, &ripper_id_embdoc_end},
{tLWSP, &ripper_id_lwsp}, {tSP, &ripper_id_sp},
{tHEREDOC_BEG, &ripper_id_heredoc_beg}, {tHEREDOC_BEG, &ripper_id_heredoc_beg},
{tHEREDOC_CONTENT, &ripper_id_heredoc_content}, {tHEREDOC_CONTENT, &ripper_id_heredoc_content},
{tHEREDOC_END, &ripper_id_heredoc_end}, {tHEREDOC_END, &ripper_id_heredoc_end},

View File

@ -9,15 +9,17 @@ def main
exit 1 exit 1
end end
$objs = %w(ripper.o) $objs = %w(ripper.o)
$cleanfiles.concat %w(ripper.y ripper.c ripper.output ids1 ids2) $cleanfiles.concat %w(ripper.y ripper.c ripper.E ripper.output eventids1.c ids1 ids2)
$CPPFLAGS += ' -DRIPPER' $CPPFLAGS += ' -DRIPPER'
$CPPFLAGS += ' -DRIPPER_DEBUG' if $debug $CPPFLAGS += ' -DRIPPER_DEBUG' if $debug
create_makefile 'ripper' create_makefile 'ripper'
end end
def have_command(cmd) def have_command(cmd)
ENV['PATH'].split(File::PATH_SEPARATOR).any? {|path| checking_for(cmd) {
File.executable?("#{path}/#{cmd}#{Config::CONFIG['EXEEXT']}") ENV['PATH'].split(File::PATH_SEPARATOR).any? {|path|
File.executable?("#{path}/#{cmd}#{Config::CONFIG['EXEEXT']}")
}
} }
end end

View File

@ -28,6 +28,7 @@ class Ripper
end end
PARSER_EVENTS = [ PARSER_EVENTS = [
:BEGIN, :BEGIN,
:END, :END,
:alias, :alias,
@ -151,126 +152,51 @@ class Ripper
] ]
SCANNER_EVENTS = [ SCANNER_EVENTS = [
:BEGIN,
:END, :CHAR,
:alias, :__end__,
:alias_error, :backref,
:aref, :backtick,
:aref_field, :comma,
:arg_ambiguous, :comment,
:arg_paren, :const,
:arglist_add, :cvar,
:arglist_add_block, :embdoc,
:arglist_add_star, :embdoc_beg,
:arglist_new, :embdoc_end,
:arglist_prepend, :embexpr_beg,
:array, :embexpr_end,
:assign, :embvar,
:assign_error, :float,
:assoc_new, :gvar,
:assoclist_from_args, :heredoc_beg,
:bare_assoc_hash, :heredoc_content,
:begin, :heredoc_end,
:binary, :ident,
:blockvar_add_block, :ignored_nl,
:blockvar_add_star, :int,
:blockvar_new, :ivar,
:bodystmt, :kw,
:brace_block, :lbrace,
:break, :lbracket,
:call, :lparen,
:case, :nl,
:class, :op,
:class_name_error, :period,
:command, :qwords_beg,
:command_call, :rbrace,
:const_ref, :rbracket,
:constpath_field, :regexp_beg,
:constpath_ref, :regexp_end,
:def, :rparen,
:defined, :semicolon,
:defs, :sp,
:do_block, :symbeg,
:dot2, :tstring_beg,
:dot3, :tstring_content,
:dyna_symbol, :tstring_end,
:else, :words_beg,
:elsif, :words_sep
: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
] ]
LEXER_EVENTS = SCANNER_EVENTS LEXER_EVENTS = SCANNER_EVENTS
@ -875,10 +801,6 @@ class Ripper
token token
end end
def on__lwsp(token)
token
end
def on__nl(token) def on__nl(token)
token token
end end
@ -919,6 +841,10 @@ class Ripper
token token
end end
def on__sp(token)
token
end
def on__symbeg(token) def on__symbeg(token)
token token
end end

View File

@ -1,8 +1,6 @@
# # $Id$
# generate-eventids1.rb
#
ids = ARGF.map {|s| s.strip } ids = File.readlines(ARGV[0]).map {|s| s.split[0] }
ids.each do |id| ids.each do |id|
puts "static ID ripper_id_#{id};" puts "static ID ripper_id_#{id};"

View File

@ -1,14 +1,13 @@
# # $Id$
# generate-ripper_rb.rb
# Creates ripper.rb, filling in default event handlers, given a basic
# template, the list of parser events (ids1), and a list of lexer
# events (ids2).
#
def main def main
template, ids1, ids2 = *ARGV template, ids1, ids2 = *ARGV
File.foreach(template) do |line| File.foreach(template) do |line|
case line case line
when /\A\#include ids1/
print_items read_ids(ids1)
when /\A\#include ids2/
print_items read_ids(ids2)
when /\A\#include handlers1/ when /\A\#include handlers1/
File.foreach(ids1) do |line| File.foreach(ids1) do |line|
id, arity = line.split id, arity = line.split
@ -35,9 +34,20 @@ def main
end end
end end
# Generate generic arg list depending on arity (n) def print_items(ids)
# n:: [Integer] arity of method comma = "\n"
def argdecl( n ) ids.each do |id|
print comma; comma = ",\n"
print " #{id.intern.inspect}"
end
puts
end
def read_ids(path)
File.readlines(path).map {|line| line.split[0] }
end
def argdecl(n)
%w(a b c d e f g h i j k l m)[0, n].join(', ') %w(a b c d e f g h i j k l m)[0, n].join(', ')
end end

View File

@ -4226,8 +4226,8 @@ ripper_dispatch_space(parser)
long len = parser->token_head - parser->old_lex_p; long len = parser->token_head - parser->old_lex_p;
VALUE str = rb_str_new(parser->old_lex_p, len); VALUE str = rb_str_new(parser->old_lex_p, len);
ripper_dispatch2(parser, ripper_id_scan, ID2SYM(ripper_id_lwsp), rb_str_dup(str)); ripper_dispatch2(parser, ripper_id_scan, ID2SYM(ripper_id_sp), rb_str_dup(str));
ripper_dispatch1(parser, ripper_id_lwsp, str); ripper_dispatch1(parser, ripper_id_sp, str);
parser->current_position += len; parser->current_position += len;
parser->current_column += len; parser->current_column += len;
} }