From 854ae564a34910fe3bd13a83a3d4bfa10cf0d838 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 30 Apr 2014 10:27:05 +0900 Subject: fix embedded documents tabs are allowed after `=begin` and `=end`. raise `SyntaxError` if no =end is found. --- src/parse.y | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/parse.y') 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) { -- cgit v1.2.3