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

* parse.y [ripper]: emit lexer-event values to the parser.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2004-10-31 05:22:58 +00:00
parent 1c0b6e5829
commit cf49a01eae
2 changed files with 53 additions and 60 deletions

View file

@ -1,3 +1,8 @@
Sun Oct 31 14:18:56 2004 Minero Aoki <aamine@loveruby.net>
* parse.y [ripper]: emit lexer-event values to the parser
(still incomplete).
Sat Oct 30 15:24:41 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp> Sat Oct 30 15:24:41 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: add WIN32OLE_TYPELIB class. add * ext/win32ole/win32ole.c: add WIN32OLE_TYPELIB class. add

108
parse.y
View file

@ -146,7 +146,6 @@ struct parser_params {
char *parser_lex_pend; char *parser_lex_pend;
int parser_heredoc_end; int parser_heredoc_end;
int parser_command_start; int parser_command_start;
/*VALUE parser_ruby_debug_lines;*/
int parser_lex_gets_ptr; int parser_lex_gets_ptr;
VALUE (*parser_lex_gets) _((struct parser_params*,VALUE)); VALUE (*parser_lex_gets) _((struct parser_params*,VALUE));
struct local_vars *parser_lvtbl; struct local_vars *parser_lvtbl;
@ -190,7 +189,6 @@ static int parser_yyerror _((struct parser_params*, const char*));
#define lex_pend (parser->parser_lex_pend) #define lex_pend (parser->parser_lex_pend)
#define heredoc_end (parser->parser_heredoc_end) #define heredoc_end (parser->parser_heredoc_end)
#define command_start (parser->parser_command_start) #define command_start (parser->parser_command_start)
/*#define ruby_debug_lines (parser->parser_ruby_debug_lines)*/
#define lex_gets_ptr (parser->parser_lex_gets_ptr) #define lex_gets_ptr (parser->parser_lex_gets_ptr)
#define lex_gets (parser->parser_lex_gets) #define lex_gets (parser->parser_lex_gets)
#define lvtbl (parser->parser_lvtbl) #define lvtbl (parser->parser_lvtbl)
@ -365,9 +363,9 @@ static VALUE ripper_id2sym _((ID));
#endif /* RIPPER */ #endif /* RIPPER */
#ifndef RIPPER #ifndef RIPPER
#define symbol(id) id # define ifndef_ripper(x) x
#else #else
#define symbol(id) ripper_id2sym(id) # define ifndef_ripper(x)
#endif #endif
#ifndef RIPPER #ifndef RIPPER
@ -1544,32 +1542,32 @@ undef_list : fitem
} }
; ;
op : '|' { $$ = symbol('|'); } op : '|' { ifndef_ripper($$ = '|'); }
| '^' { $$ = symbol('^'); } | '^' { ifndef_ripper($$ = '^'); }
| '&' { $$ = symbol('&'); } | '&' { ifndef_ripper($$ = '&'); }
| tCMP { $$ = symbol(tCMP); } | tCMP { ifndef_ripper($$ = tCMP); }
| tEQ { $$ = symbol(tEQ); } | tEQ { ifndef_ripper($$ = tEQ); }
| tEQQ { $$ = symbol(tEQQ); } | tEQQ { ifndef_ripper($$ = tEQQ); }
| tMATCH { $$ = symbol(tMATCH); } | tMATCH { ifndef_ripper($$ = tMATCH); }
| '>' { $$ = symbol('>'); } | '>' { ifndef_ripper($$ = '>'); }
| tGEQ { $$ = symbol(tGEQ); } | tGEQ { ifndef_ripper($$ = tGEQ); }
| '<' { $$ = symbol('<'); } | '<' { ifndef_ripper($$ = '<'); }
| tLEQ { $$ = symbol(tLEQ); } | tLEQ { ifndef_ripper($$ = tLEQ); }
| tLSHFT { $$ = symbol(tLSHFT); } | tLSHFT { ifndef_ripper($$ = tLSHFT); }
| tRSHFT { $$ = symbol(tRSHFT); } | tRSHFT { ifndef_ripper($$ = tRSHFT); }
| '+' { $$ = symbol('+'); } | '+' { ifndef_ripper($$ = '+'); }
| '-' { $$ = symbol('-'); } | '-' { ifndef_ripper($$ = '-'); }
| '*' { $$ = symbol('*'); } | '*' { ifndef_ripper($$ = '*'); }
| tSTAR { $$ = symbol('*'); } | tSTAR { ifndef_ripper($$ = '*'); }
| '/' { $$ = symbol('/'); } | '/' { ifndef_ripper($$ = '/'); }
| '%' { $$ = symbol('%'); } | '%' { ifndef_ripper($$ = '%'); }
| tPOW { $$ = symbol(tPOW); } | tPOW { ifndef_ripper($$ = tPOW); }
| '~' { $$ = symbol('~'); } | '~' { ifndef_ripper($$ = '~'); }
| tUPLUS { $$ = symbol(tUPLUS); } | tUPLUS { ifndef_ripper($$ = tUPLUS); }
| tUMINUS { $$ = symbol(tUMINUS); } | tUMINUS { ifndef_ripper($$ = tUMINUS); }
| tAREF { $$ = symbol(tAREF); } | tAREF { ifndef_ripper($$ = tAREF); }
| tASET { $$ = symbol(tASET); } | tASET { ifndef_ripper($$ = tASET); }
| '`' { $$ = symbol('`'); } | '`' { ifndef_ripper($$ = '`'); }
; ;
reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND
@ -3710,12 +3708,12 @@ variable : tIDENTIFIER
| tGVAR | tGVAR
| tCONSTANT | tCONSTANT
| tCVAR | tCVAR
| kNIL {$$ = symbol(kNIL);} | kNIL {ifndef_ripper($$ = kNIL);}
| kSELF {$$ = symbol(kSELF);} | kSELF {ifndef_ripper($$ = kSELF);}
| kTRUE {$$ = symbol(kTRUE);} | kTRUE {ifndef_ripper($$ = kTRUE);}
| kFALSE {$$ = symbol(kFALSE);} | kFALSE {ifndef_ripper($$ = kFALSE);}
| k__FILE__ {$$ = symbol(k__FILE__);} | k__FILE__ {ifndef_ripper($$ = k__FILE__);}
| k__LINE__ {$$ = symbol(k__LINE__);} | k__LINE__ {ifndef_ripper($$ = k__LINE__);}
; ;
var_ref : variable var_ref : variable
@ -4137,12 +4135,12 @@ operation3 : tIDENTIFIER
dot_or_colon : '.' dot_or_colon : '.'
/*%c%*/ /*%c%*/
/*%c /*%c
{ $$ = ripper_id2sym('.'); } { $$ = $<val>1; }
%*/ %*/
| tCOLON2 | tCOLON2
/*%c%*/ /*%c%*/
/*%c /*%c
{ $$ = ripper_intern("::"); } { $$ = $<val>1; }
%*/ %*/
; ;
@ -4220,11 +4218,15 @@ static int parser_here_document _((struct parser_params*,NODE*));
# define set_yylval_num(x) yylval.num = x # define set_yylval_num(x) yylval.num = x
# define set_yylval_id(x) yylval.id = x # define set_yylval_id(x) yylval.id = x
# define set_yylval_literal(x) yylval.node = NEW_LIT(x) # define set_yylval_literal(x) yylval.node = NEW_LIT(x)
# define set_yylval_node(x) yylval.node = x
# define yylval_id() yylval.id
#else #else
# define set_yylval_str(x) yylval.val = x # define set_yylval_str(x) x
# define set_yylval_num(x) yylval.val = INT2NUM(x) # define set_yylval_num(x) x
# define set_yylval_id(x) yylval.val = ripper_id2sym(x) # define set_yylval_id(x) x
# define set_yylval_literal(x) yylval.val = x # define set_yylval_literal(x) x
# define set_yylval_node(x) x
# define yylval_id() SYM2ID(yylval.val)
#endif #endif
#ifdef RIPPER #ifdef RIPPER
@ -6214,7 +6216,7 @@ parser_yylex(parser)
tokadd(c); tokadd(c);
tokfix(); tokfix();
set_yylval_id(rb_intern(tok())); set_yylval_id(rb_intern(tok()));
if (!is_global_id(yylval.id)) { if (!is_global_id(yylval_id())) {
rb_compile_error(PARSER_ARG "invalid global variable `%s'", rb_id2name(yylval.id)); rb_compile_error(PARSER_ARG "invalid global variable `%s'", rb_id2name(yylval.id));
return 0; return 0;
} }
@ -6224,17 +6226,7 @@ parser_yylex(parser)
case '`': /* $`: string before last match */ case '`': /* $`: string before last match */
case '\'': /* $': string after last match */ case '\'': /* $': string after last match */
case '+': /* $+: string matches last paren. */ case '+': /* $+: string matches last paren. */
#ifndef RIPPER set_yylval_node(NEW_BACK_REF(c));
yylval.node = NEW_BACK_REF(c);
#else
{
char buf[4];
buf[0] = '$';
buf[1] = c;
buf[2] = '\0';
yylval.val = ripper_intern(buf);
}
#endif
return tBACK_REF; return tBACK_REF;
case '1': case '2': case '3': case '1': case '2': case '3':
@ -6247,11 +6239,7 @@ parser_yylex(parser)
} while (ISDIGIT(c)); } while (ISDIGIT(c));
pushback(c); pushback(c);
tokfix(); tokfix();
#ifndef RIPPER set_yylval_node(NEW_NTH_REF(atoi(tok()+1)));
yylval.node = NEW_NTH_REF(atoi(tok()+1));
#else
yylval.val = ripper_intern(tok());
#endif
return tNTH_REF; return tNTH_REF;
default: default:
@ -6406,7 +6394,7 @@ parser_yylex(parser)
if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) { if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
lex_state = EXPR_BEG; lex_state = EXPR_BEG;
nextc(); nextc();
yylval.id = rb_intern(tok()); set_yylval_id(rb_intern(tok()));
return tLABEL; return tLABEL;
} }
} }