ext/json/ext/parser/parser.rl in json_pure-1.1.2 vs ext/json/ext/parser/parser.rl in json_pure-1.1.3
- old
+ new
@@ -1,7 +1,5 @@
-/* vim: set cin et sw=4 ts=4: */
-
#include "ruby.h"
#include "re.h"
#include "st.h"
#include "unicode.h"
@@ -73,23 +71,23 @@
action parse_value {
VALUE v = Qnil;
char *np = JSON_parse_value(json, fpc, pe, &v);
if (np == NULL) {
- fbreak;
+ fhold; fbreak;
} else {
rb_hash_aset(*result, last_name, v);
fexec np;
}
}
action parse_name {
char *np = JSON_parse_string(json, fpc, pe, &last_name);
- if (np == NULL) fbreak; else fexec np;
+ if (np == NULL) { fhold; fbreak; } else fexec np;
}
- action exit { fbreak; }
+ action exit { fhold; fbreak; }
a_pair = ignore* begin_name >parse_name
ignore* name_separator ignore*
begin_value >parse_value;
@@ -145,60 +143,60 @@
}
action parse_nan {
if (json->allow_nan) {
*result = CNaN;
} else {
- rb_raise(eParserError, "unexpected token at '%s'", p - 2);
+ rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
}
}
action parse_infinity {
if (json->allow_nan) {
*result = CInfinity;
} else {
- rb_raise(eParserError, "unexpected token at '%s'", p - 8);
+ rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
}
}
action parse_string {
char *np = JSON_parse_string(json, fpc, pe, result);
- if (np == NULL) fbreak; else fexec np;
+ if (np == NULL) { fhold; fbreak; } else fexec np;
}
action parse_number {
char *np;
if(pe > fpc + 9 && !strncmp(MinusInfinity, fpc, 9)) {
if (json->allow_nan) {
*result = CMinusInfinity;
fexec p + 10;
- fbreak;
+ fhold; fbreak;
} else {
- rb_raise(eParserError, "unexpected token at '%s'", p);
+ rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
}
}
np = JSON_parse_float(json, fpc, pe, result);
if (np != NULL) fexec np;
np = JSON_parse_integer(json, fpc, pe, result);
if (np != NULL) fexec np;
- fbreak;
+ fhold; fbreak;
}
action parse_array {
char *np;
- json->current_nesting += 1;
+ json->current_nesting++;
np = JSON_parse_array(json, fpc, pe, result);
- json->current_nesting -= 1;
- if (np == NULL) fbreak; else fexec np;
+ json->current_nesting--;
+ if (np == NULL) { fhold; fbreak; } else fexec np;
}
action parse_object {
char *np;
- json->current_nesting += 1;
+ json->current_nesting++;
np = JSON_parse_object(json, fpc, pe, result);
- json->current_nesting -= 1;
- if (np == NULL) fbreak; else fexec np;
+ json->current_nesting--;
+ if (np == NULL) { fhold; fbreak; } else fexec np;
}
- action exit { fbreak; }
+ action exit { fhold; fbreak; }
main := (
Vnull @parse_null |
Vfalse @parse_false |
Vtrue @parse_true |
@@ -228,11 +226,11 @@
%%{
machine JSON_integer;
write data;
- action exit { fbreak; }
+ action exit { fhold; fbreak; }
main := '-'? ('0' | [1-9][0-9]*) (^[0-9] @exit);
}%%
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -256,11 +254,11 @@
machine JSON_float;
include JSON_common;
write data;
- action exit { fbreak; }
+ action exit { fhold; fbreak; }
main := '-'? (
(('0' | [1-9][0-9]*) '.' [0-9]+ ([Ee] [+\-]?[0-9]+)?)
| (('0' | [1-9][0-9]*) ([Ee] [+\-]?[0-9]+))
) (^[0-9Ee.\-] @exit );
@@ -292,18 +290,18 @@
action parse_value {
VALUE v = Qnil;
char *np = JSON_parse_value(json, fpc, pe, &v);
if (np == NULL) {
- fbreak;
+ fhold; fbreak;
} else {
rb_ary_push(*result, v);
fexec np;
}
}
- action exit { fbreak; }
+ action exit { fhold; fbreak; }
next_element = value_separator ignore* begin_value >parse_value;
main := begin_array ignore*
((begin_value >parse_value ignore*)
@@ -324,11 +322,11 @@
%% write exec;
if(cs >= JSON_array_first_final) {
return p + 1;
} else {
- rb_raise(eParserError, "unexpected token at '%s'", p);
+ rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
}
}
static VALUE json_string_unescape(char *p, char *pe)
{
@@ -392,14 +390,14 @@
write data;
action parse_string {
*result = json_string_unescape(json->memo + 1, p);
- if (NIL_P(*result)) fbreak; else fexec p + 1;
+ if (NIL_P(*result)) { fhold; fbreak; } else fexec p + 1;
}
- action exit { fbreak; }
+ action exit { fhold; fbreak; }
main := '"' ((^(["\\] | 0..0x1f) | '\\'["\\/bfnrt] | '\\u'[0-9a-fA-F]{4} | '\\'^(["\\/bfnrtu]|0..0x1f))* %parse_string) '"' @exit;
}%%
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -428,18 +426,18 @@
action parse_object {
char *np;
json->current_nesting = 1;
np = JSON_parse_object(json, fpc, pe, &result);
- if (np == NULL) fbreak; else fexec np;
+ if (np == NULL) { fhold; fbreak; } else fexec np;
}
action parse_array {
char *np;
json->current_nesting = 1;
np = JSON_parse_array(json, fpc, pe, &result);
- if (np == NULL) fbreak; else fexec np;
+ if (np == NULL) { fhold; fbreak; } else fexec np;
}
main := ignore* (
begin_object >parse_object |
begin_array >parse_array
@@ -571,11 +569,11 @@
%% write exec;
if (cs >= JSON_first_final && p == pe) {
return result;
} else {
- rb_raise(eParserError, "unexpected token at '%s'", p);
+ rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
}
}
inline static JSON_Parser *JSON_allocate()
{
@@ -613,9 +611,10 @@
return rb_str_dup(json->Vsource);
}
void Init_parser()
{
+ rb_require("json/common");
mJSON = rb_define_module("JSON");
mExt = rb_define_module_under(mJSON, "Ext");
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
eParserError = rb_path2class("JSON::ParserError");
eNestingError = rb_path2class("JSON::NestingError");