Change precedence for in and notin to match + - | ~

This commit is contained in:
gingerBill
2019-10-06 18:14:02 +01:00
parent 4e8a801b35
commit d62503d031
3 changed files with 12 additions and 19 deletions
+5 -5
View File
@@ -1144,17 +1144,17 @@ token_precedence :: proc(p: ^Parser, kind: token.Kind) -> int {
token.Lt_Eq, token.Gt_Eq: token.Lt_Eq, token.Gt_Eq:
return 5; return 5;
case token.In, token.Notin: case token.In, token.Notin:
if p.expr_level >= 0 || p.allow_in_expr { if p.expr_level < 0 && !p.allow_in_expr {
return 6; return 0;
} }
return 0; fallthrough;
case token.Add, token.Sub, token.Or, token.Xor: case token.Add, token.Sub, token.Or, token.Xor:
return 7; return 6;
case token.Mul, token.Quo, case token.Mul, token.Quo,
token.Mod, token.Mod_Mod, token.Mod, token.Mod_Mod,
token.And, token.And_Not, token.And, token.And_Not,
token.Shl, token.Shr: token.Shl, token.Shr:
return 8; return 7;
} }
return 0; return 0;
} }
+1 -9
View File
@@ -1190,15 +1190,7 @@ where_clauses :: proc() {
} }
main :: proc() { main :: proc() {
x := "foobarbaz"; when true {
i : int;
i = strings.last_index(x, "foo"); fmt.println(i);
i = strings.last_index(x, "bar"); fmt.println(i);
i = strings.last_index(x, "baz"); fmt.println(i);
i = strings.last_index(x, "asd"); fmt.println(i);
i = strings.last_index(x, "a"); fmt.println(i);
i = strings.last_index(x, "ba"); fmt.println(i);
when false {
general_stuff(); general_stuff();
union_type(); union_type();
parametric_polymorphism(); parametric_polymorphism();
+6 -5
View File
@@ -2479,17 +2479,18 @@ i32 token_precedence(AstFile *f, TokenKind t) {
case Token_LtEq: case Token_LtEq:
case Token_GtEq: case Token_GtEq:
return 5; return 5;
case Token_in: case Token_in:
case Token_notin: case Token_notin:
if (f->expr_level >= 0 || f->allow_in_expr) { if (f->expr_level < 0 && !f->allow_in_expr) {
return 6; return 0;
} }
return 0; /*fallthrough*/
case Token_Add: case Token_Add:
case Token_Sub: case Token_Sub:
case Token_Or: case Token_Or:
case Token_Xor: case Token_Xor:
return 7; return 6;
case Token_Mul: case Token_Mul:
case Token_Quo: case Token_Quo:
case Token_Mod: case Token_Mod:
@@ -2498,7 +2499,7 @@ i32 token_precedence(AstFile *f, TokenKind t) {
case Token_AndNot: case Token_AndNot:
case Token_Shl: case Token_Shl:
case Token_Shr: case Token_Shr:
return 8; return 7;
} }
return 0; return 0;
} }