Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
cf6e7966
Commit
cf6e7966
authored
Apr 22, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #35 from fceller/master
simple fix for underflow / capture errors and warnings
parents
7feb68eb
844d7d49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
6 deletions
+68
-6
src/compile.h
src/compile.h
+12
-0
src/parse.y
src/parse.y
+56
-6
No files found.
src/compile.h
View file @
cf6e7966
...
...
@@ -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
*
);
...
...
src/parse.y
View file @
cf6e7966
...
...
@@ -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
...
...
@@ -2976,8 +3003,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 {
...
...
@@ -4604,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;
...
...
@@ -4641,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)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment