fix unary parsing

main
Ziyang Hu 2 years ago
parent dc2a233d48
commit 7618250c91

@ -3,4 +3,7 @@
* Conversion methods
* `v.format()`
* `v.parse_int()`
* `v.parse_float()`
* `v.parse_float()`
* Note about iterator efficiency [here](https://github.com/facebook/rocksdb/wiki/Reducing-memcpy-overhead-when-using-Iterators)
* Homogeneous array types
* Alignment could imply necessary copies (COW)

@ -83,7 +83,7 @@ literal = _{ null | boolean | number | string}
// expressions
comma_sep_expr = { expr ~ ("," ~ expr)* }
expr = {(unary | term) ~ (operation ~ (unary | term)) *}
expr = {unary ~ (operation ~ unary) *}
operation = _{ (op_and | op_or | op_pow | op_str_cat | op_add | op_sub | op_mul | op_div | op_mod | op_coalesce |
op_ge | op_le | op_gt | op_lt | op_eq | op_ne)}
op_or = { "||" }
@ -103,7 +103,7 @@ op_ge = { ">=" }
op_le = { "<=" }
op_pow = { "^" }
unary = { unary_op ~ term }
unary = { (unary_op ~ unary) | term }
unary_op = _{ minus | negate }
minus = { "-" }
negate = { "!" }

@ -107,7 +107,7 @@ pub enum Value<'a> {
// not evaluated
Variable(Cow<'a, str>),
TupleRef(TableId, ColId),
Apply(Cow<'a, str>, Vec<Value<'a>>),
Apply(Cow<'a, str>, Vec<Value<'a>>), // TODO optimization: special case for small number of args (esp. 0, 1, 2)
FieldAccess(Cow<'a, str>, Box<Value<'a>>),
IdxAccess(usize, Box<Value<'a>>),
// cannot exist
@ -486,13 +486,15 @@ fn build_expr_primary(pair: Pair<Rule>) -> Result<Value> {
Rule::unary => {
let mut inner = pair.into_inner();
let op = inner.next().unwrap().as_rule();
let term = build_expr_primary(inner.next().unwrap())?;
let p = inner.next().unwrap();
let op = p.as_rule();
let op = match op {
Rule::term => return build_expr_primary(p),
Rule::negate => OP_NEGATE,
Rule::minus => OP_MINUS,
_ => unreachable!()
};
let term = build_expr_primary(inner.next().unwrap())?;
Ok(Value::Apply(op.into(), vec![term]))
}

Loading…
Cancel
Save