| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
| |
There is no such thing as a 'JsonArrary' type.
|
|
|
|
|
|
|
|
| |
When parsing an array with a JsonParser with the debugging notes
enabled, we get an erroneous increment of the idx variable - which is
then passed to the JsonParser::array-element signal.
Thanks to: Michael Stapelberg <michael@stapelberg.de>
|
|
|
|
|
|
| |
We identify a missing ':' separator between an object member name and
its value, so it would be a good thing to actually have an error code
for that.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The array and object parsing logic in JsonParser has clearly exploded
beyond control: a simple tightening of the JSON validation almost broke
the parser in two. It it is time to...
<cue Christopher Lee voice-over>
REFACTOR THE CODE!
</cue Christopher Lee voice-over>
This time, we should be following the JSON state machine and try to do
more prediction of the next state based on peeking the next token.
The code is fairly cleaner, now; and, most of all, still passes the
validation test suite - which is, you know... nice.
|
|
|
|
|
|
|
|
|
| |
The JsonScanner error reporting mechanism, which is basically
GScanner's, sucks beyond belief. In order to report an error code we
need to store it inside the JsonParser private structure and then use it
when creating the GError inside the error handler.
This, frankly, is quite stupid.
|
|
|
|
|
|
| |
The main switch inside json_parse_statement() is re-implementing the
bare value parsing that is also provided by json_parse_value(). We
should kill it off to avoid redundant code.
|
|
|
|
| |
Print out the values we are parsing, for debug purposes.
|
|
|
|
|
|
| |
We are doing some of the work twice, especially when dealing with the
trailing commas detection and the unknown tokens after an array element
or an object member definition.
|
|
|
|
|
|
| |
Apparently, some breakage crept in JsonParser which allowed invalid JSON
to actually pass. For instance: trailing and missing commas, invalid
barewords and wrong array and object closing braces.
|
|
|
|
|
|
|
| |
• Fix the transfer rules for JsonNode, JsonObject and JsonArray
getters.
• Annotate the methods returning lists
|
|
|
|
|
| |
A missing get_next_token() prevents getting the contents of
the tokenizer in order to place them into the JsonNode.
|
|
|
|
|
|
| |
When parsing a value embedded in a Json Object or Array we need to
return the right expected token so that the generated syntax error
will be correct.
|
| |
|
|
|
|
|
| |
Add the setter for JsonNode:parent, to be used in JsonParser instead
of directly accessing the JsonNode structure.
|
|
|
|
|
| |
The code that parses a value within an object and an array should
be moved to its own function to avoid duplication.
|
|
|
|
| |
Clean up some notes, and add introspection annotations where needed.
|
|
|
|
|
|
|
|
| |
We switched everything to 64 bit integers but then I forgot to
enable the support for actually making the tokenizer store the
parsed integers into a 64 bit value.
Bad Emmanuele, no cookie for you.
|
|
|
|
|
|
|
|
| |
The tokenizer is not advanced when we peek a base value and return.
This causes an endless loop which terminates only if the OOM killer
in the kernel gets the right process.
Thanks to Thomas Weidner for catching and reporting the issue.
|
|
|
|
|
|
|
|
| |
THere is no such thing as the "Lesser General Public License
version 2": the LGPL v2 is the "Library GPL", and has been
superceded by v2.1 with the new "Lesser GPL" name.
Also, the copyright is now Intel Corp.
|
|
|
|
|
|
|
|
|
|
| |
The JsonNode structure has always been meant to be completely
opaque; we indirectly exposed the :type member, but only for
access through the JSON_NODE_TYPE() macro.
Since that macro has become a proxy for the json_node_get_node_type()
function we can safely move everything into a private, uninstalled
header file and let JsonNode be completely opaque to the developer.
|
|
|
|
|
|
|
| |
Since json_object_add_member() has been deprecated and it's using
a gcc compiler attribute to loudly complain while compiling the
library, we should restore the sanity and use json_object_set_member()
instead.
|
|
|
|
|
|
|
| |
Static analysis of the code showed some potential leaks inside
error paths for JsonParser.
Thanks to: Gordon Williams <gordon.williams@collabora.co.uk>
|
|
|
|
|
| |
Since I decided to rant about assignments in JSON definitions,
I also need to show what an assignment looks like.
|
|
|
|
| |
Add more spaces and remove the ` from the error message.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The load_from_file() method must set the is_filename/filename fields
of the JsonParserPrivate structure, so that the error handler can
use them to print out the file, as well as the line in case of
error.
Since load_from_data() needs to unset those two fields, to avoid
printing invalid/stale information, we need to have a generic "load"
function that can be invoked by both load_from_data() and
load_from_file(), and leave the JsonParser object set up to those
two methods.
Hence, a private json_parser_load() has been added, moving most of
the code out of json_parser_load_from_data(). This function does not
perform type checks and requires that the length of the memory buffer
containing the JSON data stream is already a positive integer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Instead of just relaying the line number both when parsing files
and memory buffers, JsonParser should also print out the file name
in case it is available.
The error message format should be make-like and emacs-friendly,
that is:
filename:line_number: error message
so that editors and development environments can parse the errors
easily.
This commit adds the filename string, and a boolean flag for checking
whether the filename is set, inside the JsonParser private data
structure. The boolean flag is checked inside the JsonScanner error
handler when populating the GError or when printing the warning
directly on stderr.
|
|
|
|
| |
JsonParser now uses JsonScanner, the internal copy of GScanner.
|
|
|
|
|
|
|
| |
Rename the GScanner function calls into JsonScanner, to see what we
actually need to have public.
Also, remove the configuration: JsonScanner will provide us with one.
|
| |
|
|
|
|
|
|
|
|
|
| |
The get_root() method should not return a copy of the parsed node: it is
up to the developer copying it, if it needs to be kept around across multiple
parsing runs.
This commit reverts the 0b6b09c0 commit, by removing the peek_root() method
and restoring the previous get_root() method behaviour.
|
|
|
|
|
|
|
|
| |
The JsonParser object clears its state upon starting the parsing sequence
or during the instance destruction process. It's worth moving the free
and unref calls into their own function to be called by the load_from_data()
and dispose methods. As further optimisation, inlining them should be
worth as well.
|
|
|
|
| |
Use an intermediary pointer to avoid a lot of pointer dereferences
|
|
|
|
|
|
| |
When the same JsonParser loads a different buffer it needs to clear out the
current state; this means clearing the variable_name string it saves when
the passed JSON stream is a JavaScript assignment.
|
|
|
|
|
|
|
| |
Since we allow a negative value, meaning "take the whole string", for the
length parameter, when need a signed size_t. This also fixes the bug where
we implicitly always computed the buffer length and discarded the passed
length parameter.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The json_parser_get_root() returns a pointer to the root node. This does
not conform to the API naming convention inherited from GLib, where
functions returning an internal pointer are called "peek" and function
returning a copy are called "get".
Thus, json_parser_get_root() will now return a copy of the root node and
it is left to the developer to free the returned JsonNode.
A function returning the pointer has also been added, and it's called
json_parser_peek_root().
|
| |
|
|
|
|
|
|
| |
There's no end to web developers insanity when they can twist and turn a
perfectly simple and elegant notation into something that allows lazyness
and breakage.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Some JSON web APIs return a full JavaScript assignment instead of just
the data structure (and I'm looking at you, Tumblr). This is done in clear
violation of the grammar published in the RFC 4627, and it's evidently
done because most web developers are too lazy for doing a
var foo = eval('(' + text ')');
and want everything defined for them. JsonParser will blissfully ignore
the left-hand part of the assignment but, in the interest of the developer
who cares, will record: 1. that the parsed statement was in fact an
assignment and 2. the name of the variable used.
The function json_parser_has_assignment() can be used to query both the
presence of an assignment and the variable name at the same time.
|
|
|
|
| |
Add a check for commas after complex data types inside object members.
|
|
|
|
| |
Catch missing commas after an array element or an object member.
|
|
|
|
|
|
|
|
|
|
| |
The copy of JSON-GLib in Clutter trunk has two fixes for the JsonParser
object:
* support for negative numbers (ints and floats);
* correct parse error propagation
which should make the JsonParser hopefully complete.
|
| |
|
|
|
|
|
|
|
|
| |
If the root node contains just a bare value (true, false, null, fundamental
type) then it's still valid JSON.
Also, use the commodity JsonNode API to avoid using values in the parser
code.
|
|
|
|
|
|
| |
GScanner advertise the floating point values as floats, but it really
uses doubles. Hence, we need to use G_TYPE_DOUBLE when saving the
parsed constants into a GValue.
|
|
|
|
|
|
| |
Add two methods to JsonParser to retrieve the currently parsed line
and position within that line. These methods works only while parsing,
so within the signal handlers and inside subclasses.
|
| |
|
|
|
|
|
|
|
| |
JsonParser should emit signals in critical places, like: start/end of
the parsing process; start and end of a JsonObject and a JsonArray;
completion of every member and element of a JsonObject and a JsonArray.
These signals require the addition of some custom marshaller.
|
|
|
|
|
|
|
| |
Now that we are providing a generator class we need to provide the
constructors and setters for JsonNode, JsonObject and JsonArray. This
also means that the json-private.h header is now useless, so we can
remove it from the build and repository.
|
| |
|
|
|
|
|
| |
The comma is used as a member and element separator, so it should be
swallowed by the parser as soon as possible.
|