1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/racc/cparse/cparse.c: sync with original code, rev 1.8.

* ext/racc/cparse/cparse.c: should mark CparseParams objects.
* lib/racc/parser.rb: sync with original code, rev 1.8.
* lib/racc/parser.rb: update coding style.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2006-07-06 12:50:51 +00:00
parent c3e411ee8a
commit 69aeed5065
3 changed files with 98 additions and 61 deletions

View file

@ -1,3 +1,13 @@
Thu Jul 6 21:50:06 2006 Minero Aoki <aamine@loveruby.net>
* ext/racc/cparse/cparse.c: sync with original code, rev 1.8.
* ext/racc/cparse/cparse.c: should mark CparseParams objects.
* lib/racc/parser.rb: sync with original code, rev 1.8.
* lib/racc/parser.rb: update coding style.
Wed Jul 5 01:12:19 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* test/ruby/test_lambda.rb (TestLambdaParameters::test_lambda_as_iterator):

View file

@ -7,7 +7,7 @@
This library is free software.
You can distribute/modify this program under the same terms of ruby.
$originalId: cparse.c,v 1.7 2006/07/02 10:02:02 aamine Exp $
$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $
*/
@ -194,9 +194,9 @@ static VALUE lexer_i _((VALUE block_args, VALUE data, VALUE self));
static VALUE assert_array _((VALUE a));
static long assert_integer _((VALUE n));
static VALUE assert_hash _((VALUE h));
static void initialize_params _((struct cparse_params *v,
VALUE parser, VALUE arg,
static VALUE initialize_params _((VALUE vparams, VALUE parser, VALUE arg,
VALUE lexer, VALUE lexmid));
static void cparse_params_mark _((void *ptr));
static void parse_main _((struct cparse_params *v,
VALUE tok, VALUE val, int resume));
@ -217,12 +217,14 @@ static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self));
static VALUE
racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
{
struct cparse_params params;
struct cparse_params *v = &params;
volatile VALUE vparams;
struct cparse_params *v;
vparams = Data_Make_Struct(CparseParams, struct cparse_params,
cparse_params_mark, -1, v);
D_puts("starting cparse");
v->sys_debug = RTEST(sysdebug);
initialize_params(v, parser, arg, Qnil, Qnil);
vparams = initialize_params(vparams, parser, arg, Qnil, Qnil);
v->lex_is_iterator = Qfalse;
parse_main(v, Qnil, Qnil, 0);
@ -232,12 +234,14 @@ racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
static VALUE
racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
{
struct cparse_params params;
struct cparse_params *v = &params;
volatile VALUE vparams;
struct cparse_params *v;
vparams = Data_Make_Struct(CparseParams, struct cparse_params,
cparse_params_mark, -1, v);
v->sys_debug = RTEST(sysdebug);
D_puts("start C yyparse");
initialize_params(v, parser, arg, lexer, lexmid);
vparams = initialize_params(vparams, parser, arg, lexer, lexmid);
v->lex_is_iterator = Qtrue;
D_puts("params initialized");
parse_main(v, Qnil, Qnil, 0);
@ -310,12 +314,13 @@ assert_integer(VALUE n)
return NUM2LONG(n);
}
static void
initialize_params(struct cparse_params *v,
VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
static VALUE
initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
{
v->value_v = Data_Wrap_Struct(CparseParams, 0, 0, v);
struct cparse_params *v;
Data_Get_Struct(vparams, struct cparse_params, v);
v->value_v = vparams;
v->parser = parser;
v->lexer = lexer;
if (! NIL_P(lexmid))
@ -360,6 +365,45 @@ initialize_params(struct cparse_params *v,
v->fin = 0;
v->lex_is_iterator = Qfalse;
rb_iv_set(parser, "@vstack", v->vstack);
if (v->debug) {
rb_iv_set(parser, "@tstack", v->tstack);
}
else {
rb_iv_set(parser, "@tstack", Qnil);
}
return vparams;
}
static void
cparse_params_mark(void *ptr)
{
struct cparse_params *v = (struct cparse_params*)ptr;
rb_gc_mark(v->value_v);
rb_gc_mark(v->parser);
rb_gc_mark(v->lexer);
rb_gc_mark(v->action_table);
rb_gc_mark(v->action_check);
rb_gc_mark(v->action_default);
rb_gc_mark(v->action_pointer);
rb_gc_mark(v->goto_table);
rb_gc_mark(v->goto_check);
rb_gc_mark(v->goto_default);
rb_gc_mark(v->goto_pointer);
rb_gc_mark(v->goto_pointer);
rb_gc_mark(v->goto_pointer);
rb_gc_mark(v->goto_pointer);
rb_gc_mark(v->goto_pointer);
rb_gc_mark(v->reduce_table);
rb_gc_mark(v->token_table);
rb_gc_mark(v->state);
rb_gc_mark(v->vstack);
rb_gc_mark(v->tstack);
rb_gc_mark(v->t);
rb_gc_mark(v->retval);
}
static void
@ -446,8 +490,10 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
extract_user_token(v, tmp, &tok, &val);
}
/* convert token */
tmp = rb_hash_aref(v->token_table, tok);
v->t = NIL_P(tmp) ? vERROR_TOKEN : tmp;
v->t = rb_hash_aref(v->token_table, tok);
if (NIL_P(v->t)) {
v->t = vERROR_TOKEN;
}
D_printf("(act) t(k2)=%ld\n", NUM2LONG(v->t));
if (v->debug) {
rb_funcall(v->parser, id_d_read_token,
@ -765,7 +811,7 @@ Init_cparse(void)
rb_define_const(Parser, "Racc_Runtime_Core_Version_C",
rb_str_new2(RACC_VERSION));
rb_define_const(Parser, "Racc_Runtime_Core_Id_C",
rb_str_new2("$originalId: cparse.c,v 1.7 2006/07/02 10:02:02 aamine Exp $"));
rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);

View file

@ -1,7 +1,7 @@
#
# parser.rb
# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
#
# Copyright (c) 1999-2004 Minero Aoki
# Copyright (c) 1999-2006 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the same terms of ruby.
@ -10,13 +10,6 @@
# into a Racc output file, you may use that output file
# without restriction.
#
# $raccId: parser.rb,v 1.4 2003/11/03 13:41:47 aamine Exp $
#
# NOTE:
# This file is part of the runtime library of Racc parser generator.
# If you want to generate your own parser, you must get Racc full package.
# Get it from: http://raa.ruby-lang.org/list.rhtml?name=racc
#
unless defined?(NotImplementedError)
NotImplementedError = NotImplementError
@ -29,7 +22,6 @@ unless defined?(::ParseError)
ParseError = Racc::ParseError
end
module Racc
unless defined?(Racc_No_Extentions)
@ -38,14 +30,14 @@ module Racc
class Parser
Racc_Runtime_Version = '1.4.4'
Racc_Runtime_Revision = '$raccRevision: 1.4 $'.split[1]
Racc_Runtime_Version = '1.4.5'
Racc_Runtime_Revision = '$originalRevision: 1.8 $'.split[1]
Racc_Runtime_Core_Version_R = '1.4.4'
Racc_Runtime_Core_Revision_R = '$raccRevision: 1.4 $'.split[1]
Racc_Runtime_Core_Version_R = '1.4.5'
Racc_Runtime_Core_Revision_R = '$originalRevision: 1.8 $'.split[1]
begin
require 'racc/cparse'
# Racc_Runtime_Core_Version_C = (defined in extension)
# Racc_Runtime_Core_Version_C = (defined in extention)
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
unless new.respond_to?(:_racc_do_parse_c, true)
raise LoadError, 'old cparse.so'
@ -111,7 +103,7 @@ module Racc
raise NotImplementedError, "#{self.class}\#next_token is not defined"
end
def _racc_do_parse_rb( arg, in_debug )
def _racc_do_parse_rb(arg, in_debug)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
@ -156,11 +148,11 @@ module Racc
### yyparse
###
def yyparse( recv, mid )
def yyparse(recv, mid)
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
end
def _racc_yyparse_rb( recv, mid, arg, c_debug )
def _racc_yyparse_rb(recv, mid, arg, c_debug)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
@ -179,7 +171,6 @@ module Racc
end
end
recv.__send__(mid) do |tok, val|
# $stderr.puts "rd: tok=#{tok}, val=#{val}"
unless tok
@racc_t = 0
else
@ -193,12 +184,7 @@ module Racc
act = action_table[i] and
action_check[i] == @racc_state[-1]
act = action_default[@racc_state[-1]]
# $stderr.puts "02: act=#{act}"
# $stderr.puts "curstate=#{@racc_state[-1]}"
else
# $stderr.puts "01: act=#{act}"
end
while act = _racc_evalact(act, arg)
;
end
@ -211,9 +197,6 @@ module Racc
act = action_table[i] and
action_check[i] == @racc_state[-1]
act = action_default[@racc_state[-1]]
# $stderr.puts "04: act=#{act}"
else
# $stderr.puts "03: act=#{act}"
end
while act = _racc_evalact(act, arg)
;
@ -227,13 +210,12 @@ module Racc
### common
###
def _racc_evalact( act, arg )
# $stderr.puts "ea: act=#{act}"
def _racc_evalact(act, arg)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
reduce_n, use_result, * = arg
nerr = 0 # tmp
nerr = 0 # tmp
if act > 0 and act < shift_n
#
@ -266,7 +248,7 @@ nerr = 0 # tmp
when 2 # yyaccept
return shift_n
else
raise RuntimeError, '[Racc Bug] unknown jump code'
raise '[Racc Bug] unknown jump code'
end
end
@ -304,7 +286,6 @@ nerr = 0 # tmp
break
end
end
throw :racc_end_parse, nil if @racc_state.size <= 1
@racc_state.pop
@racc_vstack.pop
@ -316,7 +297,7 @@ nerr = 0 # tmp
return act
else
raise RuntimeError, "[Racc Bug] unknown action #{act.inspect}"
raise "[Racc Bug] unknown action #{act.inspect}"
end
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
@ -324,7 +305,7 @@ nerr = 0 # tmp
nil
end
def _racc_do_reduce( arg, act )
def _racc_do_reduce(arg, act)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
@ -365,7 +346,7 @@ nerr = 0 # tmp
goto_default[k1]
end
def on_error( t, val, vstack )
def on_error(t, val, vstack)
raise ParseError, sprintf("\nparse error on value %s (%s)",
val.inspect, token_to_str(t) || '?')
end
@ -386,20 +367,20 @@ nerr = 0 # tmp
# for debugging output
#
def racc_read_token( t, tok, val )
def racc_read_token(t, tok, val)
@racc_debug_out.print 'read '
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
@racc_debug_out.puts val.inspect
@racc_debug_out.puts
end
def racc_shift( tok, tstack, vstack )
def racc_shift(tok, tstack, vstack)
@racc_debug_out.puts "shift #{racc_token2str tok}"
racc_print_stacks tstack, vstack
@racc_debug_out.puts
end
def racc_reduce( toks, sim, tstack, vstack )
def racc_reduce(toks, sim, tstack, vstack)
out = @racc_debug_out
out.print 'reduce '
if toks.empty?
@ -418,20 +399,20 @@ nerr = 0 # tmp
@racc_debug_out.puts
end
def racc_e_pop( state, tstack, vstack )
def racc_e_pop(state, tstack, vstack)
@racc_debug_out.puts 'error recovering mode: pop token'
racc_print_states state
racc_print_stacks tstack, vstack
@racc_debug_out.puts
end
def racc_next_state( curstate, state )
def racc_next_state(curstate, state)
@racc_debug_out.puts "goto #{curstate}"
racc_print_states state
@racc_debug_out.puts
end
def racc_print_stacks( t, v )
def racc_print_stacks(t, v)
out = @racc_debug_out
out.print ' ['
t.each_index do |i|
@ -440,19 +421,19 @@ nerr = 0 # tmp
out.puts ' ]'
end
def racc_print_states( s )
def racc_print_states(s)
out = @racc_debug_out
out.print ' ['
s.each {|st| out.print ' ', st }
out.puts ' ]'
end
def racc_token2str( tok )
def racc_token2str(tok)
self.class::Racc_token_to_s_table[tok] or
raise RuntimeError, "[Racc Bug] can't convert token #{tok} to string"
raise "[Racc Bug] can't convert token #{tok} to string"
end
def token_to_str( t )
def token_to_str(t)
self.class::Racc_token_to_s_table[t]
end