summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-17 04:30:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-17 04:30:44 +0000
commit25a2e870d4d2bcc7326bbce65998e0f9c96e01a6 (patch)
tree690616e21303d8711a4e765c628a7e9d3517066d /parse.y
parent27e1b2477601804e56f256bbd3b12b887c2bea9a (diff)
downloadbundler-25a2e870d4d2bcc7326bbce65998e0f9c96e01a6.tar.gz
parse.y: separate from parse_ident
* parse.y (tokadd_ident, tokenize_ident): extract from parse_ident(). * parse.y (parse_gvar, parse_atmark): move tokenization from parse_ident(). * parse.y (parse_ident): now deals with non-sigil names only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y222
1 files changed, 108 insertions, 114 deletions
diff --git a/parse.y b/parse.y
index ec9114c427..e17307002c 100644
--- a/parse.y
+++ b/parse.y
@@ -7368,6 +7368,29 @@ parse_percent(struct parser_params *parser, const int space_seen, const enum lex
}
static int
+tokadd_ident(struct parser_params *parser, int c)
+{
+ do {
+ if (tokadd_mbchar(c) == -1) return -1;
+ c = nextc();
+ } while (parser_is_identchar());
+ pushback(c);
+ return 0;
+}
+
+static void
+tokenize_ident(struct parser_params *parser, const enum lex_state_e last_state)
+{
+ ID ident = TOK_INTERN();
+
+ set_yylval_name(ident);
+ if (!IS_lex_state_for(last_state, EXPR_DOT|EXPR_FNAME) &&
+ is_local_id(ident) && lvar_defined(ident)) {
+ lex_state = EXPR_END;
+ }
+}
+
+static int
parse_gvar(struct parser_params *parser, const enum lex_state_e last_state)
{
register int c;
@@ -7457,7 +7480,11 @@ parse_gvar(struct parser_params *parser, const enum lex_state_e last_state)
case '0':
tokadd('$');
}
- return -c;
+
+ if (tokadd_ident(parser, c)) return 0;
+ lex_state = EXPR_END;
+ tokenize_ident(parser, last_state);
+ return tGVAR;
}
static int
@@ -7483,7 +7510,11 @@ parse_atmark(struct parser_params *parser, const enum lex_state_e last_state)
}
return 0;
}
- return -c;
+
+ if (tokadd_ident(parser, c)) return 0;
+ lex_state = EXPR_END;
+ tokenize_ident(parser, last_state);
+ return result;
}
static int
@@ -7498,131 +7529,100 @@ parse_ident(struct parser_params *parser, int c, int cmd_state)
if (tokadd_mbchar(c) == -1) return 0;
c = nextc();
} while (parser_is_identchar());
- switch (tok()[0]) {
- case '@': case '$':
+ if ((c == '!' || c == '?') && !peek('=')) {
+ tokadd(c);
+ }
+ else {
pushback(c);
- break;
- default:
- if ((c == '!' || c == '?') && !peek('=')) {
- tokadd(c);
- }
- else {
- pushback(c);
- }
}
tokfix();
- switch (tok()[0]) {
- case '$':
- lex_state = EXPR_END;
- result = tGVAR;
- break;
-
- case '@':
- lex_state = EXPR_END;
- if (tok()[1] == '@')
- result = tCVAR;
- else
- result = tIVAR;
- break;
-
- default:
- if (toklast() == '!' || toklast() == '?') {
- result = tFID;
- }
- else {
- if (IS_lex_state(EXPR_FNAME)) {
- register int c = nextc();
- if (c == '=' && !peek('~') && !peek('>') &&
- (!peek('=') || (peek_n('>', 1)))) {
- result = tIDENTIFIER;
- tokadd(c);
- tokfix();
- }
- else {
- pushback(c);
- }
- }
- if (result == 0 && ISUPPER(tok()[0])) {
- result = tCONSTANT;
+ if (toklast() == '!' || toklast() == '?') {
+ result = tFID;
+ }
+ else {
+ if (IS_lex_state(EXPR_FNAME)) {
+ register int c = nextc();
+ if (c == '=' && !peek('~') && !peek('>') &&
+ (!peek('=') || (peek_n('>', 1)))) {
+ result = tIDENTIFIER;
+ tokadd(c);
+ tokfix();
}
else {
- result = tIDENTIFIER;
+ pushback(c);
}
}
-
- if (IS_LABEL_POSSIBLE()) {
- if (IS_LABEL_SUFFIX(0)) {
- lex_state = EXPR_LABELARG;
- nextc();
- set_yylval_name(TOK_INTERN());
- return tLABEL;
- }
+ if (result == 0 && ISUPPER(tok()[0])) {
+ result = tCONSTANT;
}
- if (mb == ENC_CODERANGE_7BIT && !IS_lex_state(EXPR_DOT)) {
- const struct kwtable *kw;
-
- /* See if it is a reserved word. */
- kw = rb_reserved_word(tok(), toklen());
- if (kw) {
- enum lex_state_e state = lex_state;
- lex_state = kw->state;
- if (IS_lex_state_for(state, EXPR_FNAME)) {
- set_yylval_name(rb_intern(kw->name));
- return kw->id[0];
- }
- if (IS_lex_state(EXPR_BEG)) {
- command_start = TRUE;
- }
- if (kw->id[0] == keyword_do) {
- if (lpar_beg && lpar_beg == paren_nest) {
- lpar_beg = 0;
- --paren_nest;
- return keyword_do_LAMBDA;
- }
- if (COND_P()) return keyword_do_cond;
- if (CMDARG_P() && !IS_lex_state_for(state, EXPR_CMDARG))
- return keyword_do_block;
- if (IS_lex_state_for(state, (EXPR_BEG | EXPR_ENDARG)))
- return keyword_do_block;
- return keyword_do;
- }
- if (IS_lex_state_for(state, (EXPR_BEG | EXPR_VALUE)))
- return kw->id[0];
- else {
- if (kw->id[0] != kw->id[1])
- lex_state = EXPR_BEG;
- return kw->id[1];
- }
- }
+ else {
+ result = tIDENTIFIER;
}
+ }
- if (IS_lex_state(EXPR_BEG_ANY | EXPR_ARG_ANY | EXPR_DOT)) {
- if (cmd_state) {
- lex_state = EXPR_CMDARG;
+ if (IS_LABEL_POSSIBLE()) {
+ if (IS_LABEL_SUFFIX(0)) {
+ lex_state = EXPR_LABELARG;
+ nextc();
+ set_yylval_name(TOK_INTERN());
+ return tLABEL;
+ }
+ }
+ if (mb == ENC_CODERANGE_7BIT && !IS_lex_state(EXPR_DOT)) {
+ const struct kwtable *kw;
+
+ /* See if it is a reserved word. */
+ kw = rb_reserved_word(tok(), toklen());
+ if (kw) {
+ enum lex_state_e state = lex_state;
+ lex_state = kw->state;
+ if (IS_lex_state_for(state, EXPR_FNAME)) {
+ set_yylval_name(rb_intern(kw->name));
+ return kw->id[0];
+ }
+ if (IS_lex_state(EXPR_BEG)) {
+ command_start = TRUE;
}
+ if (kw->id[0] == keyword_do) {
+ if (lpar_beg && lpar_beg == paren_nest) {
+ lpar_beg = 0;
+ --paren_nest;
+ return keyword_do_LAMBDA;
+ }
+ if (COND_P()) return keyword_do_cond;
+ if (CMDARG_P() && !IS_lex_state_for(state, EXPR_CMDARG))
+ return keyword_do_block;
+ if (IS_lex_state_for(state, (EXPR_BEG | EXPR_ENDARG)))
+ return keyword_do_block;
+ return keyword_do;
+ }
+ if (IS_lex_state_for(state, (EXPR_BEG | EXPR_VALUE)))
+ return kw->id[0];
else {
- lex_state = EXPR_ARG;
+ if (kw->id[0] != kw->id[1])
+ lex_state = EXPR_BEG;
+ return kw->id[1];
}
}
- else if (lex_state == EXPR_FNAME) {
- lex_state = EXPR_ENDFN;
+ }
+
+ if (IS_lex_state(EXPR_BEG_ANY | EXPR_ARG_ANY | EXPR_DOT)) {
+ if (cmd_state) {
+ lex_state = EXPR_CMDARG;
}
else {
- lex_state = EXPR_END;
+ lex_state = EXPR_ARG;
}
}
-
- {
- ID ident = TOK_INTERN();
-
- set_yylval_name(ident);
- if (!IS_lex_state_for(last_state, EXPR_DOT|EXPR_FNAME) &&
- is_local_id(ident) && lvar_defined(ident)) {
- lex_state = EXPR_END;
- }
+ else if (lex_state == EXPR_FNAME) {
+ lex_state = EXPR_ENDFN;
+ }
+ else {
+ lex_state = EXPR_END;
}
+ tokenize_ident(parser, last_state);
return result;
}
@@ -8244,16 +8244,10 @@ parser_yylex(struct parser_params *parser)
return parse_percent(parser, space_seen, last_state);
case '$':
- c = parse_gvar(parser, last_state);
- if (c >= 0) return c;
- c = -c;
- break;
+ return parse_gvar(parser, last_state);
case '@':
- c = parse_atmark(parser, last_state);
- if (c >= 0) return c;
- c = -c;
- break;
+ return parse_atmark(parser, last_state);
case '_':
if (was_bol() && whole_match_p("__END__", 7, 0)) {