added Lua5.3's new operators

This commit is contained in:
nymphium 2015-08-13 18:02:30 +09:00
parent 9e98affc1d
commit b0904c170c
4 changed files with 12 additions and 5 deletions

View File

@ -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,

View File

@ -166,6 +166,9 @@ string_chars = {
number: (node) =>
node[2]
bitnot: (node) =>
@line "~", @value node[2]
length: (node) =>
@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"),
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,

View File

@ -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 +