add bitwise update assignment operators (#277)

This commit is contained in:
Kawahara Satoru 2016-09-26 03:36:07 +09:00 committed by leaf
parent f2cb2f506c
commit 330f5491d6
4 changed files with 6 additions and 2 deletions

View File

@ -146,7 +146,7 @@ local build_grammar = wrap_env(debug_grammar, function(root)
CompFor = key("for" * Name * sym("=") * Ct(Exp * sym(",") * Exp * (sym(",") * Exp) ^ -1) / mark("for")),
CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"),
Assign = sym("=") * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark("assign"),
Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=")) / trim) * Exp / mark("update"),
Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=") + sym("&=") + sym("|=") + sym(">>=") + sym("<<=")) / trim) * Exp / mark("update"),
CharOperators = Space * C(S("+-*/%^><|&")),
WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op("..") + op("<<") + op(">>") + op("//"),
BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,

View File

@ -175,7 +175,7 @@ build_grammar = wrap_env debug_grammar, (root) ->
CompClause: CompFor + CompForEach + key"when" * Exp / mark"when"
Assign: sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign"
Update: ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update"
Update: ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=" + sym"&=" + sym"|=" + sym">>=" + sym"<<=") / trim) * Exp / mark"update"
CharOperators: Space * C(S"+-*/%^><|&")
WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<<" + op">>" + op"//"

View File

@ -243,6 +243,8 @@ another hello, one,
a += 3 - 5
a *= 3 + 5
a *= 3
a >>= 3
a <<= 3
a /= func "cool"
---

View File

@ -241,6 +241,8 @@ another(hello, one, two, three, four, {
a = a + (3 - 5)
a = a * (3 + 5)
a = a * 3
a = a >> 3
a = a << 3
a = a / func("cool")
x["then"] = "hello"
x["while"]["true"] = "hello"