summaryrefslogtreecommitdiffhomepage
path: root/src/parse.y
diff options
context:
space:
mode:
authormimaki <[email protected]>2012-04-23 11:51:47 +0900
committermimaki <[email protected]>2012-04-23 11:51:47 +0900
commitc80487561f291e8239541687341b4d64a840c108 (patch)
treed4f7777cc91597cf880bed364df26066b9aaee8f /src/parse.y
parent835443614d21b13b27af3674d7f8cb9bf49c298b (diff)
parent3f0b98762d4a49beb7cc3f9cc8a8dfcee4aa5f6f (diff)
downloadmruby-c80487561f291e8239541687341b4d64a840c108.tar.gz
mruby-c80487561f291e8239541687341b4d64a840c108.zip
Merge branch 'master' of github.com:mruby/mruby
Conflicts: src/variable.c
Diffstat (limited to 'src/parse.y')
-rw-r--r--src/parse.y64
1 files changed, 57 insertions, 7 deletions
diff --git a/src/parse.y b/src/parse.y
index ef49338ac..2c02a31cb 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -281,7 +281,7 @@ new_true(parser_state *p)
return list1((node*)NODE_TRUE);
}
-// (:true)
+// (:false)
static node*
new_false(parser_state *p)
{
@@ -2904,8 +2904,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++;
}
@@ -2921,8 +2934,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
@@ -2982,8 +3009,13 @@ nextc(parser_state *p)
c = *p->s++;
}
if (c == '\n') {
- p->lineno++;
- p->column = 0;
+ if (p->column < 0) {
+ p->column++; // pushback caused an underflow
+ }
+ else {
+ p->lineno++;
+ p->column = 0;
+ }
// must understand heredoc
}
else {
@@ -4610,6 +4642,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;
@@ -4648,6 +4682,22 @@ mrb_parse_nstring(mrb_state *mrb, char *s, size_t len)
}
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)
{
return mrb_parse_nstring(mrb, s, strlen(s));