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

View File

@@ -1144,17 +1144,17 @@ token_precedence :: proc(p: ^Parser, kind: token.Kind) -> int {
token.Lt_Eq, token.Gt_Eq:
return 5;
case token.In, token.Notin:
if p.expr_level >= 0 || p.allow_in_expr {
return 6;
if p.expr_level < 0 && !p.allow_in_expr {
return 0;
}
return 0;
fallthrough;
case token.Add, token.Sub, token.Or, token.Xor:
return 7;
return 6;
case token.Mul, token.Quo,
token.Mod, token.Mod_Mod,
token.And, token.And_Not,
token.Shl, token.Shr:
return 8;
return 7;
}
return 0;
}

View File

@@ -1190,15 +1190,7 @@ where_clauses :: proc() {
}
main :: proc() {
x := "foobarbaz";
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 {
when true {
general_stuff();
union_type();
parametric_polymorphism();

View File

@@ -2479,17 +2479,18 @@ i32 token_precedence(AstFile *f, TokenKind t) {
case Token_LtEq:
case Token_GtEq:
return 5;
case Token_in:
case Token_notin:
if (f->expr_level >= 0 || f->allow_in_expr) {
return 6;
if (f->expr_level < 0 && !f->allow_in_expr) {
return 0;
}
return 0;
/*fallthrough*/
case Token_Add:
case Token_Sub:
case Token_Or:
case Token_Xor:
return 7;
return 6;
case Token_Mul:
case Token_Quo:
case Token_Mod:
@@ -2498,7 +2499,7 @@ i32 token_precedence(AstFile *f, TokenKind t) {
case Token_AndNot:
case Token_Shl:
case Token_Shr:
return 8;
return 7;
}
return 0;
}