summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-10-09 10:07:22 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-12-09 20:50:41 +0900
commitf7a0f11c3650f7553dd1792e06e52643354c8316 (patch)
tree35989a6de0fc156b753cf4e9727fa35d586dbc48 /mrbgems/mruby-compiler
parent0011652a2875de7ea6979e16417514098fb71d89 (diff)
downloadmruby-f7a0f11c3650f7553dd1792e06e52643354c8316.tar.gz
mruby-f7a0f11c3650f7553dd1792e06e52643354c8316.zip
Parser refactoring on numbered parameters.
Now identifiers like `_1abc` are allowed.
Diffstat (limited to 'mrbgems/mruby-compiler')
-rw-r--r--mrbgems/mruby-compiler/core/parse.y42
1 files changed, 17 insertions, 25 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 061bbd58a..8ebf7dd81 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -856,7 +856,7 @@ setup_args(parser_state *p, node *a)
buf[0] = '_';
buf[1] = i+'0';
- buf[3] = '\0';
+ buf[2] = '\0';
sym = intern_cstr(buf);
args = cons(new_arg(p, sym), args);
p->locals->car = cons(nsym(sym), p->locals->car);
@@ -5893,30 +5893,6 @@ parser_yylex(parser_state *p)
case '_':
token_column = newtok(p);
- tokadd(p, c);
- c = nextc(p);
- if (ISDIGIT(c)) {
- int n = 0;
-
- while (c >= 0 && ISDIGIT(c)) {
- n *= 10;
- n += c - '0';
- tokadd(p, c);
- c = nextc(p);
- }
- pushback(p, c);
- if (n == 0) {
- yyerror(p, "_0 is not available");
- return 0;
- }
- if (n > NUMPARAM_MAX || n < 0) {
- yyerror(p, "too large numbered parameter");
- return 0;
- }
- pylval.num = n;
- p->lstate = EXPR_END;
- return tNUMPARAM;
- }
break;
default:
@@ -5975,6 +5951,22 @@ parser_yylex(parser_state *p)
result = tIVAR;
break;
+ case '_':
+ if (toklen(p) == 2 && ISDIGIT(tok(p)[1])) {
+ int n = tok(p)[1] - '0';
+ if (n == 0) {
+ yyerror(p, "_0 is not available");
+ return 0;
+ }
+ if (n > NUMPARAM_MAX) {
+ yyerror(p, "too large numbered parameter");
+ return 0;
+ }
+ pylval.num = n;
+ p->lstate = EXPR_END;
+ return tNUMPARAM;
+ }
+ /* fall through */
default:
if (toklast(p) == '!' || toklast(p) == '?') {
result = tFID;