Project

General

Profile

Backport #1183 » label_hash.patch

knu (Akinori MUSHA), 02/20/2009 07:17 PM

View differences:

parse.y (working copy)
EXPR_FNAME, /* ignore newline, no reserved words. */
EXPR_DOT, /* right after `.' or `::', no reserved words. */
EXPR_CLASS, /* immediate after `class', no here document. */
EXPR_VALUE /* alike EXPR_BEG but label is disallowed. */
} lex_state;
static NODE *lex_strterm;
......
k__LINE__
k__FILE__
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <node> tINTEGER tFLOAT tSTRING_CONTENT
%token <node> tNTH_REF tBACK_REF
%token <num> tREGEXP_END
......
{
$$ = list_append(NEW_LIST($1), $3);
}
| tLABEL arg_value
{
$$ = list_append(NEW_LIST(NEW_LIT(ID2SYM($1))), $2);
}
;
operation : tIDENTIFIER
......
}
#define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
#define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_CLASS)
#define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || \
lex_state == EXPR_VALUE || lex_state == EXPR_CLASS)
static int
yylex()
......
case EXPR_FNAME:
case EXPR_DOT:
case EXPR_CLASS:
case EXPR_VALUE:
goto retry;
default:
break;
......
case '?':
if (lex_state == EXPR_END || lex_state == EXPR_ENDARG) {
lex_state = EXPR_BEG;
lex_state = EXPR_VALUE;
return '?';
}
c = nextc();
......
}
ternary:
pushback(c);
lex_state = EXPR_BEG;
lex_state = EXPR_VALUE;
return '?';
}
else if (ismbchar(c)) {
......
}
}
if ((lex_state == EXPR_BEG && !cmd_state) ||
lex_state == EXPR_ARG ||
lex_state == EXPR_CMDARG) {
if (peek(':') && !(lex_p + 1 < lex_pend && lex_p[1] == ':')) {
lex_state = EXPR_BEG;
nextc();
yylval.id = rb_intern(tok());
return tLABEL;
}
}
if (lex_state != EXPR_DOT) {
const struct kwtable *kw;
......
return kDO_BLOCK;
return kDO;
}
if (state == EXPR_BEG)
if (state == EXPR_BEG || state == EXPR_VALUE)
return kw->id[0];
else {
if (kw->id[0] != kw->id[1])
......
}
}
if (lex_state == EXPR_BEG ||
lex_state == EXPR_MID ||
if (IS_BEG() ||
lex_state == EXPR_DOT ||
lex_state == EXPR_ARG ||
lex_state == EXPR_CLASS ||
lex_state == EXPR_CMDARG) {
IS_ARG()) {
if (cmd_state) {
lex_state = EXPR_CMDARG;
}
NEWS (working copy)
specific directories such as library directories, ri directories and
gem directories.
=== Language core changes
* new syntax
* New literal syntax for hash is introduced, which is also
applicable to hash style arguments.
colormap = { apple: 'red', banana: 'yellow', melon: 'green' }
FileUtils.mkdir 'tmp', mode: 0700
The lines above are equivalent to the lines below:
colormap = { :apple => 'red', :banana => 'yellow', :melon => 'green' }
FileUtils.mkdir 'tmp', :mode => 0700
=== Library updates (outstanding ones only)
* builtin classes
ChangeLog (working copy)
Thu Feb 19 17:32:59 2009 Akinori MUSHA <knu@iDaemons.org>
* parse.y: Backport the new literal syntax for hash and hash style
arguments; based on the patch by Brent Roman <brent@mbari.org>
in [ruby-core:21984].
Thu Feb 19 14:22:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (create_makefile): added phony targets.
(1-1/2)