Skip to content

Commit 0879cb7

Browse files
committed
Fix parsing of comparison operators and string-containing brackets in expressions
1 parent a98d397 commit 0879cb7

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/loreline/Interpreter.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,6 +4362,12 @@ typedef InterpreterOptions = {
43624362
final i:Int = Std.int(index);
43634363
ArrayAccess(arrAccess.pos, target, i);
43644364
}
4365+
else if (index is String) {
4366+
if (target == null) {
4367+
throw new RuntimeError('Cannot access field \'$index\' of null', arrAccess.pos);
4368+
}
4369+
FieldAccess(arrAccess.pos, target, index);
4370+
}
43654371
else {
43664372
throw new RuntimeError('Invalid array access target', arrAccess.pos);
43674373
}

src/loreline/Lexer.hx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,11 +1413,17 @@ class Token {
14131413
}
14141414

14151415
// Handle array access
1416+
// Handle array access (skip strings inside brackets)
14161417
if (c == "[".code) {
14171418
pos++;
14181419
var bracketLevel = 1;
14191420
while (pos < this.length && bracketLevel > 0) {
14201421
c = input.uCharCodeAt(pos);
1422+
if (c == '"'.code) {
1423+
pos = scanStringEnd(pos, false);
1424+
if (pos == -1) return false;
1425+
continue;
1426+
}
14211427
if (c == "[".code) bracketLevel++;
14221428
if (c == "]".code) bracketLevel--;
14231429
pos++;
@@ -1677,12 +1683,20 @@ class Token {
16771683
continue;
16781684
}
16791685

1680-
// Handle bracket access
1686+
// Handle bracket access (skip strings inside brackets)
16811687
if (c == "[".code) {
1682-
// Skip everything until closing bracket
16831688
pos++;
16841689
while (pos < this.length) {
1685-
if (input.uCharCodeAt(pos) == "]".code) {
1690+
final bc = input.uCharCodeAt(pos);
1691+
if (bc == '"'.code) {
1692+
pos = scanStringEnd(pos, false);
1693+
if (pos == -1) {
1694+
pos = startPos;
1695+
return false;
1696+
}
1697+
continue;
1698+
}
1699+
if (bc == "]".code) {
16861700
pos++;
16871701
break;
16881702
}
@@ -1776,12 +1790,17 @@ class Token {
17761790
continue;
17771791
}
17781792

1779-
// Handle bracket access
1793+
// Handle bracket access (skip strings inside brackets)
17801794
if (c == "[".code) {
1781-
// Skip everything until closing bracket
17821795
pos++;
17831796
while (pos < this.length) {
1784-
if (input.uCharCodeAt(pos) == "]".code) {
1797+
final bc = input.uCharCodeAt(pos);
1798+
if (bc == '"'.code) {
1799+
pos = scanStringEnd(pos, false);
1800+
if (pos == -1) return false;
1801+
continue;
1802+
}
1803+
if (bc == "]".code) {
17851804
pos++;
17861805
break;
17871806
}
@@ -1802,6 +1821,11 @@ class Token {
18021821
else if (c == "\r".code || c == "\n".code) {
18031822
return false;
18041823
}
1824+
else if (c == '"'.code) {
1825+
// Skip quoted strings so their content isn't matched as operators
1826+
pos = scanStringEnd(pos, false);
1827+
if (pos == -1) return false;
1828+
}
18051829
else if (isIdentifierStart(c)) {
18061830
if (!readIdent()) return false;
18071831
}

0 commit comments

Comments
 (0)