douglascrockford / json-c Goto Github PK
View Code? Open in Web Editor NEWJSON_checker
JSON_checker
At present, after encountering an open curly brace, the parser state is set to ST (expecting string). It would make more sense to set the state to KE (expecting key). And once you do that, you can eliminate the OB altogether with two small changes. As it is now:
white 1-9 ABCDF etc
space | { } [ ] : , " \ / + - . 0 | a b c d e f l n r s t u | E |*/
/*start GO*/ {GO,GO,-6,__,-5,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/*ok OK*/ {OK,OK,__,-8,__,-7,__,-3,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/*object OB*/ {OB,OB,__,-9,__,__,__,__,ST,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/*key KE*/ {KE,KE,__,__,__,__,__,__,ST,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/* { */ case -6:
if (!push(jc, MODE_KEY)) {
return reject(jc);
}
jc->state = OB;
break;
After eliminating OB state:
white 1-9 ABCDF etc
space | { } [ ] : , " \ / + - . 0 | a b c d e f l n r s t u | E |*/
/*start GO*/ {GO,GO,-6,__,-5,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/*ok OK*/ {OK,OK,__,-8,__,-7,__,-3,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/*key KE*/ {KE,KE,__,-9,__,__,__,__,ST,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__},
/* { */ case -6:
if (!push(jc, MODE_KEY)) {
return reject(jc);
}
jc->state = KE; // transition directly to KE (expecting key) state
break;
It seems the so-called first commit is actually not the first commit, rendering this library totally unusable!
Hi.
I just wanted to mention this:
JSON_checker.c:289:19: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare] if (jc->valid != GOOD) { ~~~~~~~~~ ^ ~~~~ JSON_checker.c:415:19: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare] if (jc->valid != GOOD) { ~~~~~~~~~ ^ ~~~~
It's not a big deal really, well…
I'm unsure of what you're trying to accomplish.
0xBABAB00E = 3132796942
Which is too big for an int so it overflows to -1162170354… Which makes sense.
Anyway all of that to say you could have used #define GOOD (int) 0xBABAB00E
At present, it is difficult to know if a change to JSON_checker.c breaks anything or not. It would be useful to include a validation tests, perhaps by adapting the examples in https://github.com/nst/JSONTestSuite, which contains a trove of test cases, classified as:
As you said "It could be adapted to produce a very fast JSON parser.",I'd like to implement a lightweight JSON parser based on it, but then I find it a little difficult.
So is there someone who has already done this job? Or do you have some suggestion to make such a JSON parser?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.