A bunch of prerequisites before we can do arrays, part 1

This commit is contained in:
2023-11-12 23:03:45 -06:00
parent db15f28adc
commit 21af891574
17 changed files with 102 additions and 61 deletions
+6
View File
@@ -18,6 +18,7 @@ impl AstNode for Expr {
PRATT_PARSER
.map_primary(|term| match term.as_rule() {
PestRule::number => Expr::Number(term.into_number()),
PestRule::alloc => Expr::New(Expr::from_pair(term.first()).into()),
PestRule::name => Expr::Name(String::from(term.as_str())),
PestRule::expr => Expr::from_pair(term),
PestRule::string => Self::String(term.into_quoted_string()),
@@ -269,4 +270,9 @@ mod test {
Ok(Expr::Call(Call { target: "blah".into(), args: vec![Expr::String("foo".into()), 2.into()] }))
);
}
#[test]
fn alloc() {
assert_eq!(Expr::from_str("new(8)"), Ok(Expr::New(8.into())));
}
}
+3 -1
View File
@@ -63,7 +63,9 @@ operator = _{
}
expr = { prefix* ~ term ~ suffix* ~ (operator ~ prefix* ~ term ~ suffix*)* }
term = _{ number | name | "(" ~ expr ~ ")" | string }
term = _{ number | alloc | name | "(" ~ expr ~ ")" | string }
alloc = { "new" ~ "(" ~ expr ~ ")" }
suffix = _{ subscript | arglist }
subscript = { "[" ~ expr ~ "]" }