Skip to content

Commit a98d397

Browse files
committed
Fix comparison operators (==, !=, <=, >=) inside ${} interpolation in unquoted text
1 parent 81a558f commit a98d397

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

src/loreline/Lexer.hx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,8 +1759,8 @@ class Token {
17591759

17601760
var c = input.uCharCodeAt(pos);
17611761

1762-
// Found assign operator
1763-
if (!isEscape && (c == "=".code ||
1762+
// Found assign operator (but not comparison operators ==, !=, <=, >=)
1763+
if (!isEscape && ((c == "=".code && (pos + 1 >= this.length || input.uCharCodeAt(pos + 1) != "=".code)) ||
17641764
(input.uCharCodeAt(pos + 1) == "=".code && (c == "+".code || c == "-".code || c == "*".code || c == "/".code || c == ":".code)))) {
17651765
return true;
17661766
}
@@ -1806,7 +1806,12 @@ class Token {
18061806
if (!readIdent()) return false;
18071807
}
18081808
else {
1809-
pos++;
1809+
// Skip two-char comparison operators so their trailing = isn't matched as assignment
1810+
if ((c == "=".code || c == "!".code || c == "<".code || c == ">".code) && pos + 1 < this.length && input.uCharCodeAt(pos + 1) == "=".code) {
1811+
pos += 2;
1812+
} else {
1813+
pos++;
1814+
}
18101815
}
18111816
}
18121817
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
state
3+
score: 100
4+
level: 5
5+
name: "Sam"
6+
active: true
7+
premium: false
8+
9+
// Equality
10+
${name == "Sam" ? "match" : "no match"}
11+
12+
// Inequality
13+
${name != "Sam" ? "stranger" : "friend"}
14+
15+
// Less than or equal
16+
${level <= 5 ? "beginner" : "experienced"}
17+
18+
// Greater than or equal
19+
${score >= 100 ? "perfect" : "needs work"}
20+
21+
// Logical and
22+
${active and premium ? "VIP" : "regular"}
23+
24+
// Logical or
25+
${active or premium ? "has access" : "locked out"}
26+
27+
// Combined: equality + logical
28+
${name == "Sam" and score >= 100 ? "top player" : "keep trying"}
29+
30+
// Ternary in dialogue
31+
narrator: The player is ${score == 100 ? "flawless" : "imperfect"}
32+
33+
// Nested access with equality
34+
${name != "Alex" ? "welcome" : "go away"}
35+
36+
// Less than
37+
${level < 10 ? "novice" : "veteran"}
38+
39+
/*
40+
<test>
41+
- expected: |
42+
~ match
43+
44+
~ friend
45+
46+
~ beginner
47+
48+
~ perfect
49+
50+
~ regular
51+
52+
~ has access
53+
54+
~ top player
55+
56+
narrator: The player is flawless
57+
58+
~ welcome
59+
60+
~ novice
61+
</test>
62+
*/

0 commit comments

Comments
 (0)