Skip to content

Commit 2503bc5

Browse files
committed
[Lua] Split out = from other operators
1 parent df76b02 commit 2503bc5

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

Lua/Lua.sublime-syntax

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ contexts:
205205

206206
- match: local{{identifier_break}}
207207
scope: storage.modifier.lua
208-
push: expression-list
208+
push: expression-list-stmt
209209

210210
- match: end{{identifier_break}}
211211
scope: invalid.illegal.unexpected-end.lua
212212

213213
- match: (?=\S)
214-
push: expression
214+
push: expression-stmt
215215

216216
block-contents:
217217
- meta_scope: meta.block.lua
@@ -312,15 +312,15 @@ contexts:
312312
- include: else-pop
313313

314314
- - match: (?==)
315-
set: expression-list-end
315+
set: expression-list-stmt-end
316316

317317
- match: in{{identifier_break}}
318318
scope: keyword.control.loop.lua
319319
set: expression-list
320320

321321
- include: else-pop
322322

323-
- expression-list
323+
- expression-list-stmt
324324

325325
- match: '::'
326326
scope: punctuation.definition.label.begin.lua
@@ -367,12 +367,24 @@ contexts:
367367
- expression-end
368368
- expression-begin
369369

370+
expression-stmt:
371+
- match: ''
372+
set:
373+
- expression-stmt-end
374+
- expression-begin
375+
370376
expression-list:
371377
- match: ''
372378
set:
373379
- expression-list-end
374380
- expression-begin
375381

382+
expression-list-stmt:
383+
- match: ''
384+
set:
385+
- expression-list-stmt-end
386+
- expression-begin
387+
376388
expression-end:
377389
- match: (?=;)
378390
pop: 1
@@ -394,6 +406,12 @@ contexts:
394406

395407
- include: else-pop
396408

409+
expression-stmt-end:
410+
- match: =(?!=)
411+
scope: keyword.operator.assignment.lua
412+
push: expression-begin
413+
- include: expression-end
414+
397415
expression-list-end:
398416
- match: ','
399417
scope: punctuation.separator.comma.lua
@@ -405,6 +423,12 @@ contexts:
405423
- left-angle-is-less-than
406424
- include: expression-end
407425

426+
expression-list-stmt-end:
427+
- match: =(?!=)
428+
scope: keyword.operator.assignment.lua
429+
push: expression-begin
430+
- include: expression-list-end
431+
408432
expression-begin:
409433
- match: (?=;)
410434
pop: 1
@@ -457,13 +481,19 @@ contexts:
457481
- match: \.\.
458482
scope: keyword.operator.concatenation.lua
459483
push: expression-begin
460-
- match: =
461-
scope: keyword.operator.assignment.lua
462-
push: expression-begin
463484
- match: (?:and|or){{identifier_break}}
464485
scope: keyword.operator.logical.lua
465486
push: expression-begin
466487

488+
# assume that == is being typed
489+
- match: =(?=\s*(?:{{reserved_word_statement}}|$))
490+
scope: keyword.operator.comparison.lua
491+
push: expression-begin
492+
# only complain once it is clear that it isn't ==
493+
- match: =(?!=)
494+
scope: invalid.illegal.invalid-operator.lua
495+
push: expression-begin
496+
467497
accessor:
468498
- match: '[.:]'
469499
scope: punctuation.accessor.lua

Lua/tests/syntax_test_lua.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,15 @@
623623
elseif false then
624624
-- ^^^^^^ keyword.control.conditional
625625
-- ^^^^ keyword.control.conditional
626+
elseif a = 0 then
627+
-- ^ variable.other
628+
-- ^ invalid.illegal.invalid-operator
629+
-- ^ constant.numeric.value
630+
-- ^^^^ keyword.control.conditional
631+
elseif a = then
632+
-- ^ variable.other
633+
-- ^ keyword.operator.comparison
634+
-- ^^^^ keyword.control.conditional
626635
else
627636
-- ^^^^ keyword.control.conditional
628637
end
@@ -634,6 +643,7 @@
634643

635644
if a ! = b then end
636645
-- ^ invalid.illegal.unexpected-character.lua
646+
-- ^ invalid.illegal.invalid-operator.lua
637647
-- ^^^^ keyword.control.conditional
638648
-- ^^^ keyword.control.end
639649

0 commit comments

Comments
 (0)