#miden #source #component #scanner #token #parser #peek

miden-parsing

Reusable parsing components for use in Miden projects

1 unstable release

0.1.0 Jul 12, 2023

#847 in Programming languages

Download history 21/week @ 2024-04-20 21/week @ 2024-04-27 17/week @ 2024-05-04 16/week @ 2024-05-11 20/week @ 2024-05-18 12/week @ 2024-05-25 16/week @ 2024-06-01 8/week @ 2024-06-08 17/week @ 2024-06-15 19/week @ 2024-06-22 2/week @ 2024-06-29 16/week @ 2024-07-13 21/week @ 2024-07-20 44/week @ 2024-07-27 99/week @ 2024-08-03

180 downloads per month
Used in 5 crates (via air-parser)

MIT license

21KB
382 lines

miden-parsing

This crate provides additional infrastructure on top of miden-diagnostics for parsing within a compiler frontend.

Features

The following are features provided by this crate:

  • An abstraction called Source that provides the core operations required by the scanner component of a parser, along with a "standard" implementation called FileMapSource which builds on the SourceFile type provided by miden-diagnostics
  • Scanner, a low-level component intended for consumption from a lexer. At a high level, the scanner operates on the input source to allow a lexer to precisely control what characters in the source are part of the current token, the ability to get a slice associated with the current token, as well as the ability to control advancement of the underlying source stream (i.e. get the current char, pop the current char, peek the next char, etc).
  • Parse<T> a trait which describes what is needed to parse a T, and exposes the API for doing so
  • Parser<C> represents a parser with a configuration type C that is capable of parsing any compatible Parse implementation. This parser is designed for use with components provided by miden-diagnostics, specifically CodeMap and DiagnosticsHandler. It abstracts away some of the boilerplate involved with common parsing tasks, e.g. parse_file and parse_string.

This crate is known to work well with LALRPOP, and only requires that a compiler frontend provide a lexer and token type specific to the language being parsed. See the examples folder for a complete end-to-end demonstration of how to use this crate (and miden-diagnostics) with LALRPOP for a simple language.

Dependencies

~3–10MB
~100K SLoC