11 releases

0.1.0-preview9 Oct 25, 2021
0.1.0-preview8 Oct 24, 2021
0.1.0-preview6 Oct 23, 2021
0.1.0-preview4 Oct 17, 2021

#1223 in Parser implementations

Download history 20/week @ 2023-10-31 16/week @ 2023-11-07 4/week @ 2023-11-14 16/week @ 2023-11-21 26/week @ 2023-11-28 3/week @ 2023-12-05 14/week @ 2023-12-12 4/week @ 2023-12-19 37/week @ 2023-12-26 2/week @ 2024-01-02 4/week @ 2024-01-09 4/week @ 2024-01-16 13/week @ 2024-01-23 24/week @ 2024-01-30 3/week @ 2024-02-06 61/week @ 2024-02-13

102 downloads per month
Used in ron-utils

Unlicense

210KB
6K SLoC

EXPERIMENT: Rusty Object Notation reboot

Experimental implementation of a new parser for RON using small functional parsers for individual syntax elements over a stateful parser.

This experiment started off as "RON + nom", but is now using its own parsers & combinators inspired by nom.

Motivation

The current ron parsing suffers from the following problems:

  • parsing is done in both parse.rs and the deserializer itself
    • bad code organization
    • hard to maintain
    • limits reuse
  • serde's data model stops us from accurately reflecting struct / map and struct names

Benefits

Stateless / functional parsers are

  • easier to maintain
  • easier to reuse
  • much easier to test

An abstract syntax tree (AST)...

  • makes the deserializer much easier & cleaner to implement
  • allows reporting locations of syntax & type errors
  • can be reused by multiple deserializer implementations (serde::Deserializer, our_own::Deserializer, ron-edit)

Error reporting

The old RON deserializer produced errors that were often hard to understand. ron-reboot is meant to change that; this is the output of a deserialization error as of 2021-10-15:

error: invalid type: boolean `true`, expected a string
 --> string:3:9
  |
3 |       y: true,
  |          ^^^^
  |

or with a multi-line expression:

error: invalid type: map, expected a string
 --> string:3:9
  |
3 |       y: (
  |  ________^
4 | |         this: "is",
5 | |         not: "the right type",
6 | |     ),
  | |______^
  |

Goals / Progress

Goal Status
Parser generating AST ✔️ done
Parser generating beautiful errors ✔️ done
Accurate Value deserialization from AST ✔️ done
Replace nom combinators ✔️ done
Spans in AST (locations for error reporting) ✔️ done
Serde Deserializer using AST ✔️ done
Serde Deserializer generating beautiful errors ✔️ done
ron-edit (format & comments preserving writer) ❌ to be done

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed according to the license of this project (The Unlicense), without any additional terms or conditions.

Dependencies

~180KB