A bunch of prerequisites before we can do arrays, part 1
This commit is contained in:
@@ -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())));
|
||||
}
|
||||
}
|
||||
@@ -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 ~ "]" }
|
||||
|
||||
Reference in New Issue
Block a user