diff --git a/moonscript/compile/value.lua b/moonscript/compile/value.lua index af7320e..2c457dc 100644 --- a/moonscript/compile/value.lua +++ b/moonscript/compile/value.lua @@ -286,6 +286,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, diff --git a/moonscript/compile/value.moon b/moonscript/compile/value.moon index 193a4b5..02ae94c 100644 --- a/moonscript/compile/value.moon +++ b/moonscript/compile/value.moon @@ -173,6 +173,9 @@ string_chars = { number: (node) => node[2] + bitnot: (node) => + @line "~", @value node[2] + length: (node) => @line "#", @value node[2] diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 49b673d..072e4ef 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -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(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 = (Chain + Callable) * Ct(InvokeArgs ^ -1) / join_chain, Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue + String), SliceValue = SimpleValue + ChainValue, diff --git a/moonscript/parse.moon b/moonscript/parse.moon index 556f81d..c87cffa 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -180,8 +180,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(Chain, check_assignable) + Name + SelfName @@ -196,6 +196,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 +