Merge branch 'lua5.3_operators' of https://github.com/Nymphium/moonscript into Nymphium-lua5.3_operators

This commit is contained in:
leaf corcoran 2015-12-27 22:36:13 -08:00
commit 93a1bffe0c
4 changed files with 12 additions and 5 deletions

View File

@ -286,6 +286,9 @@ return {
number = function(self, node) number = function(self, node)
return node[2] return node[2]
end, end,
bitnot = function(self, node)
return self:line("~", self:value(node[2]))
end,
length = function(self, node) length = function(self, node)
return self:line("#", self:value(node[2])) return self:line("#", self:value(node[2]))
end, end,

View File

@ -173,6 +173,9 @@ string_chars = {
number: (node) => number: (node) =>
node[2] node[2]
bitnot: (node) =>
@line "~", @value node[2]
length: (node) => length: (node) =>
@line "#", @value node[2] @line "#", @value node[2]

View File

@ -145,12 +145,12 @@ local build_grammar = wrap_env(debug_grammar, function(root)
CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"), CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"),
Assign = sym("=") * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark("assign"), 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=")) / trim) * Exp / mark("update"),
CharOperators = Space * C(S("+-*/%^><")), CharOperators = Space * C(S("+-*/%^><|&")),
WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op(".."), WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op("..") + op("<<") + op(">>") + op("//"),
BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0, BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,
Assignable = Cmt(Chain, check_assignable) + Name + SelfName, Assignable = Cmt(Chain, check_assignable) + Name + SelfName,
Exp = Ct(Value * (BinaryOperator * Value) ^ 0) / flatten_or_mark("exp"), 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 = (Chain + Callable) * Ct(InvokeArgs ^ -1) / join_chain, ChainValue = (Chain + Callable) * Ct(InvokeArgs ^ -1) / join_chain,
Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue + String), Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue + String),
SliceValue = SimpleValue + ChainValue, SliceValue = SimpleValue + ChainValue,

View File

@ -180,8 +180,8 @@ build_grammar = wrap_env debug_grammar, (root) ->
Assign: sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign" 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=") / trim) * Exp / mark"update"
CharOperators: Space * C(S"+-*/%^><") CharOperators: Space * C(S"+-*/%^><|&")
WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<<" + op">>" + op"//"
BinaryOperator: (WordOperators + CharOperators) * SpaceBreak^0 BinaryOperator: (WordOperators + CharOperators) * SpaceBreak^0
Assignable: Cmt(Chain, check_assignable) + Name + SelfName Assignable: Cmt(Chain, check_assignable) + Name + SelfName
@ -196,6 +196,7 @@ build_grammar = wrap_env debug_grammar, (root) ->
Cmt(Do, check_do) + Cmt(Do, check_do) +
sym"-" * -SomeSpace * Exp / mark"minus" + sym"-" * -SomeSpace * Exp / mark"minus" +
sym"#" * Exp / mark"length" + sym"#" * Exp / mark"length" +
sym"~" * Exp / mark"bitnot" +
key"not" * Exp / mark"not" + key"not" * Exp / mark"not" +
TblComprehension + TblComprehension +
TableLit + TableLit +