diff options
| author | Nobuyoshi Nakada <[email protected]> | 2014-04-30 10:27:05 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <[email protected]> | 2014-05-03 08:42:31 +0900 |
| commit | 854ae564a34910fe3bd13a83a3d4bfa10cf0d838 (patch) | |
| tree | a85dd32b1cc2c15a2d74e3c7d630cdba2016fa27 /src | |
| parent | 69c6ff7aa06045a3fdaf6a134041e9206cb95a9e (diff) | |
| download | mruby-854ae564a34910fe3bd13a83a3d4bfa10cf0d838.tar.gz mruby-854ae564a34910fe3bd13a83a3d4bfa10cf0d838.zip | |
fix embedded documents
tabs are allowed after `=begin` and `=end`.
raise `SyntaxError` if no =end is found.
Diffstat (limited to 'src')
| -rw-r--r-- | src/parse.y | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/parse.y b/src/parse.y index 7f1139a07..477305db4 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3417,15 +3417,15 @@ skip(parser_state *p, char term) } } -static mrb_bool -peek_n(parser_state *p, int c, int n) +static int +peekc_n(parser_state *p, int n) { node *list = 0; int c0; do { c0 = nextc(p); - if (c0 < 0) return FALSE; + if (c0 < 0) return c0; list = push(list, (node*)(intptr_t)c0); } while(n--); if (p->pb) { @@ -3434,8 +3434,13 @@ peek_n(parser_state *p, int c, int n) else { p->pb = list; } - if (c0 == c) return TRUE; - return FALSE; + return c0; +} + +static mrb_bool +peek_n(parser_state *p, int c, int n) +{ + return peekc_n(p, n) == c && c >= 0; } #define peek(p,c) peek_n((p), (c), 0) @@ -4189,14 +4194,20 @@ parser_yylex(parser_state *p) case '=': if (p->column == 1) { - if (peeks(p, "begin ") || peeks(p, "begin\n")) { - if (skips(p, "\n=end ")) { - goto retry; - } - if (skips(p, "\n=end\n")) { + static const char begin[] = "begin"; + static const char end[] = "\n=end"; + if (peeks(p, begin)) { + c = peekc_n(p, sizeof(begin)-1); + if (c < 0 || isspace(c)) { + do { + if (!skips(p, end)) { + yyerror(p, "embedded document meets end of file"); + return 0; + } + c = nextc_n(p, sizeof(end)-1); + } while (!(c < 0 || isspace(c))); goto retry; } - goto retry; } } if (p->lstate == EXPR_FNAME || p->lstate == EXPR_DOT) { |
