#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "jv.h"
#include "jv_dtoa.h"
#include "jv_parse.h"
return 0;
}
-jv jv_parse(const char* string) {
+jv jv_parse_sized(const char* string, int length) {
+ printf("'%s' [%d]", string, length);
struct jv_parser parser;
jv_parser_init(&parser);
const char* p = string;
char ch;
- while ((ch = *p++)) {
+ while (p < string + length) {
+ ch = *p++;
presult msg = scan(&parser, ch);
if (msg){
- printf("ERROR: %s (parsing [%s])\n", msg, string);
+ printf("ERROR: %s (parsing '%s')\n", msg, string);
return jv_null();
}
}
presult msg = finish(&parser);
if (msg) {
- printf("ERROR: %s (parsing [%s])\n", msg, string);
+ printf("ERROR: %s (parsing '%s')\n", msg, string);
return jv_null();
}
jv value = jv_copy(parser.next);
jv_parser_free(&parser);
return value;
}
+
+jv jv_parse(const char* string) {
+ return jv_parse_sized(string, strlen(string));
+}
"|=" { return SETPIPE; }
"."|"="|";"|"["|"]"|","|":"|"("|")"|"{"|"}"|"|"|"+"|"\$" { return yytext[0];}
-[[:digit:]]+ { yylval->literal = jv_number((double)atoi(yytext)); return LITERAL;}
+\"(\\.|[^\\"])*\" |
+[+-]?[0-9.]+([eE][+-]?[0-9]+)? {
+ yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;
+}
+
[[:alnum:]]+ { yylval->literal = jv_string(yytext); return IDENT;}
+
[ \n\t]+ {}
+
%%
/* perhaps these should be calls... */
/*
: IDENT ':' ExpD {
$$ = gen_dictpair(gen_op_const(LOADK, $1), $3);
}
+| LITERAL ':' ExpD {
+ assert(jv_get_kind($1) == JV_KIND_STRING);
+ $$ = gen_dictpair(gen_op_const(LOADK, $1), $3);
+ }
| IDENT {
$$ = gen_dictpair(gen_op_const(LOADK, jv_copy($1)),
gen_index(gen_noop(), gen_op_const(LOADK, $1)));