From dd1527cfc8b1b68025b7311ae0ba97915ffab38a Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 20 Apr 2012 14:11:34 +0900 Subject: make %(foo) work --- src/parse.y | 1 + 1 file changed, 1 insertion(+) (limited to 'src/parse.y') diff --git a/src/parse.y b/src/parse.y index 5925b9a5e..b22dd10f6 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4228,6 +4228,7 @@ parser_yylex(parser_state *p) else if (term == '[') term = ']'; else if (term == '{') term = '}'; else if (term == '<') term = '>'; + p->sterm = term; #if 0 else paren = 0; #endif -- cgit v1.2.3 From 669cfc7f66cecf24156b0052fac291c98c4b10f5 Mon Sep 17 00:00:00 2001 From: lucas dicioccio Date: Sat, 21 Apr 2012 12:02:12 +0200 Subject: typo in the node's comment --- src/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parse.y') diff --git a/src/parse.y b/src/parse.y index b22dd10f6..2bc78f577 100644 --- a/src/parse.y +++ b/src/parse.y @@ -275,7 +275,7 @@ new_true(parser_state *p) return list1((node*)NODE_TRUE); } -// (:true) +// (:false) static node* new_false(parser_state *p) { -- cgit v1.2.3 From fc125524b2ece07fc70e782cc1a232d794dd4f6d Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sat, 21 Apr 2012 23:30:34 +0200 Subject: only increment position, if no error has occured --- src/parse.y | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/parse.y') diff --git a/src/parse.y b/src/parse.y index 2bc78f577..9ffe6d33d 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2976,12 +2976,16 @@ nextc(parser_state *p) c = *p->s++; } if (c == '\n') { - p->lineno++; - p->column = 0; + if (p->nerr < 1) { + p->lineno++; + p->column = 0; + } // must understand heredoc } else { - p->column++; + if (p->nerr < 1) { + p->column++; + } } return c; } -- cgit v1.2.3 From 9760b7f126cfd5bb8ab8764331ad876b8e23297c Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 22 Apr 2012 07:40:31 +0200 Subject: simple fix for underflow --- src/parse.y | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/parse.y') diff --git a/src/parse.y b/src/parse.y index 9ffe6d33d..62433a6bf 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2976,16 +2976,17 @@ nextc(parser_state *p) c = *p->s++; } if (c == '\n') { - if (p->nerr < 1) { + if (p->column < 0) { + p->column++; // pushback caused an underflow + } + else { p->lineno++; p->column = 0; } // must understand heredoc } else { - if (p->nerr < 1) { - p->column++; - } + p->column++; } return c; } -- cgit v1.2.3 From 844d7d49b3803f35ee102179e35de283df8e96c2 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 22 Apr 2012 08:53:55 +0200 Subject: allow errors & warning to be captured --- src/compile.h | 12 ++++++++++++ src/parse.y | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 4 deletions(-) (limited to 'src/parse.y') diff --git a/src/compile.h b/src/compile.h index f0e6b1874..212628deb 100644 --- a/src/compile.h +++ b/src/compile.h @@ -25,6 +25,12 @@ enum mrb_lex_state_enum { EXPR_MAX_STATE }; +struct mrb_parser_message { + int lineno; + int column; + char* message; +}; + struct mrb_parser_state { mrb_state *mrb; struct mrb_pool *pool; @@ -55,14 +61,20 @@ struct mrb_parser_state { void *ylval; int nerr; + int nwarn; mrb_ast_node *tree, *begin_tree; + int capture_errors; + struct mrb_parser_message error_buffer[10]; + struct mrb_parser_message warn_buffer[10]; + jmp_buf jmp; }; struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*); struct mrb_parser_state* mrb_parse_string(mrb_state*,char*); struct mrb_parser_state* mrb_parse_nstring(mrb_state*,char*,size_t); +struct mrb_parser_state* mrb_parse_nstring_ext(mrb_state*,char*,size_t); int mrb_generate_code(mrb_state*, mrb_ast_node*); int mrb_compile_file(mrb_state*,FILE*); diff --git a/src/parse.y b/src/parse.y index 62433a6bf..6e2696bd9 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2898,8 +2898,21 @@ none : /* none */ static void yyerror(parser_state *p, const char *s) { - fputs(s, stderr); - fputs("\n", stderr); + char* c; + size_t n; + + if (! p->capture_errors) { + fputs(s, stderr); + fputs("\n", stderr); + } + else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) { + n = strlen(s); + c = parser_palloc(p, n + 1); + memcpy(c, s, n + 1); + p->error_buffer[p->nerr].message = c; + p->error_buffer[p->nerr].lineno = p->lineno; + p->error_buffer[p->nerr].column = p->column; + } p->nerr++; } @@ -2915,8 +2928,22 @@ yyerror_i(parser_state *p, const char *fmt, int i) static void yywarn(parser_state *p, const char *s) { - fputs(s, stderr); - fputs("\n", stderr); + char* c; + size_t n; + + if (! p->capture_errors) { + fputs(s, stderr); + fputs("\n", stderr); + } + else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) { + n = strlen(s); + c = parser_palloc(p, n + 1); + memcpy(c, s, n + 1); + p->error_buffer[p->nwarn].message = c; + p->error_buffer[p->nwarn].lineno = p->lineno; + p->error_buffer[p->nwarn].column = p->column; + } + p->nwarn++; } static void @@ -4609,6 +4636,8 @@ parser_new(mrb_state *mrb) p->cmd_start = TRUE; p->in_def = p->in_single = FALSE; + p->capture_errors = NULL; + p->lineno = 1; #if defined(PARSER_TEST) || defined(PARSER_DEBUG) yydebug = 1; @@ -4646,6 +4675,22 @@ mrb_parse_nstring(mrb_state *mrb, char *s, size_t len) return p; } +parser_state* +mrb_parse_nstring_ext(mrb_state *mrb, char *s, size_t len) +{ + parser_state *p; + + p = parser_new(mrb); + if (!p) return 0; + p->s = s; + p->send = s + len; + p->f = NULL; + p->capture_errors = 1; + + start_parser(p); + return p; +} + parser_state* mrb_parse_string(mrb_state *mrb, char *s) { -- cgit v1.2.3