diff --git a/moonscript/compile/value.lua b/moonscript/compile/value.lua index 5a8f1f1..4395cdf 100644 --- a/moonscript/compile/value.lua +++ b/moonscript/compile/value.lua @@ -322,6 +322,9 @@ value_compile = { minus = function(self, node) return self:line("-", self:value(node[2])) end, + number = function(self, node) + return 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 245b423..54c1124 100644 --- a/moonscript/compile/value.moon +++ b/moonscript/compile/value.moon @@ -183,6 +183,9 @@ value_compile = minus: (node) => @line "-", @value node[2] + number: (node) => + node[2] + length: (node) => @line "#", @value node[2] diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 7124612..8780d59 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -39,7 +39,11 @@ local SomeSpace = S" \t"^1 * Comment^-1 local _Name = C(R("az", "AZ", "__") * R("az", "AZ", "09", "__")^0) local Name = Space * _Name -local Num = Space * C(R("09")^1) / tonumber + +local Num = P"0x" * R("09", "af", "AF")^1 + + R"09"^1 * (P"." * R"09"^1)^-1 * (S"eE" * P"-"^-1 * R"09"^1)^-1 + +Num = Space * (Num / function(value) return {"number", value} end) local FactorOp = Space * C(S"+-") local TermOp = Space * C(S"*/%^") diff --git a/tests/inputs/literals.moon b/tests/inputs/literals.moon new file mode 100644 index 0000000..ef80828 --- /dev/null +++ b/tests/inputs/literals.moon @@ -0,0 +1,21 @@ + + +121 +121.2323 +121.2323e-1 +121.2323e13434 +2323E34 +0x12323 + +0xfF2323 +0xabcdef +0xABCDEF + +[[ hello world ]] + +[=[ hello world ]=] +[====[ hello world ]====] + +"another world" + +'what world' diff --git a/tests/inputs/using.moon b/tests/inputs/using.moon new file mode 100644 index 0000000..55a16a7 --- /dev/null +++ b/tests/inputs/using.moon @@ -0,0 +1,21 @@ + +hello = "hello" +world = "world" + +(using nil) -> + hello = 3223 + +(a using nil) -> + hello = 3223 + a = 323 + +(a,b,c using a,b,c) -> + a,b,c = 1,2,3 + world = 12321 + +(a,e,f using a,b,c, hello) -> + a,b,c = 1,2,3 + hello = 12321 + world = "yeah" + + diff --git a/tests/outputs/literals.lua b/tests/outputs/literals.lua new file mode 100644 index 0000000..0f78e4c --- /dev/null +++ b/tests/outputs/literals.lua @@ -0,0 +1,14 @@ +local _ = 121 +_ = 121.2323 +_ = 121.2323e-1 +_ = 121.2323e13434 +_ = 2323E34 +_ = 0x12323 +_ = 0xfF2323 +_ = 0xabcdef +_ = 0xABCDEF +_ = [[ hello world ]] +_ = [=[ hello world ]=] +_ = [====[ hello world ]====] +_ = "another world" +_ = 'what world' \ No newline at end of file diff --git a/tests/outputs/syntax.lua b/tests/outputs/syntax.lua index fa6ba7b..ec630d5 100644 --- a/tests/outputs/syntax.lua +++ b/tests/outputs/syntax.lua @@ -176,7 +176,7 @@ x = hello - world - something return print(something) end)() if something then - _ = 3589 + _ = 03589 else _ = 3434 end diff --git a/tests/outputs/using.lua b/tests/outputs/using.lua new file mode 100644 index 0000000..2ab4101 --- /dev/null +++ b/tests/outputs/using.lua @@ -0,0 +1,20 @@ +local hello = "hello" +local world = "world" +local _ +_ = function() + local hello = 3223 +end +_ = function(a) + local hello = 3223 + a = 323 +end +_ = function(a, b, c) + a, b, c = 1, 2, 3 + local world = 12321 +end +_ = function(a, e, f) + local b, c + a, b, c = 1, 2, 3 + hello = 12321 + local world = "yeah" +end \ No newline at end of file