| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
This commit completes the JsonParser class by adding the ability to
parse JSON objects, either alone or inside arrays. JsonParser is now
a JSON parser.
|
|
|
|
|
| |
When parsing a JSON node we need to correctly set up the parent node
of the newly created ones.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This huge commit removes JsonData and adds JsonNode, the generic container
for fundamental and complex data types extracted from a JSON stream. The
contents of a JsonNode can be extracted from it in form of a GValue for
fundamental types (integers, floats, strings, booleans) or in form of
JsonObject and JsonArray objects. JsonObject and JsonArray now accept
JsonNodes instead of GValues.
The JsonParser object builds the data model tree when parsing a JSON stream;
the tree can be recursed by getting the root node and walking it using the
GValue API for the fundamental types and the objects/arrays API for complex
types.
The API has been updated and the tests now recurse through the generated
data model tree.
|
|
|
|
|
|
| |
Since there cannot be any other token except for the comma, which we
eat anyway, there's no point in going through the switch() check
after we have finished parsing a nested array.
|
|
|
|
|
|
|
| |
Add the array parsing code. The parser identifies and builds nested
levels of arrays, but the storage is not quite right. That is a problem
of the parser object, though, so this can be considered a first raw
pass at the problem.
|
|
|
|
|
| |
JSON is an object serialisation format (thanks, RFC4627), so it can
only express objects and/or arrays as top-levels.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Initial commit for getting JsonParser to work. Because GScanner API
is old and mostly sucks, we need to do some magic with signals.
If json_parser_load_from_data() fails, the passed GError will be set
with a JSON_PARSER_ERROR code and message; unfortunately, we can't get
the nice error message out of GScanner. We can, however, override the
default message handler and make it emit a signal on the JsonParser
object.
So, to make a long story short: the GError passed to the load_from_data()
method is filled with a short error message; the *real* error message
is passed to the ::error signal handlers so they can actually use it.
GScanner should really get a way to retrieve the last error message.
|