30 Commits

Author SHA1 Message Date
Jordan Hrycaj
3509706517
Lazy JSON parser (#42)
* Proper error handling when parsed number exceeds uint64

details:
  Returns an "errNonPortableInt" error

* need legacy flag for unit tests

* lazy numeric token parser

why:
  Numeric data may have a custom format. In particular,numeric data may be
  Uint256 which is not a JSON standard and might lead to an overflow.

details:
  Numeric values are assigned a preliminary token type tkNumeric without
  being fully parsed. This can be used to insert a custom parser.
  Otherwise the value is parsed implicitly when querying/fetching the
  token type.

  + tok:     replaced by getter tok() resolving lazy stuff (if necessary)
  + tokKind: current type without auto-resolving

  This lazy scheme could be extended to other custom types as long as
  the first token letter determines the custom type.

* activate lazy parsing in reader

howto:
  + no code change if a custom reader refers to an existing reader
    type FancyInt = distinct int
    proc readValue(reader: var JsonReader, value: var FancyInt) =
      value = reader.readValue(int).FancyInt

  + bespoke reader for cusom parsing
    type FancyUint = distinct uint
    proc readValue(reader: var JsonReader, value: var FancyUint) =
      if reader.lexer.lazyTok == tkNumeric:
        var accu: FancyUint
        reader.lexer.customIntValueIt:
          accu = accu * 10 + it.u256
        value = accu
      elif reader.lexer.tok == tkString:
        value = reader.lexer.strVal.parseUint.FancyUint
        ...
      reader.lexer.next

  + full code explanation at json_serialisation/reader.readValue()

* Add lazy parsing for customised string objects

why:
  This allows parsing large or specialised strings without storing it
  in the lexer state descriptor.

details:
  Similar logic applies as for the cusomised number parser. For mostly
  all practical cases, a DSL template is available serving as wrapper
  around the character/byte item processor code.

* fix typo in unit test
2022-05-05 17:33:40 +01:00
Tanguy
010aa238cf Enable styleCheck:usages 2021-12-15 13:17:38 +02:00
Zahary Karadjov
297496d703 NULL cstrings are encoded to JS null 2021-11-01 18:59:12 +02:00
Zahary Karadjov
4f3775ddf4 Add JsonReader.init(..., requireAllFields: bool) 2021-08-11 20:01:47 +03:00
jangko
5d36ea5900
fixes test 2020-12-24 16:32:59 +07:00
jangko
dd2a6d8ac3
add github action 2020-12-24 16:04:58 +07:00
Zahary Karadjov
3b0c9eafa4
Bugfix: incorrect logic in the parsing of comments fails to detect EOF properly 2020-10-09 19:32:25 +03:00
Zahary Karadjov
d5eb9427b8
Serialization of JsonNode fields 2020-07-24 23:16:35 +03:00
Zahary Karadjov
25adda6f3f
Alternative implementation that doesn't require rewind points 2020-07-21 22:09:38 +03:00
Zahary Karadjov
4d8145c67b
WIP Deserialization of the JsonString literal fields 2020-07-17 23:58:02 +03:00
Zahary Karadjov
1cf51931f1
Implement forward-compatible deserialization 2020-06-30 22:11:56 +03:00
Zahary Karadjov
aa51f6fed1
Test case for the serializedFieldName pragma
The pragma was added in https://github.com/status-im/nim-serialization/pull/25
2020-05-20 13:53:21 +03:00
Jacek Sieka
cb695d175f reader support for stringlikes 2020-04-29 19:37:34 +03:00
Jacek Sieka
e485b74a10 treat array-of-char as string 2020-04-29 19:37:34 +03:00
Zahary Karadjov
f52683b2ee
Close #12 2020-04-09 20:46:48 +03:00
Zahary Karadjov
88b79e2300
Remove warnings in Nim 1.0.2 2019-11-04 18:42:34 +00:00
Alexander Ivanov
e49b8bdb43 Implement support for normal and ordered tables 2019-08-02 13:33:44 +03:00
Zahary Karadjov
342a272281
Some of the test cases were moved to the generic suite in nim-serialization 2019-08-02 11:54:47 +03:00
Zahary Karadjov
997ae368a5
Add a test case for case objects 2019-08-01 17:12:31 +03:00
Zahary Karadjov
73d9e0d458
Handle changes in the serialization APIs 2019-07-18 21:20:17 +03:00
Zahary Karadjov
7922a83c4d
Serialization for sets 2019-07-16 13:20:05 +03:00
Zahary Karadjov
9d909d352a Add support and tests for Option and reference types 2019-06-24 17:38:37 +03:00
Mamy André-Ratsimbazafy
f3d8f822bd
Handle reserved keyword type as field name 2019-05-28 17:42:18 +02:00
Zahary Karadjov
4ffd0b3af3 Add a test for handling missing fields 2019-04-08 15:29:21 +03:00
Zahary Karadjov
c2daa5a23c Improved error handling and pretty-printing for arrays 2019-03-20 01:54:16 +02:00
Ștefan Talpalaru
002c6bbb38
assert() -> doAssert()
and an explicit "test" task for the sake of nimble.sh
2019-03-14 00:39:10 +01:00
Zahary Karadjov
a9d565f8e0 Tests with distinct types 2019-03-13 23:20:58 +02:00
Zahary Karadjov
edda2577a3 Handle large unsigned values and add Portable JsonMode in the Lexer 2019-01-21 19:40:14 +02:00
Ștefan Talpalaru
d61f2e01fb add "--threads:on" to tests
and be explicit about relative path imports in them
2019-01-11 15:33:32 +02:00
Zahary Karadjov
6d3fae7df2 Json deserialisation; Tests 2018-12-19 12:47:53 +02:00