mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
added Lua5.3's new operators
This commit is contained in:
parent
9e98affc1d
commit
b0904c170c
@ -276,6 +276,9 @@ return {
|
||||
number = function(self, node)
|
||||
return node[2]
|
||||
end,
|
||||
bitnot = function(self, node)
|
||||
return self:line("~", self:value(node[2]))
|
||||
end,
|
||||
length = function(self, node)
|
||||
return self:line("#", self:value(node[2]))
|
||||
end,
|
||||
|
@ -166,6 +166,9 @@ string_chars = {
|
||||
number: (node) =>
|
||||
node[2]
|
||||
|
||||
bitnot: (node) =>
|
||||
@line "~", @value node[2]
|
||||
|
||||
length: (node) =>
|
||||
@line "#", @value node[2]
|
||||
|
||||
|
@ -145,12 +145,12 @@ local build_grammar = wrap_env(debug_grammar, function(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"),
|
||||
CharOperators = Space * C(S("+-*/%^><")),
|
||||
WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op(".."),
|
||||
CharOperators = Space * C(S("+-*/%^><|&")),
|
||||
WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op("..") + op("<<") + op(">>") + op("//"),
|
||||
BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,
|
||||
Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName,
|
||||
Exp = Ct(Value * (BinaryOperator * Value) ^ 0) / flatten_or_mark("exp"),
|
||||
SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num,
|
||||
SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + sym("~") * Exp / mark("bitnot") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num,
|
||||
ChainValue = StringChain + ((Chain + DotChain + Callable) * Ct(InvokeArgs ^ -1)) / flatten_func,
|
||||
Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue),
|
||||
SliceValue = SimpleValue + ChainValue,
|
||||
|
@ -179,8 +179,8 @@ build_grammar = wrap_env debug_grammar, (root) ->
|
||||
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"
|
||||
|
||||
CharOperators: Space * C(S"+-*/%^><")
|
||||
WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".."
|
||||
CharOperators: Space * C(S"+-*/%^><|&")
|
||||
WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<<" + op">>" + op"//"
|
||||
BinaryOperator: (WordOperators + CharOperators) * SpaceBreak^0
|
||||
|
||||
Assignable: Cmt(DotChain + Chain, check_assignable) + Name + SelfName
|
||||
@ -195,6 +195,7 @@ build_grammar = wrap_env debug_grammar, (root) ->
|
||||
Cmt(Do, check_do) +
|
||||
sym"-" * -SomeSpace * Exp / mark"minus" +
|
||||
sym"#" * Exp / mark"length" +
|
||||
sym"~" * Exp / mark"bitnot" +
|
||||
key"not" * Exp / mark"not" +
|
||||
TblComprehension +
|
||||
TableLit +
|
||||
|
Loading…
Reference in New Issue
Block a user