summaryrefslogtreecommitdiff
path: root/json-glib/json-parser.c
Commit message (Collapse)AuthorAgeFilesLines
* Stop providing our own marshaller and use the generic oneThibault Saunier2017-03-131-19/+10
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=773603
* Only seal arrays and objects when a parser is immutableEmmanuele Bassi2017-03-131-2/+4
| | | | | | | We seal nodes conditionally on the :immutable property, but we are sealing their contents unconditionally. https://bugzilla.gnome.org/show_bug.cgi?id=779970
* Allow empty string as object member nameDr. David Alan Gilbert2017-03-111-1/+1
| | | | | | | | | | | Commit 028e540 disallowed empty member names in objects, however they are unfortunately valid JSON. This patch reenables an empty string as a member name. Tests are updated to allow the empty string case, and to test the use of an empty string in generation, iteration etc. https://bugzilla.gnome.org/show_bug.cgi?id=747279
* Fix translator commentsPiotr Drąg2017-01-281-4/+4
| | | | They need to be exactly one line above a string to show up in .po files.
* parser: Rename `immutable` bit fieldEmmanuele Bassi2016-03-011-9/+9
|
* docs: Fix the Since tagsEmmanuele Bassi2016-03-011-2/+2
| | | | The newly added API is available since 1.2.
* core: Add JSON node, object, array hashesPhilip Withnall2016-03-011-6/+2
| | | | | | | | | | | | | | | | | | | Now that these objects can be marked as immutable, it is possible to calculate and cache hash values for each of them. This allows efficient hash-based deduplication of large numbers of JSON nodes, as needed by Walbottle for JSON test vector generation. To complement the new hash functions, each of JsonNode, JsonValue, JsonObject and JsonArray also now have an equal() comparison method. This compares them structurally and recursively, using the definition of equality from the JSON Schema specification, which seems as good as any other. http://json-schema.org/latest/json-schema-core.html#anchor9 https://bugzilla.gnome.org/show_bug.cgi?id=756121 Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
* node: Add json_node_ref() and json_node_unref()Philip Withnall2016-03-011-12/+12
| | | | | | | | | | | | | | Add reference counting semantics to JsonNode, in addition to the existing init/unset and alloc/free semantics. json_node_free() must only be used with nodes allocated using json_node_alloc(). json_node_unref() may be used with all nodes (if correctly paired; it may be paired with json_node_alloc()). It is not valid to call json_node_free() on a node whose reference count is not 1. https://bugzilla.gnome.org/show_bug.cgi?id=756121
* core: Add immutability support to core objectsPhilip Withnall2016-03-011-0/+108
| | | | | | | | | | | Add an immutable mode to JsonNode, JsonObject, JsonArray and JsonValue. This is an optional mode which objects enter by calling json_*_seal(). It is a one-way transition, which means that we can build and manipulate objects as much as desired, before sealing them and enjoying the benefits of immutable objects: no need to take copies when handling them, persistent hash values (still to be implemented). https://bugzilla.gnome.org/show_bug.cgi?id=756121
* parser: Detect missing commas in arraysEmmanuele Bassi2016-02-251-1/+14
| | | | | Just like we detect trailing commas, we should also detect missing ones to avoid parsing invalid JSON successfully.
* parser: Correctly increment the array index counterEmmanuele Bassi2016-02-251-1/+2
| | | | | We pass the counter to the JsonParser::array-element signal, but we never really increment it.
* parser: Port to GTaskEmmanuele Bassi2015-06-091-118/+62
| | | | | GSimpleAsyncResult is deprecated in GLib 2.46, so we should drop its use, and simplify the code in the process.
* Drop unnecessary '_' prefix from json_marshalEmmanuele Bassi2014-12-301-9/+9
| | | | | It's not public API anyway, and we use annotations instead of the '_' prefix.
* json-parser: use length parameter when validating utf-8djcb2014-04-171-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=727755
* parser: Use the right length for parsing the stream contentsEmmanuele Bassi2014-04-171-2/+2
| | | | | | | The ByteArray we use to buffer the contents of a stream in order to pass them to the parser may have a bigger length. We should use the cursor position that we use to put a '\0' in the buffer instead. We could also use -1, but this saves us a strlen() later on.
* Remove conditional inclusion of config.hEmmanuele Bassi2014-03-181-2/+0
| | | | All the platforms and build system we support have a config.h header.
* parser: Always perform UTF-8 validationEmmanuele Bassi2013-10-271-0/+9
| | | | | | JSON is defined to be encoded using UTF-8, so we should not rely on the documentation saying so when parsing, but validate the input and eventually provide a recoverable parsing error.
* parser: Always use a valid GError internallyEmmanuele Bassi2013-10-261-2/+15
| | | | | Do not just pass the GError through from the public-facing arguments: we may want to perform error checking internally at any later date.
* parser: Drop a pointless macroEmmanuele Bassi2013-08-221-4/+2
| | | | | The JSON_PARSER_GET_PRIVATE macro is pointless, now that we use the new version of GLib.
* Remove compile time GLib version checkEmmanuele Bassi2013-08-211-13/+1
| | | | | We depend on a new version of GLib, so we can remove a bunch of old version checks.
* Use new macros when compiling against new GLibEmmanuele Bassi2013-07-201-1/+11
| | | | | | | | If we're being compiled against a newer version of GLib, we should use the new macros that add instance private data. Since this is a stable branch, we cannot bump the GLib requirement; so we use version checks to conditionally compile the new code.
* Use G_DEFINE_QUARK macroEmmanuele Bassi2013-05-161-7/+3
| | | | Instead of hand-writing the error domain function ourselves.
* Use typed initializers for JsonNodeEmmanuele Bassi2012-10-271-16/+21
|
* scanner: Remove unused functionsEmmanuele Bassi2012-10-261-29/+23
| | | | | | | | JsonScanner is an internal, modified copy of GScanner; we don't need a bunch of the provided functions, as the type and its related API are meant for internal use only. Fewer functions == better coverage == less code to maintain.
* parser: Empty member names are not validEmmanuele Bassi2012-10-261-0/+13
| | | | | When parsing a JSON object, a member name has to be a valid string, not an empty one.
* parser: Use error codes for invalid assignmentsEmmanuele Bassi2012-10-251-1/+3
| | | | | In case we're parsing an assignment we should use the 'invalid bareword' error code.
* parser: Consolidate value parsingEmmanuele Bassi2012-10-251-25/+12
| | | | | | | Instead of doing a preliminary check when parsing arrays and objects, we should just call json_parse_value() and let it handle all the valid values and eventual error cases. This simplifies error handling and makes it more reliable.
* parser: Show the column in the error messageEmmanuele Bassi2012-10-251-2/+3
| | | | | For JSON parsed from data (which tends to be in a single line) the column holds more information than the line.
* parser: Fix small leak in json_parse_statementMiguel Angel Cabrera Moya2012-10-251-1/+4
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=686096
* Mark GError messages for translationsEmmanuele Bassi2011-06-011-1/+4
| | | | These errors might find their way into a UI.
* Add i18n machineryEmmanuele Bassi2011-06-011-0/+2
| | | | We need to translate the GError messages.
* Add missing introspection annotations.Luca Bruno2011-01-101-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=638932
* parser: Add loading from a GInputStreamEmmanuele Bassi2010-08-021-0/+258
| | | | | JsonParser should be able to use a GInputStream (both synchronously and asynchronously) to retrieve the JSON data and parse it.
* parser: Do not access GScanner:tokenEmmanuele Bassi2010-05-261-3/+6
| | | | | | | | | The GScanner:token member is declared as GTokenType instead of being an unsigned int. This means that comparing it to any other enumeration is going to generate a warning in GCC >= 4.5. Unfortunately, extending the GTokenType enumeration is the idiomatic way of handling new tokens. EPIC. FAIL.
* docs: Fix typoEmmanuele Bassi2010-04-141-1/+1
| | | | There is no such thing as a 'JsonArrary' type.
* parser: Do not increment the index variableEmmanuele Bassi2010-04-031-1/+1
| | | | | | | | 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>
* parser: Add MISSING_COLON errorEmmanuele Bassi2010-03-191-2/+1
| | | | | | 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.
* parser: Refactor the JsonParser logicEmmanuele Bassi2010-03-191-288/+200
| | | | | | | | | | | | | | | | | | 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.
* parser: Return specific error codesEmmanuele Bassi2010-03-191-10/+39
| | | | | | | | | 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.
* parser: Re-use json_parse_value()Emmanuele Bassi2010-03-181-55/+2
| | | | | | 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.
* parser: Add debug annotations for json_parse_value()Emmanuele Bassi2010-03-181-0/+8
| | | | Print out the values we are parsing, for debug purposes.
* parser: Clean up array and object parsingEmmanuele Bassi2010-03-181-20/+24
| | | | | | 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.
* parser: Improve strictnessEmmanuele Bassi2010-03-011-39/+78
| | | | | | 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.
* Update Introspection annotationsEmmanuele Bassi2009-11-121-2/+3
| | | | | | | • Fix the transfer rules for JsonNode, JsonObject and JsonArray getters. • Annotate the methods returning lists
* parser: Advance when parsing bare valuesEmmanuele Bassi2009-10-291-0/+1
| | | | | A missing get_next_token() prevents getting the contents of the tokenizer in order to place them into the JsonNode.
* [parser] Return the right expected tokenEmmanuele Bassi2009-09-221-2/+14
| | | | | | 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.
* [parser] Whitespace clean upEmmanuele Bassi2009-09-221-5/+6
|
* [node] Add JsonNode.set_parent()Emmanuele Bassi2009-09-061-7/+7
| | | | | Add the setter for JsonNode:parent, to be used in JsonParser instead of directly accessing the JsonNode structure.
* [parser] Clean up value parsingEmmanuele Bassi2009-09-061-118/+81
| | | | | The code that parses a value within an object and an array should be moved to its own function to avoid duplication.
* [docs] Small documentation fixesEmmanuele Bassi2009-09-021-1/+2
| | | | Clean up some notes, and add introspection annotations where needed.