Expand description
Parsel, the Zero-Code Parser Generator
Parsel is a library for generating parsers directly from syntax tree node types.
The main entry point is the #[derive(Parse)]
custom derive
proc-macro, which generates an implementation of the syn::parse::Parse
trait
for the annotated AST node type.
In the future, a #[derive(ToTokens)]
macro is also planned, for easily obtaining
the source representation of a specific AST node. This will also help with getting
its Span
due to the blanket impl<T> Spanned for T where T: ToTokens
in syn
.
AST nodes that have a struct
type correspond to sequences: every field (whether
named or numbered) will be parsed and populated one after another, in the order
specified in the source.
AST nodes having an enum
type correspond to alternation: their variants will be
tried in order, and the first one that succeeds will be returned. Fields of tuple
and struct variants are treated in the same sequential manner as struct
fields.
Furthermore, the library provides a number of helper types for common needs, such as optional productions, repetition, and grouping or parenthesizing.
Roadmap:
- Configure and use Clippy
-
Add tests for various scenarios
-
Unit-like
struct
s are disallowed (there issyn::parse::Nothing
for that purpose) - Unit-like variants are disallowed
-
Empty (uninhabited)
enum
s are disallowed -
Parsing of simple named-field
struct
succeeds -
Parsing of simple tuple
struct
succeeds -
Parsing of
enum
with multiple kinds of variants succeeds -
Parsing a generic
struct
succeeds (named-field as well as tuple) -
Parsing a generic
enum
succeeds (with multiple kinds of variants)
-
Unit-like
- Handle generic AST node types
- Refactor into modules
- Add helper types for repetition, optional, etc.
-
Implement
#[derive(ToTokens)]
, getimpl Spanned
for free - Code Examples, tutorial
Traits
Parsing interface implemented by all types that can be parsed in a default way from a token stream.
Derive Macros
Implements the syn::parse::Parse
trait for the annotated type.