git.delta.rocks / jrsonnet / refs/commits / a17ef2dd6ca7

difftreelog

fix(parser) infix operator precedence, ifcomp

Лач2020-06-04parent: #e284e94.patch.diff
in: master

1 file changed

modifiedcrates/jsonnet-parser/src/lib.rsdiffbeforeafterboth
134 pub rule forspec(s: &ParserSettings) -> ForSpecData134 pub rule forspec(s: &ParserSettings) -> ForSpecData
135 = keyword("for") _ id:id() _ keyword("in") _ cond:expr(s) {ForSpecData(id, cond)}135 = keyword("for") _ id:id() _ keyword("in") _ cond:expr(s) {ForSpecData(id, cond)}
136 pub rule compspec(s: &ParserSettings) -> Vec<expr::CompSpec>136 pub rule compspec(s: &ParserSettings) -> Vec<expr::CompSpec>
137 = s:(i:ifspec(s) { expr::CompSpec::IfSpec(i) } / f:forspec(s) {expr::CompSpec::ForSpec(f)} )+ {s}137 = s:(i:ifspec(s) { expr::CompSpec::IfSpec(i) } / f:forspec(s) {expr::CompSpec::ForSpec(f)} ) ** _ {s}
138 pub rule local_expr(s: &ParserSettings) -> LocExpr138 pub rule local_expr(s: &ParserSettings) -> LocExpr
139 = l(s,<keyword("local") _ binds:bind(s) ** comma() _ ";" _ expr:expr(s) { Expr::LocalExpr(binds, expr) }>)139 = l(s,<keyword("local") _ binds:bind(s) ** comma() _ ";" _ expr:expr(s) { Expr::LocalExpr(binds, expr) }>)
140 pub rule string_expr(s: &ParserSettings) -> LocExpr140 pub rule string_expr(s: &ParserSettings) -> LocExpr
248 a:(@) _ "/" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Div, b))}248 a:(@) _ "/" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Div, b))}
249 a:(@) _ "%" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Mod, b))}249 a:(@) _ "%" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Mod, b))}
250 --250 --
251 e:expr_basic_with_suffix(s) {e}
252 "-" _ expr:expr(s) { loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Minus, expr)) }251 "-" _ b:@ {loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Minus, b))}
253 "!" _ expr:expr(s) { loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Not, expr)) }252 "!" _ b:@ {loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Not, b))}
254 "~" _ expr:expr(s) { loc_expr_todo!(Expr::UnaryOp(UnaryOpType::BitNot, expr)) }253 "~" _ b:@ { loc_expr_todo!(Expr::UnaryOp(UnaryOpType::BitNot, b)) }
254 --
255 e:expr_basic_with_suffix(s) {e}
255 "(" _ e:expr(s) _ ")" {loc_expr_todo!(Expr::Parened(e))}256 "(" _ e:expr(s) _ ")" {loc_expr_todo!(Expr::Parened(e))}
256 } end:position!() {257 } end:position!() {
257 let LocExpr(e, _) = a;258 let LocExpr(e, _) = a;
479 );480 );
480 }481 }
482
483 #[test]
484 fn infix_precedence_division() {
485 use Expr::*;
486 assert_eq!(
487 parse!("!a / !b"),
488 el!(BinaryOp(
489 el!(UnaryOp(UnaryOpType::Not, el!(Var("a".to_owned())))),
490 BinaryOpType::Div,
491 el!(UnaryOp(UnaryOpType::Not, el!(Var("b".to_owned()))))
492 ))
493 );
494 }
481495
482 #[test]496 #[test]
483 fn double_negation() {497 fn double_negation() {
491 )505 )
492 }506 }
507
508 #[test]
509 fn array_test_error() {
510 parse!("[a for a in b if c for e in f]");
511 // ^^^^ failed code
512 }
493513
494 #[test]514 #[test]
495 fn can_parse_stdlib() {515 fn can_parse_stdlib() {