summaryrefslogtreecommitdiff
path: root/json-glib/json-parser.c
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* Actually use the int64 support in the ScannerEmmanuele Bassi2009-08-121-6/+6
| | | | | | | | 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.
* [parser] Advance the tokenizer to avoid an infinite loopEmmanuele Bassi2009-06-281-5/+11
| | | | | | | | 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.
* Fix license and copyright noticesEmmanuele Bassi2009-06-091-2/+6
| | | | | | | | 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.
* [node] Make JsonNode completely privateEmmanuele Bassi2009-06-091-0/+2
| | | | | | | | | | 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.
* Update after the json_object_add_member() deprecationEmmanuele Bassi2009-04-171-3/+3
| | | | | | | 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.
* [parser] Prevent leaks on error codepathsEmmanuele Bassi2009-04-131-5/+33
| | | | | | | Static analysis of the code showed some potential leaks inside error paths for JsonParser. Thanks to: Gordon Williams <gordon.williams@collabora.co.uk>
* [docs] Show an example of assignmentEmmanuele Bassi2009-04-131-5/+12
| | | | | Since I decided to rant about assignments in JSON definitions, I also need to show what an assignment looks like.
* Whitespace fixesEmmanuele Bassi2009-04-131-6/+12
| | | | Add more spaces and remove the ` from the error message.
* Abstract the loading code into its own functionerror-locationEmmanuele Bassi2008-11-281-72/+103
| | | | | | | | | | | | | | | | | | 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.
* Display the filename inside error messagesEmmanuele Bassi2008-11-281-2/+26
| | | | | | | | | | | | | | | | | | | | 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.
* Update JsonParser to fix compilationEmmanuele Bassi2008-02-291-16/+17
| | | | JsonParser now uses JsonScanner, the internal copy of GScanner.
* Use JsonScanner API into JsonParserEmmanuele Bassi2008-02-291-83/+44
| | | | | | | 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.
* Include JsonScanner into JsonParserEmmanuele Bassi2008-02-291-0/+1
|
* Revert JsonParser::get_root semanticsEmmanuele Bassi2008-01-291-24/+2
| | | | | | | | | 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.
* Extract the parser state clearing into its own functionEmmanuele Bassi2008-01-271-21/+30
| | | | | | | | 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.
* Kill off a few indirectionsEmmanuele Bassi2007-12-251-11/+14
| | | | Use an intermediary pointer to avoid a lot of pointer dereferences
* Plug a leak when loading a new buffer with the same parserEmmanuele Bassi2007-12-251-0/+2
| | | | | | 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.
* Use gssize for the buffer length parameterEmmanuele Bassi2007-12-251-5/+5
| | | | | | | 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.
* Change json_parser_get_root() semanticsEmmanuele Bassi2007-11-211-2/+24
| | | | | | | | | | | | | 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().
* Fix variable shadowing for distcheckEmmanuele Bassi2007-11-131-2/+2
|
* When parsing a full assignment, also swallow any trailing semi-colonEmmanuele Bassi2007-11-101-1/+11
| | | | | | 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.
* Add support for parsing assignmentsEmmanuele Bassi2007-11-101-2/+78
| | | | | | | | | | | | | | | | | 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.
* More sanity checks for objectsEmmanuele Bassi2007-10-291-1/+7
| | | | Add a check for commas after complex data types inside object members.
* Add more sanity checks to the parserEmmanuele Bassi2007-10-291-0/+10
| | | | Catch missing commas after an array element or an object member.
* Backport fixes from Clutter trunkEmmanuele Bassi2007-10-291-20/+103
| | | | | | | | | | 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.
* Fix compilation errors with extra maintainer CFLAGSEmmanuele Bassi2007-10-161-2/+2
|
* Parse bare root valuesEmmanuele Bassi2007-10-101-50/+29
| | | | | | | | 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.
* Use doubles when parsing, not floatsEmmanuele Bassi2007-10-051-4/+4
| | | | | | 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 line/position getters to JsonParserEmmanuele Bassi2007-10-051-3/+43
| | | | | | 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.
* Document the newly added signalsEmmanuele Bassi2007-10-051-0/+64
|
* Add more signals to the JsonParser classEmmanuele Bassi2007-10-051-3/+115
| | | | | | | 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.
* Move data types ctors and setters into the public headersEmmanuele Bassi2007-10-011-1/+0
| | | | | | | 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.
* Add licensing informations to the source codeEmmanuele Bassi2007-10-011-2/+26
|
* Swallow the comma earlier in the parserEmmanuele Bassi2007-10-011-9/+16
| | | | | The comma is used as a member and element separator, so it should be swallowed by the parser as soon as possible.