Skip to content

Commit 481e0f6

Browse files
committed
add or= an and= operators
1 parent 1313013 commit 481e0f6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

moonscript/parse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ local build_grammar = wrap_env(function()
449449
CompClause = CompFor + key"when" * Exp / mark"when",
450450

451451
Assign = sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign",
452-
Update = ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=") / trim) * Exp / mark"update",
452+
Update = ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update",
453453

454454
-- we can ignore precedence for now
455455
OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">",

tests/inputs/syntax.moon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,9 @@ a /= func "cool"
232232
x.then = "hello"
233233
x.while.true = "hello"
234234

235+
--
236+
237+
x or= "hello"
238+
x and= "hello"
239+
235240
-- cooool

tests/outputs/syntax.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,7 @@ a = a * (3 + 5)
228228
a = a * 3
229229
a = a / func("cool")
230230
x["then"] = "hello"
231-
x["while"]["true"] = "hello"
231+
x["while"]["true"] = "hello"
232+
x = x or "hello"
233+
x = x and "hello"
234+
return x

0 commit comments

Comments
 (0)