summaryrefslogtreecommitdiff
path: root/ext/ripper
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-14 11:27:36 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-14 11:27:36 +0000
commitd3bce8cb5a9c44eb4413aca819bfa4dfeceda221 (patch)
treef8aa91fcc45b24d858c07096b6996309185209fe /ext/ripper
parent26a828a605a6738db2388b6487c6ddef4a48088a (diff)
* 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
Diffstat (limited to 'ext/ripper')
-rw-r--r--ext/ripper/.cvsignore4
-rw-r--r--ext/ripper/MANIFEST1
-rw-r--r--ext/ripper/Makefile.dev18
-rw-r--r--ext/ripper/depend36
-rw-r--r--ext/ripper/eventids2.c29
-rw-r--r--ext/ripper/extconf.rb8
-rw-r--r--ext/ripper/lib/ripper.rb174
-rwxr-xr-xext/ripper/tools/generate-eventids1.rb6
-rwxr-xr-xext/ripper/tools/generate-ripper_rb.rb28
9 files changed, 121 insertions, 183 deletions
diff --git a/ext/ripper/.cvsignore b/ext/ripper/.cvsignore
new file mode 100644
index 0000000000..184a72c8ce
--- /dev/null
+++ b/ext/ripper/.cvsignore
@@ -0,0 +1,4 @@
+Makefile
+eventids1.c
+ripper.c
+ripper.y
diff --git a/ext/ripper/MANIFEST b/ext/ripper/MANIFEST
index fe1e25e620..fd9caadc31 100644
--- a/ext/ripper/MANIFEST
+++ b/ext/ripper/MANIFEST
@@ -1,4 +1,5 @@
MANIFEST
+Makefile.dev
README
depend
eventids2.c
diff --git a/ext/ripper/Makefile.dev b/ext/ripper/Makefile.dev
new file mode 100644
index 0000000000..59615e56d6
--- /dev/null
+++ b/ext/ripper/Makefile.dev
@@ -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 > $@
diff --git a/ext/ripper/depend b/ext/ripper/depend
index eef9ad78fc..6d34ef2fb6 100644
--- a/ext/ripper/depend
+++ b/ext/ripper/depend
@@ -1,6 +1,4 @@
-# Do not remove "./"; nmake requires this.
-ripper.o: ./ripper.c lex.c eventids1.c eventids2.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -c ./ripper.c
+ripper.o: lex.c eventids1.c eventids2.c
ripper.c: 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
$(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
- $(RUBY) $(srcdir)/tools/list-parse-event-ids.rb $(hdrdir)/parse.y | $(RUBY) $(srcdir)/tools/generate-eventids1.rb > $@
+eventids1.c: $(hdrdir)/parse.y $(srcdir)/tools/generate-eventids1.rb ids1
+ $(RUBY) $(srcdir)/tools/generate-eventids1.rb ids1 > $@
-lex.c:
- cp $(hdrdir)/lex.c . || cp $(srcdir)/lex.c .
+ids1: $(srcdir)/tools/list-parse-event-ids.rb $(hdrdir)/parse.y
+ $(RUBY) $(srcdir)/tools/list-parse-event-ids.rb -a $(hdrdir)/parse.y > $@
-#
-# Entries for ripper developpers (no srcdir/objdir support)
-#
-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 > $@
+ids2: $(srcdir)/tools/list-scan-event-ids.rb $(srcdir)/eventids2.c
+ $(RUBY) $(srcdir)/tools/list-scan-event-ids.rb -a $(srcdir)/eventids2.c > $@
diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c
index 28519eb8e6..cab4b45657 100644
--- a/ext/ripper/eventids2.c
+++ b/ext/ripper/eventids2.c
@@ -1,14 +1,14 @@
-#define tIGNORED_NL (tLAST_TOKEN + 1)
-#define tCOMMENT (tLAST_TOKEN + 2)
-#define tEMBDOC_BEG (tLAST_TOKEN + 3)
-#define tEMBDOC (tLAST_TOKEN + 4)
-#define tEMBDOC_END (tLAST_TOKEN + 5)
-#define tLWSP (tLAST_TOKEN + 6)
-#define tHEREDOC_BEG (tLAST_TOKEN + 7)
+#define tIGNORED_NL (tLAST_TOKEN + 1)
+#define tCOMMENT (tLAST_TOKEN + 2)
+#define tEMBDOC_BEG (tLAST_TOKEN + 3)
+#define tEMBDOC (tLAST_TOKEN + 4)
+#define tEMBDOC_END (tLAST_TOKEN + 5)
+#define tSP (tLAST_TOKEN + 6)
+#define tHEREDOC_BEG (tLAST_TOKEN + 7)
#define tHEREDOC_CONTENT (tLAST_TOKEN + 8)
-#define tHEREDOC_END (tLAST_TOKEN + 9)
-#define k__END__ (tLAST_TOKEN + 10)
-#define tCHAR (tLAST_TOKEN + 11)
+#define tHEREDOC_END (tLAST_TOKEN + 9)
+#define k__END__ (tLAST_TOKEN + 10)
+#define tCHAR (tLAST_TOKEN + 11)
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;
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_content;
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 = rb_intern("on__embdoc");
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_content = rb_intern("on__heredoc_content");
ripper_id_heredoc_end = rb_intern("on__heredoc_end");
@@ -241,13 +241,14 @@ static struct token_assoc {
{tUPLUS, &ripper_id_op},
{tWORDS_BEG, &ripper_id_words_beg},
{tXSTRING_BEG, &ripper_id_backtick},
-/* ripper specific tokens */
+
+ /* ripper specific tokens */
{tIGNORED_NL, &ripper_id_ignored_nl},
{tCOMMENT, &ripper_id_comment},
{tEMBDOC_BEG, &ripper_id_embdoc_beg},
{tEMBDOC, &ripper_id_embdoc},
{tEMBDOC_END, &ripper_id_embdoc_end},
- {tLWSP, &ripper_id_lwsp},
+ {tSP, &ripper_id_sp},
{tHEREDOC_BEG, &ripper_id_heredoc_beg},
{tHEREDOC_CONTENT, &ripper_id_heredoc_content},
{tHEREDOC_END, &ripper_id_heredoc_end},
diff --git a/ext/ripper/extconf.rb b/ext/ripper/extconf.rb
index 536e23d3ad..f1716b84c0 100644
--- a/ext/ripper/extconf.rb
+++ b/ext/ripper/extconf.rb
@@ -9,15 +9,17 @@ def main
exit 1
end
$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_DEBUG' if $debug
create_makefile 'ripper'
end
def have_command(cmd)
- ENV['PATH'].split(File::PATH_SEPARATOR).any? {|path|
- File.executable?("#{path}/#{cmd}#{Config::CONFIG['EXEEXT']}")
+ checking_for(cmd) {
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? {|path|
+ File.executable?("#{path}/#{cmd}#{Config::CONFIG['EXEEXT']}")
+ }
}
end
diff --git a/ext/ripper/lib/ripper.rb b/ext/ripper/lib/ripper.rb
index b34147ee2a..15a05aaddc 100644
--- a/ext/ripper/lib/ripper.rb
+++ b/ext/ripper/lib/ripper.rb
@@ -28,6 +28,7 @@ class Ripper
end
PARSER_EVENTS = [
+
:BEGIN,
:END,
:alias,
@@ -151,126 +152,51 @@ class Ripper
]
SCANNER_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
+
+ :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
@@ -875,10 +801,6 @@ class Ripper
token
end
- def on__lwsp(token)
- token
- end
-
def on__nl(token)
token
end
@@ -919,6 +841,10 @@ class Ripper
token
end
+ def on__sp(token)
+ token
+ end
+
def on__symbeg(token)
token
end
diff --git a/ext/ripper/tools/generate-eventids1.rb b/ext/ripper/tools/generate-eventids1.rb
index de0e27b89c..3d9a57e034 100755
--- a/ext/ripper/tools/generate-eventids1.rb
+++ b/ext/ripper/tools/generate-eventids1.rb
@@ -1,8 +1,6 @@
-#
-# generate-eventids1.rb
-#
+# $Id$
-ids = ARGF.map {|s| s.strip }
+ids = File.readlines(ARGV[0]).map {|s| s.split[0] }
ids.each do |id|
puts "static ID ripper_id_#{id};"
diff --git a/ext/ripper/tools/generate-ripper_rb.rb b/ext/ripper/tools/generate-ripper_rb.rb
index c6b2aea13f..9d33bddc4c 100755
--- a/ext/ripper/tools/generate-ripper_rb.rb
+++ b/ext/ripper/tools/generate-ripper_rb.rb
@@ -1,14 +1,13 @@
-#
-# 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).
-#
+# $Id$
def main
template, ids1, ids2 = *ARGV
File.foreach(template) do |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/
File.foreach(ids1) do |line|
id, arity = line.split
@@ -35,9 +34,20 @@ def main
end
end
-# Generate generic arg list depending on arity (n)
-# n:: [Integer] arity of method
-def argdecl( n )
+def print_items(ids)
+ comma = "\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(', ')
end