From b54659ac7cf72fe2d8be28f699c220e463f9b6f7 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 1 Apr 2025 10:12:57 +0100 Subject: Add `##` operator to `core:odin` --- core/odin/parser/parser.odin | 3 ++- core/odin/tokenizer/token.odin | 10 ++++++++++ core/odin/tokenizer/tokenizer.odin | 10 +++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 63c7e388f..a2472ea2d 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -1627,7 +1627,8 @@ token_precedence :: proc(p: ^Parser, kind: tokenizer.Token_Kind) -> int { case .Mul, .Quo, .Mod, .Mod_Mod, .And, .And_Not, - .Shl, .Shr: + .Shl, .Shr, + .Concat: return 7 } return 0 diff --git a/core/odin/tokenizer/token.odin b/core/odin/tokenizer/token.odin index 48d08f127..74e60f2b8 100644 --- a/core/odin/tokenizer/token.odin +++ b/core/odin/tokenizer/token.odin @@ -64,6 +64,8 @@ Token_Kind :: enum u32 { Shl, // << Shr, // >> + Concat, // ## + Cmp_And, // && Cmp_Or, // || @@ -80,6 +82,9 @@ Token_Kind :: enum u32 { And_Not_Eq, // &~= Shl_Eq, // <<= Shr_Eq, // >>= + + Concat_Eq, // ##= + Cmp_And_Eq, // &&= Cmp_Or_Eq, // ||= B_Assign_Op_End, @@ -199,6 +204,8 @@ tokens := [Token_Kind.COUNT]string { "<<", ">>", + "##", + "&&", "||", @@ -215,6 +222,9 @@ tokens := [Token_Kind.COUNT]string { "&~=", "<<=", ">>=", + + "##=", + "&&=", "||=", "", diff --git a/core/odin/tokenizer/tokenizer.odin b/core/odin/tokenizer/tokenizer.odin index d4da82c56..6fa16fece 100644 --- a/core/odin/tokenizer/tokenizer.odin +++ b/core/odin/tokenizer/tokenizer.odin @@ -650,7 +650,15 @@ scan :: proc(t: ^Tokenizer) -> Token { } case '#': kind = .Hash - if t.ch == '!' { + + if t.ch == '#' { + advance_rune(t) + kind = .Concat + if t.ch == '=' { + advance_rune(t) + kind = .Concat_Eq + } + } else if t.ch == '!' { kind = .Comment lit = scan_comment(t) } else if t.ch == '+' { -- cgit v1.2.3