summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-05-01 00:21:08 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-05-01 00:21:08 +0200
commit23f2fb9ddca6801388b3e4debb66d1db673ec38c (patch)
tree7e4cede1df809d7e434be5916b5315bf58d65ff2
parentcc318d3e7ee1006e98994f7d2e382a0a69445893 (diff)
downloadrebel-23f2fb9ddca6801388b3e4debb66d1db673ec38c.tar
rebel-23f2fb9ddca6801388b3e4debb66d1db673ec38c.zip
rebel-parse: add type and pat modes to parse-string
-rw-r--r--crates/rebel-parse/examples/parse-string.rs4
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs4
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>