summaryrefslogtreecommitdiffstats
path: root/crates/rebel-parse/src/grammar/recipe.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rebel-parse/src/grammar/recipe.rs')
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs
index 68429cb..8903eec 100644
--- a/crates/rebel-parse/src/grammar/recipe.rs
+++ b/crates/rebel-parse/src/grammar/recipe.rs
@@ -2,7 +2,7 @@ use crate::{
ast::{
self,
expr::{self, Expr},
- pat::Pat,
+ pat::{DestrPat, Pat},
typ::{self, Type},
},
token::*,
@@ -40,10 +40,10 @@ peg::parser! {
/ [Token::Keyword(Keyword::Let)] dest:typed_pat() {
ast::BlockStmt::let_assign(dest, None)
}
- / dest:pat() op:assign_op() expr:expr() {
+ / dest:destr_pat() op:assign_op() expr:expr() {
ast::BlockStmt::assign(dest, op, false, expr)
}
- / dest:pat() p2('=', '+') expr:expr() {
+ / dest:destr_pat() p2('=', '+') expr:expr() {
ast::BlockStmt::assign(dest, Some(Add), true, expr)
}
/ expr:expr() {
@@ -79,8 +79,22 @@ peg::parser! {
typ::Literal::Struct(entries)
}
- pub rule pat() -> Pat<'a>
- = path:path() { Pat::Path(path) }
+ pub rule pat() -> ast::pat::Pat<'a>
+ = p('(') pat:pat() p(')') { Pat::Paren(Box::new(pat)) }
+ / ident:ident() { Pat::Ident(ident) }
+
+ pub rule destr_pat() -> DestrPat<'a> = precedence! {
+ pat:@ p('[') index:expr() p(']') {
+ DestrPat::Index { pat: Box::new(pat), index: Box::new(index) }
+ }
+ --
+ pat:@ p('.') field:field() {
+ DestrPat::Field { pat: Box::new(pat), field }
+ }
+ --
+ p('(') pat:destr_pat() p(')') { DestrPat::Paren(Box::new(pat)) }
+ path:path() { DestrPat::Path(path) }
+ }
rule struct_field_typ() -> typ::StructField<'a>
= field:field() p(':') typ:typ() {