Skip to content

Commit 330f549

Browse files
Kawahara Satoruleafo
authored andcommitted
add bitwise update assignment operators (#277)
1 parent f2cb2f5 commit 330f549

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

moonscript/parse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ local build_grammar = wrap_env(debug_grammar, function(root)
146146
CompFor = key("for" * Name * sym("=") * Ct(Exp * sym(",") * Exp * (sym(",") * Exp) ^ -1) / mark("for")),
147147
CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"),
148148
Assign = sym("=") * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark("assign"),
149-
Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=")) / trim) * Exp / mark("update"),
149+
Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=") + sym("&=") + sym("|=") + sym(">>=") + sym("<<=")) / trim) * Exp / mark("update"),
150150
CharOperators = Space * C(S("+-*/%^><|&")),
151151
WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op("..") + op("<<") + op(">>") + op("//"),
152152
BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,

moonscript/parse.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ build_grammar = wrap_env debug_grammar, (root) ->
175175
CompClause: CompFor + CompForEach + key"when" * Exp / mark"when"
176176

177177
Assign: sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign"
178-
Update: ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update"
178+
Update: ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=" + sym"&=" + sym"|=" + sym">>=" + sym"<<=") / trim) * Exp / mark"update"
179179

180180
CharOperators: Space * C(S"+-*/%^><|&")
181181
WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<<" + op">>" + op"//"

spec/inputs/syntax.moon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ another hello, one,
243243
a += 3 - 5
244244
a *= 3 + 5
245245
a *= 3
246+
a >>= 3
247+
a <<= 3
246248
a /= func "cool"
247249

248250
---

spec/outputs/syntax.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ another(hello, one, two, three, four, {
241241
a = a + (3 - 5)
242242
a = a * (3 + 5)
243243
a = a * 3
244+
a = a >> 3
245+
a = a << 3
244246
a = a / func("cool")
245247
x["then"] = "hello"
246248
x["while"]["true"] = "hello"

0 commit comments

Comments
 (0)