this post was submitted on 06 Apr 2024
27 points (96.6% liked)

Rust Programming

8234 readers
38 users here now

founded 5 years ago
MODERATORS
 

Been working on this a few months. It's inspired by previous generations of parser generators, and by my own previous work generating ast lexers from grammar files. This integrates seamlessly with the type system, allowing you to declare your syntax, extract only the data you want as variables, and evaluate them easily. And just from a simple description of your syntax, you'll get beautiful errors which visually point out structures in the input.

With this I have been able to implement a (mostly complete) JSON parser in just 12 lines of parsing logic, and a pmdas-respecting expression parser in just 6 (with one helper function to apply individual operators).

Examples available on the github repo, also now available on crates.io!

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 8 months ago

Thank you! It's hopefully intuitive to anyone who knows regex or BNF already