diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-23 10:49:11 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-23 10:49:11 +0000 |
commit | 0c9d76889af8e00a946dbe8de33568fc87bdd983 (patch) | |
tree | 6b11b788338aa66e7357d013feb96082edb0a0cb | |
parent | bf189b88d34f23b1f4e7709fd6c9b947cd5073e7 (diff) | |
download | ruby-0c9d76889af8e00a946dbe8de33568fc87bdd983.tar.gz |
* ext/ripper/Makefile.dev: removed.
* ext/ripper/ripper.rb.in: moved to lib/ripper/core.rb.in.
* ext/ripper/lib/ripper/core.rb: new file.
* ext/ripper/lib/ripper/core.rb.in: new file.
* ext/ripper/tools/generate-ripper_rb.rb: change comment.
* test/ripper/*.rb: on_scan removed.
* test/ripper/*.rb: event name changed: on__ -> on_.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | ext/ripper/MANIFEST | 4 | ||||
-rw-r--r-- | ext/ripper/Makefile.dev | 18 | ||||
-rw-r--r-- | ext/ripper/depend | 19 | ||||
-rw-r--r-- | ext/ripper/lib/ripper.rb | 878 | ||||
-rw-r--r-- | ext/ripper/lib/ripper/core.rb | 883 | ||||
-rw-r--r-- | ext/ripper/lib/ripper/core.rb.in (renamed from ext/ripper/ripper.rb.in) | 13 | ||||
-rw-r--r-- | ext/ripper/lib/ripper/filter.rb | 19 | ||||
-rw-r--r-- | ext/ripper/lib/ripper/tokenizer.rb | 2 | ||||
-rwxr-xr-x | ext/ripper/tools/generate-ripper_rb.rb | 3 | ||||
-rw-r--r-- | test/ripper/dummyparser.rb | 253 | ||||
-rw-r--r-- | test/ripper/test_parser_events.rb | 3 | ||||
-rw-r--r-- | test/ripper/test_scanner_events.rb | 606 |
13 files changed, 1365 insertions, 1352 deletions
@@ -1,3 +1,19 @@ +Thu Sep 23 19:48:14 2004 Minero Aoki <aamine@loveruby.net> + + * ext/ripper/Makefile.dev: removed. + + * ext/ripper/ripper.rb.in: moved to lib/ripper/core.rb.in. + + * ext/ripper/lib/ripper/core.rb: new file. + + * ext/ripper/lib/ripper/core.rb.in: new file. + + * ext/ripper/tools/generate-ripper_rb.rb: change comment. + + * test/ripper/*.rb: on__scan event removed. + + * test/ripper/*.rb: event name is changed: on__XXX -> on_XXX. + Thu Sep 23 09:29:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org> * hash.c (rb_hash_rehash): replace st_foreach() by its deep diff --git a/ext/ripper/MANIFEST b/ext/ripper/MANIFEST index 25a907b3df..9ca4fa82ca 100644 --- a/ext/ripper/MANIFEST +++ b/ext/ripper/MANIFEST @@ -1,11 +1,11 @@ MANIFEST -Makefile.dev README depend eventids2.c extconf.rb -ripper.rb.in lib/ripper.rb +lib/ripper/core.rb +lib/ripper/core.rb.in lib/ripper/filter.rb lib/ripper/tokenizer.rb test/check-event-arity.rb diff --git a/ext/ripper/Makefile.dev b/ext/ripper/Makefile.dev deleted file mode 100644 index ab16a7a74b..0000000000 --- a/ext/ripper/Makefile.dev +++ /dev/null @@ -1,18 +0,0 @@ -# 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 $(srcdir)/tools/strip.rb > $@ diff --git a/ext/ripper/depend b/ext/ripper/depend index b0ab953a94..3cfc4ab404 100644 --- a/ext/ripper/depend +++ b/ext/ripper/depend @@ -14,3 +14,22 @@ ids1: $(srcdir)/tools/list-parse-event-ids.rb $(hdrdir)/parse.y ids2: $(srcdir)/tools/list-scan-event-ids.rb $(srcdir)/eventids2.c $(RUBY) $(srcdir)/tools/list-scan-event-ids.rb -a $(srcdir)/eventids2.c > $@ + +rb: $(srcdir)/lib/ripper/core.rb +$(srcdir)/lib/ripper/core.rb: $(srcdir)/lib/ripper/core.rb.in ids1 ids2 $(srcdir)/tools/generate-ripper_rb.rb + $(RUBY) $(srcdir)/tools/generate-ripper_rb.rb $(srcdir)/lib/ripper/core.rb.in ids1 ids2 > $@ + +# +# Entries for only ripper developpers: DO NOT USE +# + +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) $(srcdir)/tools/strip.rb > $@ diff --git a/ext/ripper/lib/ripper.rb b/ext/ripper/lib/ripper.rb index cb4924d0cd..38a5a2bd19 100644 --- a/ext/ripper/lib/ripper.rb +++ b/ext/ripper/lib/ripper.rb @@ -1,877 +1,3 @@ -# -# This file is automatically generated from ripper.rb.in and parse.y. -# DO NOT MODIFY!!!!!! -# -# -# ripper.rb -# -# Copyright (C) 2003,2004 Minero Aoki -# - -require 'ripper.so' - -class Ripper - # 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). - 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_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. - EVENTS = PARSER_EVENTS + SCANNER_EVENTS - - ### ### - ### Event Handlers ### - ### ### - - private - - def warn(fmt, *args) - end - - def warning(fmt, *args) - end - - def compile_error(msg) - end - - # - # Parser Events - # - - def on_BEGIN(a) - a - end - - def on_END(a) - a - end - - def on_alias(a, b) - a - end - - def on_alias_error(a) - a - end - - def on_aref(a, b) - a - end - - def on_aref_field(a, b) - a - end - - def on_arg_ambiguous - nil - end - - def on_arg_paren(a) - a - end - - def on_arglist_add(a, b) - a - end - - def on_arglist_add_block(a, b) - a - end - - def on_arglist_add_star(a, b) - a - end - - def on_arglist_new - nil - end - - def on_arglist_prepend(a, b) - a - end - - def on_array(a) - a - end - - def on_assign(a, b) - a - end - - def on_assign_error(a) - a - end - - def on_assoc_new(a, b) - a - end - - def on_assoclist_from_args(a) - a - end - - def on_bare_assoc_hash(a) - a - end - - def on_begin(a) - a - end - - def on_binary(a, b, c) - a - end - - def on_blockvar_add_block(a, b) - a - end - - def on_blockvar_add_star(a, b) - a - end - - def on_blockvar_new(a) - a - end - - def on_bodystmt(a, b, c, d) - a - end - - def on_brace_block(a, b) - a - end - - def on_break(a) - a - end - - def on_call(a, b, c) - a - end - - def on_case(a, b) - a - end - - def on_class(a, b, c) - a - end - - def on_class_name_error(a) - a - end - - def on_command(a, b) - a - end - - def on_command_call(a, b, c, d) - a - end - - def on_const_ref(a) - a - end - - def on_constpath_field(a, b) - a - end - - def on_constpath_ref(a, b) - a - end - - def on_def(a, b, c) - a - end - - def on_defined(a) - a - end - - def on_defs(a, b, c, d, e) - a - end - - def on_do_block(a, b) - a - end - - def on_dot2(a, b) - a - end - - def on_dot3(a, b) - a - end - - def on_dyna_symbol(a) - a - end - - def on_else(a) - a - end - - def on_elsif(a, b, c) - a - end - - def on_ensure(a) - a - end - - def on_fcall(a) - a - end - - def on_field(a, b, c) - a - end - - def on_for(a, b, c) - a - end - - def on_hash(a) - a - end - - def on_if(a, b, c) - a - end - - def on_if_mod(a, b) - a - end - - def on_ifop(a, b, c) - a - end - - def on_iter_block(a, b) - a - end - - def on_massign(a, b) - a - end - - def on_method_add_arg(a, b) - a - end - - def on_mlhs_add(a, b) - a - end - - def on_mlhs_add_star(a, b) - a - end - - def on_mlhs_new - nil - end - - def on_mlhs_paren(a) - a - end - - def on_module(a, b) - a - end - - def on_mrhs_add(a, b) - a - end - - def on_mrhs_add_star(a, b) - a - end - - def on_mrhs_new - nil - end - - def on_mrhs_new_from_arglist(a) - a - end - - def on_next(a) - a - end - - def on_opassign(a, b, c) - a - end - - def on_param_error(a) - a - end - - def on_params(a, b, c, d) - a - end - - def on_paren(a) - a - end - - def on_parse_error(a) - a - end - - def on_program(a) - a - end - - def on_qwords_add(a, b) - a - end - - def on_qwords_new - nil - end - - def on_redo - nil - end - - def on_regexp_literal(a) - a - end - - def on_rescue(a, b, c, d) - a - end - - def on_rescue_mod(a, b) - a - end - - def on_restparam(a) - a - end - - def on_retry - nil - end - - def on_return(a) - a - end - - def on_return0 - nil - end - - def on_sclass(a, b) - a - end - - def on_space(a) - a - end - - def on_stmts_add(a, b) - a - end - - def on_stmts_new - nil - end - - def on_string_add(a, b) - a - end - - def on_string_concat(a, b) - a - end - - def on_string_content - nil - end - - def on_string_dvar(a) - a - end - - def on_string_embexpr(a) - a - end - - def on_string_literal(a) - a - end - - def on_super(a) - a - end - - def on_symbol(a) - a - end - - def on_symbol_literal(a) - a - end - - def on_topconst_field(a) - a - end - - def on_topconst_ref(a) - a - end - - def on_unary(a, b) - a - end - - def on_undef(a) - a - end - - def on_unless(a, b, c) - a - end - - def on_unless_mod(a, b) - a - end - - def on_until(a, b) - a - end - - def on_until_mod(a, b) - a - end - - def on_var_alias(a, b) - a - end - - def on_var_field(a) - a - end - - def on_var_ref(a) - a - end - - def on_void_stmt - nil - end - - def on_when(a, b, c) - a - end - - def on_while(a, b) - a - end - - def on_while_mod(a, b) - a - end - - def on_word_add(a, b) - a - end - - def on_word_new - nil - end - - def on_words_add(a, b) - a - end - - def on_words_new - nil - end - - def on_xstring_add(a, b) - a - end - - def on_xstring_literal(a) - a - end - - def on_xstring_new - nil - end - - def on_yield(a) - a - end - - def on_yield0 - nil - end - - def on_zsuper - nil - end - - # - # Lexer Events - # - - def on_CHAR(token) - token - end - - def on___end__(token) - token - end - - def on_backref(token) - token - end - - def on_backtick(token) - token - end - - def on_comma(token) - token - end - - def on_comment(token) - token - end - - def on_const(token) - token - end - - def on_cvar(token) - token - end - - def on_embdoc(token) - token - end - - def on_embdoc_beg(token) - token - end - - def on_embdoc_end(token) - token - end - - def on_embexpr_beg(token) - token - end - - def on_embexpr_end(token) - token - end - - def on_embvar(token) - token - end - - def on_float(token) - token - end - - def on_gvar(token) - token - end - - def on_heredoc_beg(token) - token - end - - def on_heredoc_end(token) - token - end - - def on_ident(token) - token - end - - def on_ignored_nl(token) - token - end - - def on_int(token) - token - end - - def on_ivar(token) - token - end - - def on_kw(token) - token - end - - def on_lbrace(token) - token - end - - def on_lbracket(token) - token - end - - def on_lparen(token) - token - end - - def on_nl(token) - token - end - - def on_op(token) - token - end - - def on_period(token) - token - end - - def on_qwords_beg(token) - token - end - - def on_rbrace(token) - token - end - - def on_rbracket(token) - token - end - - def on_regexp_beg(token) - token - end - - def on_regexp_end(token) - token - end - - def on_rparen(token) - token - end - - def on_semicolon(token) - token - end - - def on_sp(token) - token - end - - def on_symbeg(token) - token - end - - def on_tstring_beg(token) - token - end - - def on_tstring_content(token) - token - end - - def on_tstring_end(token) - token - end - - def on_words_beg(token) - token - end - - def on_words_sep(token) - token - end -end - +require 'ripper/core' require 'ripper/tokenizer' +require 'ripper/filter' diff --git a/ext/ripper/lib/ripper/core.rb b/ext/ripper/lib/ripper/core.rb new file mode 100644 index 0000000000..e936783698 --- /dev/null +++ b/ext/ripper/lib/ripper/core.rb @@ -0,0 +1,883 @@ +# This file is automatically generated from core.rb.in and parse.y. +# DO NOT MODIFY!!!!!! + +# +# ripper/core.rb +# +# Copyright (C) 2003,2004 Minero Aoki +# +# This program is free software. +# You can distribute and/or modify this program under the Ruby License. +# For details of Ruby License, see ruby/COPYING. +# + +require 'ripper.so' + +class Ripper + # 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). + 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_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. + EVENTS = PARSER_EVENTS + SCANNER_EVENTS + + ### ### + ### Event Handlers ### + ### ### + + private + + # This method is called when weak warning is produced by the parser. + # _fmt_ and _args_ is printf style. + def warn(fmt, *args) + end + + # This method is called when strong warning is produced by the parser. + # _fmt_ and _args_ is printf style. + def warning(fmt, *args) + end + + # This method is called when the parser found syntax error. + def compile_error(msg) + end + + # + # Parser Events + # + + def on_BEGIN(a) + a + end + + def on_END(a) + a + end + + def on_alias(a, b) + a + end + + def on_alias_error(a) + a + end + + def on_aref(a, b) + a + end + + def on_aref_field(a, b) + a + end + + def on_arg_ambiguous + nil + end + + def on_arg_paren(a) + a + end + + def on_arglist_add(a, b) + a + end + + def on_arglist_add_block(a, b) + a + end + + def on_arglist_add_star(a, b) + a + end + + def on_arglist_new + nil + end + + def on_arglist_prepend(a, b) + a + end + + def on_array(a) + a + end + + def on_assign(a, b) + a + end + + def on_assign_error(a) + a + end + + def on_assoc_new(a, b) + a + end + + def on_assoclist_from_args(a) + a + end + + def on_bare_assoc_hash(a) + a + end + + def on_begin(a) + a + end + + def on_binary(a, b, c) + a + end + + def on_blockvar_add_block(a, b) + a + end + + def on_blockvar_add_star(a, b) + a + end + + def on_blockvar_new(a) + a + end + + def on_bodystmt(a, b, c, d) + a + end + + def on_brace_block(a, b) + a + end + + def on_break(a) + a + end + + def on_call(a, b, c) + a + end + + def on_case(a, b) + a + end + + def on_class(a, b, c) + a + end + + def on_class_name_error(a) + a + end + + def on_command(a, b) + a + end + + def on_command_call(a, b, c, d) + a + end + + def on_const_ref(a) + a + end + + def on_constpath_field(a, b) + a + end + + def on_constpath_ref(a, b) + a + end + + def on_def(a, b, c) + a + end + + def on_defined(a) + a + end + + def on_defs(a, b, c, d, e) + a + end + + def on_do_block(a, b) + a + end + + def on_dot2(a, b) + a + end + + def on_dot3(a, b) + a + end + + def on_dyna_symbol(a) + a + end + + def on_else(a) + a + end + + def on_elsif(a, b, c) + a + end + + def on_ensure(a) + a + end + + def on_fcall(a) + a + end + + def on_field(a, b, c) + a + end + + def on_for(a, b, c) + a + end + + def on_hash(a) + a + end + + def on_if(a, b, c) + a + end + + def on_if_mod(a, b) + a + end + + def on_ifop(a, b, c) + a + end + + def on_iter_block(a, b) + a + end + + def on_massign(a, b) + a + end + + def on_method_add_arg(a, b) + a + end + + def on_mlhs_add(a, b) + a + end + + def on_mlhs_add_star(a, b) + a + end + + def on_mlhs_new + nil + end + + def on_mlhs_paren(a) + a + end + + def on_module(a, b) + a + end + + def on_mrhs_add(a, b) + a + end + + def on_mrhs_add_star(a, b) + a + end + + def on_mrhs_new + nil + end + + def on_mrhs_new_from_arglist(a) + a + end + + def on_next(a) + a + end + + def on_opassign(a, b, c) + a + end + + def on_param_error(a) + a + end + + def on_params(a, b, c, d) + a + end + + def on_paren(a) + a + end + + def on_parse_error(a) + a + end + + def on_program(a) + a + end + + def on_qwords_add(a, b) + a + end + + def on_qwords_new + nil + end + + def on_redo + nil + end + + def on_regexp_literal(a) + a + end + + def on_rescue(a, b, c, d) + a + end + + def on_rescue_mod(a, b) + a + end + + def on_restparam(a) + a + end + + def on_retry + nil + end + + def on_return(a) + a + end + + def on_return0 + nil + end + + def on_sclass(a, b) + a + end + + def on_space(a) + a + end + + def on_stmts_add(a, b) + a + end + + def on_stmts_new + nil + end + + def on_string_add(a, b) + a + end + + def on_string_concat(a, b) + a + end + + def on_string_content + nil + end + + def on_string_dvar(a) + a + end + + def on_string_embexpr(a) + a + end + + def on_string_literal(a) + a + end + + def on_super(a) + a + end + + def on_symbol(a) + a + end + + def on_symbol_literal(a) + a + end + + def on_topconst_field(a) + a + end + + def on_topconst_ref(a) + a + end + + def on_unary(a, b) + a + end + + def on_undef(a) + a + end + + def on_unless(a, b, c) + a + end + + def on_unless_mod(a, b) + a + end + + def on_until(a, b) + a + end + + def on_until_mod(a, b) + a + end + + def on_var_alias(a, b) + a + end + + def on_var_field(a) + a + end + + def on_var_ref(a) + a + end + + def on_void_stmt + nil + end + + def on_when(a, b, c) + a + end + + def on_while(a, b) + a + end + + def on_while_mod(a, b) + a + end + + def on_word_add(a, b) + a + end + + def on_word_new + nil + end + + def on_words_add(a, b) + a + end + + def on_words_new + nil + end + + def on_xstring_add(a, b) + a + end + + def on_xstring_literal(a) + a + end + + def on_xstring_new + nil + end + + def on_yield(a) + a + end + + def on_yield0 + nil + end + + def on_zsuper + nil + end + + # + # Lexer Events + # + + def on_CHAR(token) + token + end + + def on___end__(token) + token + end + + def on_backref(token) + token + end + + def on_backtick(token) + token + end + + def on_comma(token) + token + end + + def on_comment(token) + token + end + + def on_const(token) + token + end + + def on_cvar(token) + token + end + + def on_embdoc(token) + token + end + + def on_embdoc_beg(token) + token + end + + def on_embdoc_end(token) + token + end + + def on_embexpr_beg(token) + token + end + + def on_embexpr_end(token) + token + end + + def on_embvar(token) + token + end + + def on_float(token) + token + end + + def on_gvar(token) + token + end + + def on_heredoc_beg(token) + token + end + + def on_heredoc_end(token) + token + end + + def on_ident(token) + token + end + + def on_ignored_nl(token) + token + end + + def on_int(token) + token + end + + def on_ivar(token) + token + end + + def on_kw(token) + token + end + + def on_lbrace(token) + token + end + + def on_lbracket(token) + token + end + + def on_lparen(token) + token + end + + def on_nl(token) + token + end + + def on_op(token) + token + end + + def on_period(token) + token + end + + def on_qwords_beg(token) + token + end + + def on_rbrace(token) + token + end + + def on_rbracket(token) + token + end + + def on_regexp_beg(token) + token + end + + def on_regexp_end(token) + token + end + + def on_rparen(token) + token + end + + def on_semicolon(token) + token + end + + def on_sp(token) + token + end + + def on_symbeg(token) + token + end + + def on_tstring_beg(token) + token + end + + def on_tstring_content(token) + token + end + + def on_tstring_end(token) + token + end + + def on_words_beg(token) + token + end + + def on_words_sep(token) + token + end +end diff --git a/ext/ripper/ripper.rb.in b/ext/ripper/lib/ripper/core.rb.in index 295dd1e353..7e6d51ab8f 100644 --- a/ext/ripper/ripper.rb.in +++ b/ext/ripper/lib/ripper/core.rb.in @@ -1,8 +1,12 @@ # -# ripper.rb +# ripper/core.rb # # Copyright (C) 2003,2004 Minero Aoki # +# This program is free software. +# You can distribute and/or modify this program under the Ruby License. +# For details of Ruby License, see ruby/COPYING. +# require 'ripper.so' @@ -39,12 +43,17 @@ class Ripper private + # This method is called when weak warning is produced by the parser. + # _fmt_ and _args_ is printf style. def warn(fmt, *args) end + # This method is called when strong warning is produced by the parser. + # _fmt_ and _args_ is printf style. def warning(fmt, *args) end + # This method is called when the parser found syntax error. def compile_error(msg) end @@ -58,5 +67,3 @@ class Ripper # #include handlers2 end - -require 'ripper/tokenizer' diff --git a/ext/ripper/lib/ripper/filter.rb b/ext/ripper/lib/ripper/filter.rb index 399c4c64bc..d1c7c4a45e 100644 --- a/ext/ripper/lib/ripper/filter.rb +++ b/ext/ripper/lib/ripper/filter.rb @@ -8,10 +8,12 @@ # For details of Ruby License, see ruby/COPYING. # -require 'ripper' +require 'ripper/core' class Ripper + # This class handles only scanner events, + # and they are dispatched in the `right' order (same with input). class Filter def initialize(src, filename = '-', lineno = 1) @@ -20,18 +22,27 @@ class Ripper @__col = nil end + # The file name of the input. def filename @__parser.filename end + # The line number of the current token. + # This value starts from 1. + # This method is valid only in event handlers. def lineno @__line end + # The column number of the current token. + # This value starts from 0. + # This method is valid only in event handlers. def column @__col end + # Starts parsing. _init_ is a data accumulator. + # It is passed to the next event handler (as of Enumerable#inject). def parse(init) data = init @__parser.parse.each do |pos, event, tok| @@ -46,7 +57,11 @@ class Ripper private - def on_default(event, tok, data) + # This method is called when some event handler have not defined. + # _event_ is :on_XXX, _token_ is scanned token, _data_ is a data + # accumulator. The return value of this method is passed to the + # next event handler (as of Enumerable#inject). + def on_default(event, token, data) data end diff --git a/ext/ripper/lib/ripper/tokenizer.rb b/ext/ripper/lib/ripper/tokenizer.rb index 4d90f16aa1..4209903ba7 100644 --- a/ext/ripper/lib/ripper/tokenizer.rb +++ b/ext/ripper/lib/ripper/tokenizer.rb @@ -8,6 +8,8 @@ # For details of Ruby License, see ruby/COPYING. # +require 'ripper/core' + class Ripper # Tokenizes Ruby program and returns an Array of String. diff --git a/ext/ripper/tools/generate-ripper_rb.rb b/ext/ripper/tools/generate-ripper_rb.rb index 8a96e4cb1e..5c06ca40a4 100755 --- a/ext/ripper/tools/generate-ripper_rb.rb +++ b/ext/ripper/tools/generate-ripper_rb.rb @@ -3,10 +3,9 @@ def main template, ids1, ids2 = *ARGV print <<header -# # This file is automatically generated from #{File.basename(template)} and parse.y. # DO NOT MODIFY!!!!!! -# + header File.foreach(template) do |line| case line diff --git a/test/ripper/dummyparser.rb b/test/ripper/dummyparser.rb index b95ebdb5d1..31fcafb159 100644 --- a/test/ripper/dummyparser.rb +++ b/test/ripper/dummyparser.rb @@ -2,9 +2,10 @@ # dummyparser.rb # -class Node +require 'ripper' - def initialize( name, *nodes ) +class Node + def initialize(name, *nodes) @name = name @children = nodes end @@ -14,512 +15,502 @@ class Node def to_s "#{@name}(#{@children.map {|n| n.to_s }.join(',')})" end - end - class NodeList - def initialize @list = [] end attr_reader :list - def push( item ) + def push(item) @list.push item self end - def prepend( items ) + def prepend(items) @list[0,0] = items end def to_s '[' + @list.join(',') + ']' end - end - class DummyParser < Ripper - def method_missing( mid, *args ) - raise NoMethodError, "wrong method: #{mid}" unless /\Aon__/ === mid.to_s - args[0] - end - - def on__program( stmts ) + def on_program(stmts) $thru_program = true stmts end - def on__stmts_new + def on_stmts_new NodeList.new end - def on__stmts_add( stmts, st ) + def on_stmts_add(stmts, st) stmts.push st stmts end - def on__void_stmt + def on_void_stmt Node.new('void') end - def on__BEGIN( stmts ) + def on_BEGIN(stmts) Node.new('BEGIN', stmts) end - def on__END( stmts ) + def on_END(stmts) Node.new('END', stmts) end - def on__var_ref( name ) + def on_var_ref(name) Node.new('ref', name) end - def on__alias(a, b) + def on_alias(a, b) Node.new('alias', a, b) end - def on__var_alias(a, b) + def on_var_alias(a, b) Node.new('valias', a, b) end - def on__alias_error(a) + def on_alias_error(a) Node.new('aliaserr', a) end - def on__aref(a, b) + def on_aref(a, b) Node.new('aref', a, b) end - def on__aref_field(a, b) + def on_aref_field(a, b) Node.new('aref_field', a, b) end - def on__arg_ambiguous + def on_arg_ambiguous Node.new('arg_ambiguous') end - def on__arg_paren( args ) + def on_arg_paren(args) args end - def on__arglist_new + def on_arglist_new NodeList.new end - def on__arglist_add( list, arg ) + def on_arglist_add(list, arg) list.push(arg) end - def on__arglist_add_block( list, blk ) + def on_arglist_add_block(list, blk) list.push('&' + blk.to_s) end - def on__arglist_add_star( list, arg ) + def on_arglist_add_star(list, arg) list.push('*' + arg.to_s) end - def on__arglist_prepend( list, args ) + def on_arglist_prepend(list, args) list.prepend args list end - def on__method_add_arg( m, arg ) + def on_method_add_arg(m, arg) m.children.push arg m end - def on__assoc_new(a, b) + def on_assoc_new(a, b) Node.new('assoc', a, b) end - def on__bare_assoc_hash( assoc_list ) + def on_bare_assoc_hash(assoc_list) Node.new('assocs', *assoc_list) end - def on__assoclist_from_args(a) + def on_assoclist_from_args(a) Node.new('assocs', *a.list) end ######## untested - def on__array(a) + def on_array(a) Node.new('array', a) end - def on__assign(a, b) + def on_assign(a, b) Node.new('assign', a, b) end - def on__assign_error(a) + def on_assign_error(a) Node.new('assign_error', a) end - def on__begin(a) + def on_begin(a) Node.new('begin', a) end - def on__binary(a, b, c) + def on_binary(a, b, c) Node.new('binary', a, b, c) end - def on__block_var(a) + def on_block_var(a) Node.new('block_var', a) end - def on__bodystmt(a, b, c, d) + def on_bodystmt(a, b, c, d) Node.new('bodystmt', a, b, c, d) end - def on__brace_block(a, b) + def on_brace_block(a, b) Node.new('brace_block', a, b) end - def on__break(a) + def on_break(a) Node.new('break', a) end - def on__call(a, b, c) + def on_call(a, b, c) Node.new('call', a, b, c) end - def on__case(a, b) + def on_case(a, b) Node.new('case', a, b) end - def on__class(a, b, c) + def on_class(a, b, c) Node.new('class', a, b, c) end - def on__class_name_error(a) + def on_class_name_error(a) Node.new('class_name_error', a) end - def on__command(a, b) + def on_command(a, b) Node.new('command', a, b) end - def on__command_call(a, b, c, d) + def on_command_call(a, b, c, d) Node.new('command_call', a, b, c, d) end - def on__const_ref(a) + def on_const_ref(a) Node.new('const_ref', a) end - def on__constpath_field(a, b) + def on_constpath_field(a, b) Node.new('constpath_field', a, b) end - def on__constpath_ref(a, b) + def on_constpath_ref(a, b) Node.new('constpath_ref', a, b) end - def on__def(a, b, c) + def on_def(a, b, c) Node.new('def', a, b, c) end - def on__defined(a) + def on_defined(a) Node.new('defined', a) end - def on__defs(a, b, c, d, e) + def on_defs(a, b, c, d, e) Node.new('defs', a, b, c, d, e) end - def on__do_block(a, b) + def on_do_block(a, b) Node.new('do_block', a, b) end - def on__dot2(a, b) + def on_dot2(a, b) Node.new('dot2', a, b) end - def on__dot3(a, b) + def on_dot3(a, b) Node.new('dot3', a, b) end - def on__dyna_symbol(a) + def on_dyna_symbol(a) Node.new('dyna_symbol', a) end - def on__else(a) + def on_else(a) Node.new('else', a) end - def on__elsif(a, b, c) + def on_elsif(a, b, c) Node.new('elsif', a, b, c) end - def on__ensure(a) + def on_ensure(a) Node.new('ensure', a) end - def on__fcall(a) + def on_fcall(a) Node.new('fcall', a) end - def on__field(a, b, c) + def on_field(a, b, c) Node.new('field', a, b, c) end - def on__for(a, b, c) + def on_for(a, b, c) Node.new('for', a, b, c) end - def on__hash(a) + def on_hash(a) Node.new('hash', a) end - def on__if(a, b, c) + def on_if(a, b, c) Node.new('if', a, b, c) end - def on__if_mod(a, b) + def on_if_mod(a, b) Node.new('if_mod', a, b) end - def on__ifop(a, b, c) + def on_ifop(a, b, c) Node.new('ifop', a, b, c) end - def on__iter_block(a, b) + def on_iter_block(a, b) Node.new('iter_block', a, b) end - def on__massign(a, b) + def on_massign(a, b) Node.new('massign', a, b) end - def on__mlhs_add(a, b) + def on_mlhs_add(a, b) Node.new('mlhs_add', a, b) end - def on__mlhs_add_star(a, b) + def on_mlhs_add_star(a, b) Node.new('mlhs_add_star', a, b) end - def on__mlhs_new + def on_mlhs_new Node.new('mlhs_new') end - def on__mlhs_paren(a) + def on_mlhs_paren(a) Node.new('mlhs_paren', a) end - def on__module(a, b) + def on_module(a, b) Node.new('module', a, b) end - def on__mrhs_add(a, b) + def on_mrhs_add(a, b) Node.new('mrhs_add', a, b) end - def on__mrhs_add_star(a, b) + def on_mrhs_add_star(a, b) Node.new('mrhs_add_star', a, b) end - def on__mrhs_new + def on_mrhs_new Node.new('mrhs_new') end - def on__mrhs_new_from_arglist(a) + def on_mrhs_new_from_arglist(a) Node.new('mrhs_new_from_arglist', a) end - def on__next(a) + def on_next(a) Node.new('next', a) end - def on__opassign(a, b, c) + def on_opassign(a, b, c) Node.new('opassign', a, b, c) end - def on__param_error(a) + def on_param_error(a) Node.new('param_error', a) end - def on__params(a, b, c, d) + def on_params(a, b, c, d) Node.new('params', a, b, c, d) end - def on__paren(a) + def on_paren(a) Node.new('paren', a) end - def on__parse_error(a) + def on_parse_error(a) Node.new('parse_error', a) end - def on__qwords_add(a, b) + def on_qwords_add(a, b) Node.new('qwords_add', a, b) end - def on__qwords_new + def on_qwords_new Node.new('qwords_new') end - def on__redo + def on_redo Node.new('redo') end - def on__regexp_literal(a) + def on_regexp_literal(a) Node.new('regexp_literal', a) end - def on__rescue(a, b, c, d) + def on_rescue(a, b, c, d) Node.new('rescue', a, b, c, d) end - def on__rescue_mod(a, b) + def on_rescue_mod(a, b) Node.new('rescue_mod', a, b) end - def on__restparam(a) + def on_restparam(a) Node.new('restparam', a) end - def on__retry + def on_retry Node.new('retry') end - def on__return(a) + def on_return(a) Node.new('return', a) end - def on__return0 + def on_return0 Node.new('return0') end - def on__sclass(a, b) + def on_sclass(a, b) Node.new('sclass', a, b) end - def on__space(a) + def on_space(a) Node.new('space', a) end - def on__string_add(a, b) + def on_string_add(a, b) Node.new('string_add', a, b) end - def on__string_concat(a, b) + def on_string_concat(a, b) Node.new('string_concat', a, b) end - def on__string_content + def on_string_content Node.new('string_content') end - def on__string_dvar(a) + def on_string_dvar(a) Node.new('string_dvar', a) end - def on__string_embexpr(a) + def on_string_embexpr(a) Node.new('string_embexpr', a) end - def on__string_literal(a) + def on_string_literal(a) Node.new('string_literal', a) end - def on__super(a) + def on_super(a) Node.new('super', a) end - def on__symbol(a) + def on_symbol(a) Node.new('symbol', a) end - def on__symbol_literal(a) + def on_symbol_literal(a) Node.new('symbol_literal', a) end - def on__topconst_field(a) + def on_topconst_field(a) Node.new('topconst_field', a) end - def on__topconst_ref(a) + def on_topconst_ref(a) Node.new('topconst_ref', a) end - def on__unary(a, b) + def on_unary(a, b) Node.new('unary', a, b) end - def on__undef(a) + def on_undef(a) Node.new('undef', a) end - def on__unless(a, b, c) + def on_unless(a, b, c) Node.new('unless', a, b, c) end - def on__unless_mod(a, b) + def on_unless_mod(a, b) Node.new('unless_mod', a, b) end - def on__until_mod(a, b) + def on_until_mod(a, b) Node.new('until_mod', a, b) end - def on__var_field(a) + def on_var_field(a) Node.new('var_field', a) end - def on__when(a, b, c) + def on_when(a, b, c) Node.new('when', a, b, c) end - def on__while(a, b) + def on_while(a, b) Node.new('while', a, b) end - def on__while_mod(a, b) + def on_while_mod(a, b) Node.new('while_mod', a, b) end - def on__word_add(a, b) + def on_word_add(a, b) Node.new('word_add', a, b) end - def on__word_new + def on_word_new Node.new('word_new') end - def on__words_add(a, b) + def on_words_add(a, b) Node.new('words_add', a, b) end - def on__words_new + def on_words_new Node.new('words_new') end - def on__xstring_add(a, b) + def on_xstring_add(a, b) Node.new('xstring_add', a, b) end - def on__xstring_literal(a) + def on_xstring_literal(a) Node.new('xstring_literal', a) end - def on__xstring_new + def on_xstring_new Node.new('xstring_new') end - def on__yield(a) + def on_yield(a) Node.new('yield', a) end - def on__yield0 + def on_yield0 Node.new('yield0') end - def on__zsuper + def on_zsuper Node.new('zsuper') end diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index 512cf377e7..db16ec5f17 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -2,12 +2,9 @@ # test_parser_events.rb # -require 'ripper.so' require 'dummyparser' -raise "ripper version differ" unless Ripper::Version == '0.1.0' require 'test/unit' - class TestRipper_ParserEvents < Test::Unit::TestCase def parse(str) diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index 5a2d4e9bf5..21aa9a8312 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -7,52 +7,28 @@ require 'test/unit' class TestRipper_ScannerEvents < Test::Unit::TestCase - class R < Ripper - def R.scan(target, src) - new(src, target).parse - end - - def initialize(src, target) - super src - @target = target ? ('on__' + target).intern : nil - end - - def parse - @tokens = [] - super - @tokens.sort_by {|tok,pos| pos }.map {|tok,| tok } - end - - def on__scan(type, tok) - @tokens.push [tok,[lineno(),column()]] if !@target or type == @target - end - end - - class PosInfo < Ripper - def parse - @q = [] - super - @q - end - - def on__scan(type, tok) - @q.push [tok, type, lineno(), column()] + def scan(target, str) + if target + sym = "on_#{target}".intern + Ripper.scan(str).select {|_,type,_| type == sym }.map {|_,_,tok| tok } + else + Ripper.scan(str).map {|_,_,tok| tok } end end def test_scan assert_equal [], - R.scan(nil, '') + scan(nil, '') assert_equal ['a'], - R.scan(nil, 'a') + scan(nil, 'a') assert_equal ['1'], - R.scan(nil, '1') + scan(nil, '1') assert_equal ['1', ';', 'def', ' ', 'm', '(', 'arg', ')', 'end'], - R.scan(nil, "1;def m(arg)end") + scan(nil, "1;def m(arg)end") assert_equal ['print', '(', '<<EOS', ')', "\n", "heredoc\n", "EOS\n"], - R.scan(nil, "print(<<EOS)\nheredoc\nEOS\n") + scan(nil, "print(<<EOS)\nheredoc\nEOS\n") assert_equal ['print', '(', ' ', '<<EOS', ')', "\n", "heredoc\n", "EOS\n"], - R.scan(nil, "print( <<EOS)\nheredoc\nEOS\n") + scan(nil, "print( <<EOS)\nheredoc\nEOS\n") end def test_location @@ -78,10 +54,9 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase end def validate_location(src) - data = PosInfo.new(src).parse buf = '' - data.sort_by {|tok, type, line, col| [line,col] }\ - .each do |tok, type, line, col| + Ripper.scan(src).each do |pos, type, tok| + line, col = *pos assert_equal buf.count("\n") + 1, line, "wrong lineno: #{tok.inspect} (#{type}) [#{line}:#{col}]" assert_equal buf.sub(/\A.*\n/m, '').size, col, @@ -93,690 +68,691 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase def test_backref assert_equal ["$`", "$&", "$'", '$1', '$2', '$3'], - R.scan('backref', %q[m($~, $`, $&, $', $1, $2, $3)]) + scan('backref', %q[m($~, $`, $&, $', $1, $2, $3)]) end def test_backtick assert_equal ["`"], - R.scan('backtick', %q[p `make all`]) + scan('backtick', %q[p `make all`]) end def test_comma assert_equal [','] * 6, - R.scan('comma', %q[ m(0,1,2,3,4,5,6) ]) + scan('comma', %q[ m(0,1,2,3,4,5,6) ]) assert_equal [], - R.scan('comma', %q[".,.,.,.,.,.,.."]) + scan('comma', %q[".,.,.,.,.,.,.."]) assert_equal [], - R.scan('comma', %Q[<<EOS\n,,,,,,,,,,\nEOS]) + scan('comma', %Q[<<EOS\n,,,,,,,,,,\nEOS]) end def test_period assert_equal [], - R.scan('period', '') + scan('period', '') assert_equal ['.'], - R.scan('period', 'a.b') + scan('period', 'a.b') assert_equal ['.'], - R.scan('period', 'Object.new') + scan('period', 'Object.new') assert_equal [], - R.scan('period', '"."') + scan('period', '"."') assert_equal [], - R.scan('period', '1..2') + scan('period', '1..2') assert_equal [], - R.scan('period', '1...3') + scan('period', '1...3') end def test_const assert_equal ['CONST'], - R.scan('const', 'CONST') + scan('const', 'CONST') assert_equal ['C'], - R.scan('const', 'C') + scan('const', 'C') assert_equal ['CONST_A'], - R.scan('const', 'CONST_A') + scan('const', 'CONST_A') assert_equal ['Const', 'Const2', 'Const3'], - R.scan('const', 'Const; Const2; Const3') + scan('const', 'Const; Const2; Const3') assert_equal ['Const'], - R.scan('const', 'Const(a)') + scan('const', 'Const(a)') assert_equal ['M', 'A', 'A2'], - R.scan('const', 'M(A,A2)') + scan('const', 'M(A,A2)') assert_equal [], - R.scan('const', '') + scan('const', '') assert_equal [], - R.scan('const', 'm(lvar, @ivar, @@cvar, $gvar)') + scan('const', 'm(lvar, @ivar, @@cvar, $gvar)') end def test_cvar assert_equal [], - R.scan('cvar', '') + scan('cvar', '') assert_equal ['@@cvar'], - R.scan('cvar', '@@cvar') + scan('cvar', '@@cvar') assert_equal ['@@__cvar__'], - R.scan('cvar', '@@__cvar__') + scan('cvar', '@@__cvar__') assert_equal ['@@CVAR'], - R.scan('cvar', '@@CVAR') + scan('cvar', '@@CVAR') assert_equal ['@@cvar'], - R.scan('cvar', ' @@cvar#comment') + scan('cvar', ' @@cvar#comment') assert_equal ['@@cvar'], - R.scan('cvar', ':@@cvar') + scan('cvar', ':@@cvar') assert_equal ['@@cvar'], - R.scan('cvar', 'm(lvar, @ivar, @@cvar, $gvar)') + scan('cvar', 'm(lvar, @ivar, @@cvar, $gvar)') assert_equal [], - R.scan('cvar', '"@@cvar"') + scan('cvar', '"@@cvar"') end def test_embexpr_beg assert_equal [], - R.scan('embexpr_beg', '') + scan('embexpr_beg', '') assert_equal ['#{'], - R.scan('embexpr_beg', '"#{expr}"') + scan('embexpr_beg', '"#{expr}"') assert_equal [], - R.scan('embexpr_beg', '%q[#{expr}]') + scan('embexpr_beg', '%q[#{expr}]') assert_equal ['#{'], - R.scan('embexpr_beg', '%Q[#{expr}]') + scan('embexpr_beg', '%Q[#{expr}]') assert_equal ['#{'], - R.scan('embexpr_beg', "m(<<EOS)\n\#{expr}\nEOS") + scan('embexpr_beg', "m(<<EOS)\n\#{expr}\nEOS") end =begin + # currently detected as "rbrace" def test_embexpr_end assert_equal [], - R.scan('embexpr_end', '') + scan('embexpr_end', '') assert_equal ['}'], - R.scan('embexpr_end', '"#{expr}"') + scan('embexpr_end', '"#{expr}"') assert_equal [], - R.scan('embexpr_end', '%q[#{expr}]') + scan('embexpr_end', '%q[#{expr}]') assert_equal ['}'], - R.scan('embexpr_end', '%Q[#{expr}]') + scan('embexpr_end', '%Q[#{expr}]') assert_equal ['}'], - R.scan('embexpr_end', "m(<<EOS)\n\#{expr}\nEOS") + scan('embexpr_end', "m(<<EOS)\n\#{expr}\nEOS") end =end def test_embvar assert_equal [], - R.scan('embvar', '') + scan('embvar', '') assert_equal ['#'], - R.scan('embvar', '"#$gvar"') + scan('embvar', '"#$gvar"') assert_equal ['#'], - R.scan('embvar', '"#@ivar"') + scan('embvar', '"#@ivar"') assert_equal ['#'], - R.scan('embvar', '"#@@cvar"') + scan('embvar', '"#@@cvar"') assert_equal [], - R.scan('embvar', '"#lvar"') + scan('embvar', '"#lvar"') assert_equal [], - R.scan('embvar', '"#"') + scan('embvar', '"#"') assert_equal [], - R.scan('embvar', '"\#$gvar"') + scan('embvar', '"\#$gvar"') assert_equal [], - R.scan('embvar', '"\#@ivar"') + scan('embvar', '"\#@ivar"') assert_equal [], - R.scan('embvar', '%q[#@ivar]') + scan('embvar', '%q[#@ivar]') assert_equal ['#'], - R.scan('embvar', '%Q[#@ivar]') + scan('embvar', '%Q[#@ivar]') end def test_float assert_equal [], - R.scan('float', '') + scan('float', '') assert_equal ['1.000'], - R.scan('float', '1.000') + scan('float', '1.000') assert_equal ['123.456'], - R.scan('float', '123.456') + scan('float', '123.456') assert_equal ['1.2345678901234567890123456789'], - R.scan('float', '1.2345678901234567890123456789') + scan('float', '1.2345678901234567890123456789') assert_equal ['1.000'], - R.scan('float', ' 1.000# comment') + scan('float', ' 1.000# comment') assert_equal ['1.234e5'], - R.scan('float', '1.234e5') + scan('float', '1.234e5') assert_equal ['1.234e1234567890'], - R.scan('float', '1.234e1234567890') + scan('float', '1.234e1234567890') assert_equal ['1.0'], - R.scan('float', 'm(a,b,1.0,c,d)') + scan('float', 'm(a,b,1.0,c,d)') end def test_gvar assert_equal [], - R.scan('gvar', '') + scan('gvar', '') assert_equal ['$a'], - R.scan('gvar', '$a') + scan('gvar', '$a') assert_equal ['$A'], - R.scan('gvar', '$A') + scan('gvar', '$A') assert_equal ['$gvar'], - R.scan('gvar', 'm(lvar, @ivar, @@cvar, $gvar)') + scan('gvar', 'm(lvar, @ivar, @@cvar, $gvar)') assert_equal %w($_ $~ $* $$ $? $! $@ $/ $\\ $; $, $. $= $: $< $> $"), - R.scan('gvar', 'm($_, $~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $")') + scan('gvar', 'm($_, $~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $")') end def test_ident assert_equal [], - R.scan('ident', '') + scan('ident', '') assert_equal ['lvar'], - R.scan('ident', 'lvar') + scan('ident', 'lvar') assert_equal ['m', 'lvar'], - R.scan('ident', 'm(lvar, @ivar, @@cvar, $gvar)') + scan('ident', 'm(lvar, @ivar, @@cvar, $gvar)') end def test_int assert_equal [], - R.scan('int', '') + scan('int', '') assert_equal ['1', '10', '100000000000000'], - R.scan('int', 'm(1,10,100000000000000)') + scan('int', 'm(1,10,100000000000000)') end def test_ivar assert_equal [], - R.scan('ivar', '') + scan('ivar', '') assert_equal ['@ivar'], - R.scan('ivar', '@ivar') + scan('ivar', '@ivar') assert_equal ['@__ivar__'], - R.scan('ivar', '@__ivar__') + scan('ivar', '@__ivar__') assert_equal ['@IVAR'], - R.scan('ivar', '@IVAR') + scan('ivar', '@IVAR') assert_equal ['@ivar'], - R.scan('ivar', 'm(lvar, @ivar, @@cvar, $gvar)') + scan('ivar', 'm(lvar, @ivar, @@cvar, $gvar)') end def test_kw assert_equal [], - R.scan('kw', '') + scan('kw', '') assert_equal %w(not), - R.scan('kw', 'not 1') + scan('kw', 'not 1') assert_equal %w(and), - R.scan('kw', '1 and 2') + scan('kw', '1 and 2') assert_equal %w(or), - R.scan('kw', '1 or 2') + scan('kw', '1 or 2') assert_equal %w(if then else end), - R.scan('kw', 'if 1 then 2 else 3 end') + scan('kw', 'if 1 then 2 else 3 end') assert_equal %w(if then elsif else end), - R.scan('kw', 'if 1 then 2 elsif 3 else 4 end') + scan('kw', 'if 1 then 2 elsif 3 else 4 end') assert_equal %w(unless then end), - R.scan('kw', 'unless 1 then end') + scan('kw', 'unless 1 then end') assert_equal %w(if true), - R.scan('kw', '1 if true') + scan('kw', '1 if true') assert_equal %w(unless false), - R.scan('kw', '2 unless false') + scan('kw', '2 unless false') assert_equal %w(case when when else end), - R.scan('kw', 'case n; when 1; when 2; else 3 end') + scan('kw', 'case n; when 1; when 2; else 3 end') assert_equal %w(while do nil end), - R.scan('kw', 'while 1 do nil end') + scan('kw', 'while 1 do nil end') assert_equal %w(until do nil end), - R.scan('kw', 'until 1 do nil end') + scan('kw', 'until 1 do nil end') assert_equal %w(while), - R.scan('kw', '1 while 2') + scan('kw', '1 while 2') assert_equal %w(until), - R.scan('kw', '1 until 2') + scan('kw', '1 until 2') assert_equal %w(while break next retry end), - R.scan('kw', 'while 1; break; next; retry end') + scan('kw', 'while 1; break; next; retry end') assert_equal %w(for in next break end), - R.scan('kw', 'for x in obj; next 1; break 2 end') + scan('kw', 'for x in obj; next 1; break 2 end') assert_equal %w(begin rescue retry end), - R.scan('kw', 'begin 1; rescue; retry; end') + scan('kw', 'begin 1; rescue; retry; end') assert_equal %w(rescue), - R.scan('kw', '1 rescue 2') + scan('kw', '1 rescue 2') assert_equal %w(def redo return end), - R.scan('kw', 'def m() redo; return end') + scan('kw', 'def m() redo; return end') assert_equal %w(def yield yield end), - R.scan('kw', 'def m() yield; yield 1 end') + scan('kw', 'def m() yield; yield 1 end') assert_equal %w(def super super super end), - R.scan('kw', 'def m() super; super(); super(1) end') + scan('kw', 'def m() super; super(); super(1) end') assert_equal %w(alias), - R.scan('kw', 'alias a b') + scan('kw', 'alias a b') assert_equal %w(undef), - R.scan('kw', 'undef public') + scan('kw', 'undef public') assert_equal %w(class end), - R.scan('kw', 'class A < Object; end') + scan('kw', 'class A < Object; end') assert_equal %w(module end), - R.scan('kw', 'module M; end') + scan('kw', 'module M; end') assert_equal %w(class end), - R.scan('kw', 'class << obj; end') + scan('kw', 'class << obj; end') assert_equal %w(BEGIN), - R.scan('kw', 'BEGIN { }') + scan('kw', 'BEGIN { }') assert_equal %w(END), - R.scan('kw', 'END { }') + scan('kw', 'END { }') assert_equal %w(self), - R.scan('kw', 'self.class') + scan('kw', 'self.class') assert_equal %w(nil true false), - R.scan('kw', 'p(nil, true, false)') + scan('kw', 'p(nil, true, false)') assert_equal %w(__FILE__ __LINE__), - R.scan('kw', 'p __FILE__, __LINE__') + scan('kw', 'p __FILE__, __LINE__') assert_equal %w(defined?), - R.scan('kw', 'defined?(Object)') + scan('kw', 'defined?(Object)') end def test_lbrace assert_equal [], - R.scan('lbrace', '') + scan('lbrace', '') assert_equal ['{'], - R.scan('lbrace', '3.times{ }') + scan('lbrace', '3.times{ }') assert_equal ['{'], - R.scan('lbrace', '3.times { }') + scan('lbrace', '3.times { }') assert_equal ['{'], - R.scan('lbrace', '3.times{}') + scan('lbrace', '3.times{}') assert_equal [], - R.scan('lbrace', '"{}"') + scan('lbrace', '"{}"') assert_equal ['{'], - R.scan('lbrace', '{1=>2}') + scan('lbrace', '{1=>2}') end def test_rbrace assert_equal [], - R.scan('rbrace', '') + scan('rbrace', '') assert_equal ['}'], - R.scan('rbrace', '3.times{ }') + scan('rbrace', '3.times{ }') assert_equal ['}'], - R.scan('rbrace', '3.times { }') + scan('rbrace', '3.times { }') assert_equal ['}'], - R.scan('rbrace', '3.times{}') + scan('rbrace', '3.times{}') assert_equal [], - R.scan('rbrace', '"{}"') + scan('rbrace', '"{}"') assert_equal ['}'], - R.scan('rbrace', '{1=>2}') + scan('rbrace', '{1=>2}') end def test_lbracket assert_equal [], - R.scan('lbracket', '') + scan('lbracket', '') assert_equal ['['], - R.scan('lbracket', '[]') + scan('lbracket', '[]') assert_equal ['['], - R.scan('lbracket', 'a[1]') + scan('lbracket', 'a[1]') assert_equal [], - R.scan('lbracket', 'm(%q[])') + scan('lbracket', 'm(%q[])') end def test_rbracket assert_equal [], - R.scan('rbracket', '') + scan('rbracket', '') assert_equal [']'], - R.scan('rbracket', '[]') + scan('rbracket', '[]') assert_equal [']'], - R.scan('rbracket', 'a[1]') + scan('rbracket', 'a[1]') assert_equal [], - R.scan('rbracket', 'm(%q[])') + scan('rbracket', 'm(%q[])') end def test_lparen assert_equal [], - R.scan('lparen', '') + scan('lparen', '') assert_equal ['('], - R.scan('lparen', '()') + scan('lparen', '()') assert_equal ['('], - R.scan('lparen', 'm()') + scan('lparen', 'm()') assert_equal ['('], - R.scan('lparen', 'm (a)') + scan('lparen', 'm (a)') assert_equal [], - R.scan('lparen', '"()"') + scan('lparen', '"()"') assert_equal [], - R.scan('lparen', '"%w()"') + scan('lparen', '"%w()"') end def test_rparen assert_equal [], - R.scan('rparen', '') + scan('rparen', '') assert_equal [')'], - R.scan('rparen', '()') + scan('rparen', '()') assert_equal [')'], - R.scan('rparen', 'm()') + scan('rparen', 'm()') assert_equal [')'], - R.scan('rparen', 'm (a)') + scan('rparen', 'm (a)') assert_equal [], - R.scan('rparen', '"()"') + scan('rparen', '"()"') assert_equal [], - R.scan('rparen', '"%w()"') + scan('rparen', '"%w()"') end def test_op assert_equal [], - R.scan('op', '') + scan('op', '') assert_equal ['|'], - R.scan('op', '1 | 1') + scan('op', '1 | 1') assert_equal ['^'], - R.scan('op', '1 ^ 1') + scan('op', '1 ^ 1') assert_equal ['&'], - R.scan('op', '1 & 1') + scan('op', '1 & 1') assert_equal ['<=>'], - R.scan('op', '1 <=> 1') + scan('op', '1 <=> 1') assert_equal ['=='], - R.scan('op', '1 == 1') + scan('op', '1 == 1') assert_equal ['==='], - R.scan('op', '1 === 1') + scan('op', '1 === 1') assert_equal ['=~'], - R.scan('op', '1 =~ 1') + scan('op', '1 =~ 1') assert_equal ['>'], - R.scan('op', '1 > 1') + scan('op', '1 > 1') assert_equal ['>='], - R.scan('op', '1 >= 1') + scan('op', '1 >= 1') assert_equal ['<'], - R.scan('op', '1 < 1') + scan('op', '1 < 1') assert_equal ['<='], - R.scan('op', '1 <= 1') + scan('op', '1 <= 1') assert_equal ['<<'], - R.scan('op', '1 << 1') + scan('op', '1 << 1') assert_equal ['>>'], - R.scan('op', '1 >> 1') + scan('op', '1 >> 1') assert_equal ['+'], - R.scan('op', '1 + 1') + scan('op', '1 + 1') assert_equal ['-'], - R.scan('op', '1 - 1') + scan('op', '1 - 1') assert_equal ['*'], - R.scan('op', '1 * 1') + scan('op', '1 * 1') assert_equal ['/'], - R.scan('op', '1 / 1') + scan('op', '1 / 1') assert_equal ['%'], - R.scan('op', '1 % 1') + scan('op', '1 % 1') assert_equal ['**'], - R.scan('op', '1 ** 1') + scan('op', '1 ** 1') assert_equal ['~'], - R.scan('op', '~1') + scan('op', '~1') assert_equal ['-'], - R.scan('op', '-a') + scan('op', '-a') assert_equal ['+'], - R.scan('op', '+a') + scan('op', '+a') assert_equal ['[]'], - R.scan('op', ':[]') + scan('op', ':[]') assert_equal ['[]='], - R.scan('op', ':[]=') + scan('op', ':[]=') assert_equal [], - R.scan('op', %q[`make all`]) + scan('op', %q[`make all`]) end def test_symbeg assert_equal [], - R.scan('symbeg', '') + scan('symbeg', '') assert_equal [':'], - R.scan('symbeg', ':sym') + scan('symbeg', ':sym') assert_equal [':'], - R.scan('symbeg', '[1,2,3,:sym]') + scan('symbeg', '[1,2,3,:sym]') assert_equal [], - R.scan('symbeg', '":sym"') + scan('symbeg', '":sym"') assert_equal [], - R.scan('symbeg', 'a ? b : c') + scan('symbeg', 'a ? b : c') end def test_tstring_beg assert_equal [], - R.scan('tstring_beg', '') + scan('tstring_beg', '') assert_equal ['"'], - R.scan('tstring_beg', '"abcdef"') + scan('tstring_beg', '"abcdef"') assert_equal ['%q['], - R.scan('tstring_beg', '%q[abcdef]') + scan('tstring_beg', '%q[abcdef]') assert_equal ['%Q['], - R.scan('tstring_beg', '%Q[abcdef]') + scan('tstring_beg', '%Q[abcdef]') end def test_tstring_content assert_equal [], - R.scan('tstring_content', '') + scan('tstring_content', '') assert_equal ['abcdef'], - R.scan('tstring_content', '"abcdef"') + scan('tstring_content', '"abcdef"') assert_equal ['abcdef'], - R.scan('tstring_content', '%q[abcdef]') + scan('tstring_content', '%q[abcdef]') assert_equal ['abcdef'], - R.scan('tstring_content', '%Q[abcdef]') + scan('tstring_content', '%Q[abcdef]') assert_equal ['abc', 'def'], - R.scan('tstring_content', '"abc#{1}def"') + scan('tstring_content', '"abc#{1}def"') assert_equal ['sym'], - R.scan('tstring_content', ':"sym"') + scan('tstring_content', ':"sym"') end def test_tstring_end assert_equal [], - R.scan('tstring_end', '') + scan('tstring_end', '') assert_equal ['"'], - R.scan('tstring_end', '"abcdef"') + scan('tstring_end', '"abcdef"') assert_equal [']'], - R.scan('tstring_end', '%q[abcdef]') + scan('tstring_end', '%q[abcdef]') assert_equal [']'], - R.scan('tstring_end', '%Q[abcdef]') + scan('tstring_end', '%Q[abcdef]') end def test_regexp_beg assert_equal [], - R.scan('regexp_beg', '') + scan('regexp_beg', '') assert_equal ['/'], - R.scan('regexp_beg', '/re/') + scan('regexp_beg', '/re/') assert_equal ['%r<'], - R.scan('regexp_beg', '%r<re>') + scan('regexp_beg', '%r<re>') assert_equal [], - R.scan('regexp_beg', '5 / 5') + scan('regexp_beg', '5 / 5') end def test_regexp_end assert_equal [], - R.scan('regexp_end', '') + scan('regexp_end', '') assert_equal ['/'], - R.scan('regexp_end', '/re/') + scan('regexp_end', '/re/') assert_equal ['>'], - R.scan('regexp_end', '%r<re>') + scan('regexp_end', '%r<re>') end def test_words_beg assert_equal [], - R.scan('words_beg', '') + scan('words_beg', '') assert_equal ['%W('], - R.scan('words_beg', '%W()') + scan('words_beg', '%W()') assert_equal ['%W('], - R.scan('words_beg', '%W(w w w)') + scan('words_beg', '%W(w w w)') assert_equal ['%W( '], - R.scan('words_beg', '%W( w w w )') + scan('words_beg', '%W( w w w )') end def test_qwords_beg assert_equal [], - R.scan('qwords_beg', '') + scan('qwords_beg', '') assert_equal ['%w('], - R.scan('qwords_beg', '%w()') + scan('qwords_beg', '%w()') assert_equal ['%w('], - R.scan('qwords_beg', '%w(w w w)') + scan('qwords_beg', '%w(w w w)') assert_equal ['%w( '], - R.scan('qwords_beg', '%w( w w w )') + scan('qwords_beg', '%w( w w w )') end # FIXME: Close paren must not present (`words_end' scanner event?). def test_words_sep assert_equal [], - R.scan('words_sep', '') + scan('words_sep', '') assert_equal [')'], - R.scan('words_sep', '%w()') + scan('words_sep', '%w()') assert_equal [' ', ' ', ')'], - R.scan('words_sep', '%w(w w w)') + scan('words_sep', '%w(w w w)') assert_equal [' ', ' ', ' )'], - R.scan('words_sep', '%w( w w w )') + scan('words_sep', '%w( w w w )') assert_equal ["\n", ' ', ' )'], - R.scan('words_sep', "%w( w\nw w )") + scan('words_sep', "%w( w\nw w )") end def test_heredoc_beg assert_equal [], - R.scan('heredoc_beg', '') + scan('heredoc_beg', '') assert_equal ['<<EOS'], - R.scan('heredoc_beg', "<<EOS\nheredoc\nEOS") + scan('heredoc_beg', "<<EOS\nheredoc\nEOS") assert_equal ['<<EOS'], - R.scan('heredoc_beg', "<<EOS\nheredoc\nEOS\n") + scan('heredoc_beg', "<<EOS\nheredoc\nEOS\n") assert_equal ['<<EOS'], - R.scan('heredoc_beg', "<<EOS\nheredoc\nEOS \n") + scan('heredoc_beg', "<<EOS\nheredoc\nEOS \n") assert_equal ['<<-EOS'], - R.scan('heredoc_beg', "<<-EOS\nheredoc\n\tEOS \n") + scan('heredoc_beg', "<<-EOS\nheredoc\n\tEOS \n") assert_equal ['<<"EOS"'], - R.scan('heredoc_beg', %Q[<<"EOS"\nheredoc\nEOS]) + scan('heredoc_beg', %Q[<<"EOS"\nheredoc\nEOS]) assert_equal [%q(<<'EOS')], - R.scan('heredoc_beg', "<<'EOS'\nheredoc\nEOS") + scan('heredoc_beg', "<<'EOS'\nheredoc\nEOS") assert_equal [%q(<<`EOS`)], - R.scan('heredoc_beg', "<<`EOS`\nheredoc\nEOS") + scan('heredoc_beg', "<<`EOS`\nheredoc\nEOS") assert_equal [%q(<<" ")], - R.scan('heredoc_beg', %Q[<<" "\nheredoc\nEOS]) + scan('heredoc_beg', %Q[<<" "\nheredoc\nEOS]) end def test_tstring_content_HEREDOC assert_equal [], - R.scan('tstring_content', '') + scan('tstring_content', '') assert_equal ["heredoc\n"], - R.scan('tstring_content', "<<EOS\nheredoc\nEOS") + scan('tstring_content', "<<EOS\nheredoc\nEOS") assert_equal ["heredoc\n"], - R.scan('tstring_content', "<<EOS\nheredoc\nEOS\n") + scan('tstring_content', "<<EOS\nheredoc\nEOS\n") assert_equal ["heredoc \n"], - R.scan('tstring_content', "<<EOS\nheredoc \nEOS \n") + scan('tstring_content', "<<EOS\nheredoc \nEOS \n") assert_equal ["heredoc\n"], - R.scan('tstring_content', "<<-EOS\nheredoc\n\tEOS \n") + scan('tstring_content', "<<-EOS\nheredoc\n\tEOS \n") end def test_heredoc_end assert_equal [], - R.scan('heredoc_end', '') + scan('heredoc_end', '') assert_equal ["EOS"], - R.scan('heredoc_end', "<<EOS\nheredoc\nEOS") + scan('heredoc_end', "<<EOS\nheredoc\nEOS") assert_equal ["EOS\n"], - R.scan('heredoc_end', "<<EOS\nheredoc\nEOS\n") + scan('heredoc_end', "<<EOS\nheredoc\nEOS\n") assert_equal ["EOS \n"], - R.scan('heredoc_end', "<<EOS\nheredoc\nEOS \n") + scan('heredoc_end', "<<EOS\nheredoc\nEOS \n") assert_equal ["\tEOS \n"], - R.scan('heredoc_end', "<<-EOS\nheredoc\n\tEOS \n") + scan('heredoc_end', "<<-EOS\nheredoc\n\tEOS \n") end def test_semicolon assert_equal [], - R.scan('semicolon', '') + scan('semicolon', '') assert_equal %w(;), - R.scan('semicolon', ';') + scan('semicolon', ';') assert_equal %w(; ;), - R.scan('semicolon', ';;') + scan('semicolon', ';;') assert_equal %w(; ; ;), - R.scan('semicolon', 'nil;nil;nil;') + scan('semicolon', 'nil;nil;nil;') assert_equal %w(; ; ;), - R.scan('semicolon', 'nil;nil;nil;nil') + scan('semicolon', 'nil;nil;nil;nil') assert_equal [], - R.scan('semicolon', '";"') + scan('semicolon', '";"') assert_equal [], - R.scan('semicolon', '%w(;)') + scan('semicolon', '%w(;)') assert_equal [], - R.scan('semicolon', '/;/') + scan('semicolon', '/;/') end def test_comment assert_equal [], - R.scan('comment', '') + scan('comment', '') assert_equal ['# comment'], - R.scan('comment', '# comment') + scan('comment', '# comment') assert_equal ["# comment\n"], - R.scan('comment', "# comment\n") + scan('comment', "# comment\n") assert_equal ["# comment\n"], - R.scan('comment', "# comment\n1 + 1") + scan('comment', "# comment\n1 + 1") assert_equal ["# comment\n"], - R.scan('comment', "1 + 1 + 1# comment\n1 + 1") + scan('comment', "1 + 1 + 1# comment\n1 + 1") end def test_embdoc_beg assert_equal [], - R.scan('embdoc_beg', '') + scan('embdoc_beg', '') assert_equal ["=begin\n"], - R.scan('embdoc_beg', "=begin\ndoc\n=end") + scan('embdoc_beg', "=begin\ndoc\n=end") assert_equal ["=begin \n"], - R.scan('embdoc_beg', "=begin \ndoc\n=end\n") + scan('embdoc_beg', "=begin \ndoc\n=end\n") assert_equal ["=begin comment\n"], - R.scan('embdoc_beg', "=begin comment\ndoc\n=end\n") + scan('embdoc_beg', "=begin comment\ndoc\n=end\n") end def test_embdoc assert_equal [], - R.scan('embdoc', '') + scan('embdoc', '') assert_equal ["doc\n"], - R.scan('embdoc', "=begin\ndoc\n=end") + scan('embdoc', "=begin\ndoc\n=end") assert_equal ["doc\n"], - R.scan('embdoc', "=begin\ndoc\n=end\n") + scan('embdoc', "=begin\ndoc\n=end\n") end def test_embdoc_end assert_equal [], - R.scan('embdoc_end', '') + scan('embdoc_end', '') assert_equal ["=end"], - R.scan('embdoc_end', "=begin\ndoc\n=end") + scan('embdoc_end', "=begin\ndoc\n=end") assert_equal ["=end\n"], - R.scan('embdoc_end', "=begin\ndoc\n=end\n") + scan('embdoc_end', "=begin\ndoc\n=end\n") end def test_sp assert_equal [], - R.scan('sp', '') + scan('sp', '') assert_equal [' '], - R.scan('sp', ' ') + scan('sp', ' ') assert_equal [' '], - R.scan('sp', ' 1') + scan('sp', ' 1') assert_equal [], - R.scan('sp', "\n") + scan('sp', "\n") assert_equal [' '], - R.scan('sp', " \n") + scan('sp', " \n") assert_equal [' ', ' '], - R.scan('sp', "1 + 1") + scan('sp', "1 + 1") assert_equal [], - R.scan('sp', "' '") + scan('sp', "' '") assert_equal [], - R.scan('sp', "%w( )") + scan('sp', "%w( )") assert_equal [], - R.scan('sp', "%w( w )") + scan('sp', "%w( w )") assert_equal [], - R.scan('sp', "p(/ /)") + scan('sp', "p(/ /)") end # `nl' event always means End-Of-Statement. def test_nl assert_equal [], - R.scan('nl', '') + scan('nl', '') assert_equal [], - R.scan('nl', "\n") + scan('nl', "\n") assert_equal ["\n"], - R.scan('nl', "1 + 1\n") + scan('nl', "1 + 1\n") assert_equal ["\n", "\n"], - R.scan('nl', "1 + 1\n2 + 2\n") + scan('nl', "1 + 1\n2 + 2\n") assert_equal [], - R.scan('nl', "1 +\n1") + scan('nl', "1 +\n1") assert_equal [], - R.scan('nl', "1;\n") + scan('nl', "1;\n") assert_equal ["\r\n"], - R.scan('nl', "1 + 1\r\n") + scan('nl', "1 + 1\r\n") assert_equal [], - R.scan('nl', "1;\r\n") + scan('nl', "1;\r\n") end def test_ignored_nl assert_equal [], - R.scan('ignored_nl', '') + scan('ignored_nl', '') assert_equal ["\n"], - R.scan('ignored_nl', "\n") + scan('ignored_nl', "\n") assert_equal [], - R.scan('ignored_nl', "1 + 1\n") + scan('ignored_nl', "1 + 1\n") assert_equal [], - R.scan('ignored_nl', "1 + 1\n2 + 2\n") + scan('ignored_nl', "1 + 1\n2 + 2\n") assert_equal ["\n"], - R.scan('ignored_nl', "1 +\n1") + scan('ignored_nl', "1 +\n1") assert_equal ["\n"], - R.scan('ignored_nl', "1;\n") + scan('ignored_nl', "1;\n") assert_equal [], - R.scan('ignored_nl', "1 + 1\r\n") + scan('ignored_nl', "1 + 1\r\n") assert_equal ["\r\n"], - R.scan('ignored_nl', "1;\r\n") + scan('ignored_nl', "1;\r\n") end def test___end__ assert_equal [], - R.scan('__end__', "") + scan('__end__', "") assert_equal ["__END__"], - R.scan('__end__', "__END__") + scan('__end__', "__END__") assert_equal ["__END__\n"], - R.scan('__end__', "__END__\n") + scan('__end__', "__END__\n") assert_equal ["__END__\n"], - R.scan(nil, "__END__\njunk junk junk") + scan(nil, "__END__\njunk junk junk") assert_equal ["__END__"], - R.scan('__end__', "1\n__END__") + scan('__end__', "1\n__END__") assert_equal [], - R.scan('__end__', "print('__END__')") + scan('__end__', "print('__END__')") end def test_CHAR assert_equal [], - R.scan('CHAR', "") + scan('CHAR', "") assert_equal ["@"], - R.scan('CHAR', "@") + scan('CHAR', "@") assert_equal [], - R.scan('CHAR', "@ivar") + scan('CHAR', "@ivar") end end |