diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast.rs | 26 | ||||
| -rw-r--r-- | src/parser.rs | 26 |
2 files changed, 39 insertions, 13 deletions
@@ -1 +1,27 @@ +use crate::parser::{self, Expr, ExprT, Scope}; +pub enum DepthExpr<'a> { + Decision { + cond: Box<DepthExpr<'a>>, + t: Scope, + else_branch: Option<Box<DepthExpr<'a>>>, + }, + IO(&'a str), + Process(&'a str), +} + +fn parse(vec: Vec<Expr>) -> Vec<DepthExpr> { + let exprs = Vec::new(); + + let mut it = vec + .iter() + .peekable(); + + while let Some(e) = it.next() { + if let ExprT::Decision((cond, scope)) = e.expr { + let cond = parser::parse(cond); + } + } + + exprs +} diff --git a/src/parser.rs b/src/parser.rs index 544c296..1475fce 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -41,23 +41,23 @@ pub fn delimit(s: &str) -> SplitWithMetadata<'_> { .char_indices() .next_back() { - let body = if ch == ';' || ch == '{' || ch == '}' { - part[..i].trim() - } else { - part.trim() - }; - if !body.is_empty() { - acc.push((body, None)); - } + acc.push(( + if ch == ';' || ch == '{' || ch == '}' { + part[..i].trim() + } else { + part.trim() + }, + None, + )); match ch { '{' => { - if let Some(last) = acc.last_mut() { - last.1 = Some(Metadata::StartScope); + if let Some((_, meta)) = acc.last_mut() { + *meta = Some(Metadata::StartScope); } } '}' => { - if let Some(last) = acc.last_mut() { - last.1 = Some(Metadata::EndScope); + if let Some((_, meta)) = acc.last_mut() { + *meta = Some(Metadata::EndScope); } } _ => {} @@ -92,7 +92,7 @@ pub fn process(strs: SplitWithMetadata<'_>) -> Vec<Expr<'_>> { }), None => exprs.push(Expr { expr: ExprT::Process(str), - meta: None, + meta, }), } } |
