An extensible-data-notation parser

https://github.com/travisstaloch/edn-data

about

edn format is a lispy subset of clojure which i find interesting for its readability and extensibility. maybe its a json, yaml or ziggy alternative.

i started working on this around 6 months ago and it has mostly been a mess. i recently was motivated to add a tokenizer and overall simplify the parsing code. now its in a state where i wanted to share.

i’ve attempted to add extensibility through ‘tagged element handlers’ but i’m not sure of the design details yet. and similar to std.json, the parser supports arbitrary and structured data plus allows users to override structured parsing by providing a pub fn ednParse() method.

arbitrary and structured parsing can both be done at comptime.

i plan to use this format in a future state machine codegen lib as shown in examples/Tokenizer.edn.

let me know if you have any use for this data format or thoughts about the lib.

features (paste from readme)

  • parsing
    • parse arbitrary data with edn.parseFromSliceAlloc() or edn.parseFromSliceBuf(). measure() is used to determine required buffer sizes for parseFromSliceBuf().
      • edn.Options.whitespace - whether to save whitespace and comments. .exclude means that ParseResult.wss.len will be 0 and each merged whitespace/comment will be replaced by a single space in fmtParseResult().
    • parse structured data with edn.parseTypeFromSlice(T)
      • edn.parseTypeFromSlice(T) supports custom parsing when T provides a pub fn ednParse(). see src/tests.zig test "ednParse()" for an example.
    • initial support for tagged element handlers. see src/tests.zig test "tagged handler" for an example.
    • ParseResult.find() - access parsed data with simple queries such as '0//1//foo'. see src/tests.zig test "ParseResult find()" for examples.
  • comptime parsing
    • parse arbitrary data with edn.parseFromSliceComptime()
    • parse structured data with comptime edn.parseTypeFromSlice(T)
  • formatting
    • format parse results with edn.fmtParseResult(parse_result, src)
4 Likes