summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crates/rebel-parse/src/ast/mod.rs13
-rw-r--r--crates/rebel-parse/src/ast/pat.rs24
2 files changed, 32 insertions, 5 deletions
diff --git a/crates/rebel-parse/src/ast/mod.rs b/crates/rebel-parse/src/ast/mod.rs
index 1afa9a1..0598cbd 100644
--- a/crates/rebel-parse/src/ast/mod.rs
+++ b/crates/rebel-parse/src/ast/mod.rs
@@ -102,16 +102,18 @@ impl<'a> BlockStmt<'a> {
pub fn validate(&self) -> Result<(), ValidationError> {
match self {
- BlockStmt::Let { dest: _, expr } => {
- // TODO: Destination validation
+ BlockStmt::Let { dest, expr } => {
+ let TypedPat { pat, typ: _ } = dest.as_ref();
+ pat.validate()?;
if let Some(expr) = expr {
expr.validate()?;
}
Ok(())
}
- BlockStmt::Assign { dest: _, expr } => {
- // TODO: Destination validation
- expr.validate()
+ BlockStmt::Assign { dest, expr } => {
+ dest.validate()?;
+ expr.validate()?;
+ Ok(())
}
BlockStmt::Expr { expr } => expr.validate(),
BlockStmt::Empty => Ok(()),
@@ -154,4 +156,5 @@ pub struct Ident<'a> {
pub enum ValidationError {
DuplicateKey,
NeedsParens,
+ InvalidLet,
}
diff --git a/crates/rebel-parse/src/ast/pat.rs b/crates/rebel-parse/src/ast/pat.rs
index d1baf68..1a48372 100644
--- a/crates/rebel-parse/src/ast/pat.rs
+++ b/crates/rebel-parse/src/ast/pat.rs
@@ -6,6 +6,15 @@ pub enum Pat<'a> {
Ident(Ident<'a>),
}
+impl<'a> Pat<'a> {
+ pub fn validate(&self) -> Result<(), ValidationError> {
+ match self {
+ Pat::Paren(pat) => pat.validate(),
+ Pat::Ident(_) => Ok(()),
+ }
+ }
+}
+
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DestrPat<'a> {
Index {
@@ -19,3 +28,18 @@ pub enum DestrPat<'a> {
Paren(Box<DestrPat<'a>>),
Path(Path<'a>),
}
+
+impl<'a> DestrPat<'a> {
+ pub fn validate(&self) -> Result<(), ValidationError> {
+ match self {
+ DestrPat::Index { pat, index } => {
+ pat.validate()?;
+ index.validate()?;
+ Ok(())
+ }
+ DestrPat::Field { pat, field: _ } => pat.validate(),
+ DestrPat::Paren(pat) => pat.validate(),
+ DestrPat::Path(_) => Ok(()),
+ }
+ }
+}