diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 00:21:08 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 00:21:08 +0200 |
commit | 23f2fb9ddca6801388b3e4debb66d1db673ec38c (patch) | |
tree | 7e4cede1df809d7e434be5916b5315bf58d65ff2 /crates/rebel-parse | |
parent | cc318d3e7ee1006e98994f7d2e382a0a69445893 (diff) | |
download | rebel-23f2fb9ddca6801388b3e4debb66d1db673ec38c.tar rebel-23f2fb9ddca6801388b3e4debb66d1db673ec38c.zip |
rebel-parse: add type and pat modes to parse-string
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r-- | crates/rebel-parse/examples/parse-string.rs | 4 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/crates/rebel-parse/examples/parse-string.rs b/crates/rebel-parse/examples/parse-string.rs index c023c46..9750a87 100644 --- a/crates/rebel-parse/examples/parse-string.rs +++ b/crates/rebel-parse/examples/parse-string.rs @@ -12,6 +12,8 @@ enum Rule { Block, BlockStmt, Expr, + Type, + Pat, } #[derive(Clone, Debug, Parser)] @@ -49,6 +51,8 @@ fn main() { Rule::Block => recipe::block(&tokens).map(as_debug), Rule::BlockStmt => recipe::block_stmt(&tokens).map(as_debug), Rule::Expr => recipe::expr(&tokens).map(as_debug), + Rule::Type => recipe::typ(&tokens).map(as_debug), + Rule::Pat => recipe::pat(&tokens).map(as_debug), }; if opts.rule != Rule::Tokenize { let dur = Instant::now().duration_since(start); diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 50a0694..68429cb 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -62,7 +62,7 @@ peg::parser! { rule typed_pat() -> ast::TypedPat<'a> = pat:pat() typ:tagged(<p(':')>, <typ()>)? { ast::TypedPat { pat, typ } } - rule typ() -> Type<'a> + pub rule typ() -> Type<'a> = lit:typ_literal() { Type::Literal(lit) } / path:path() { Type::Path(path) } / p('(') t:typ() p(')') { Type::Paren(Box::new(t)) } @@ -79,7 +79,7 @@ peg::parser! { typ::Literal::Struct(entries) } - rule pat() -> Pat<'a> + pub rule pat() -> Pat<'a> = path:path() { Pat::Path(path) } rule struct_field_typ() -> typ::StructField<'a> |