mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
fixed number literals (all lua ones supported)
integer, float and hex
This commit is contained in:
parent
0f3ce4b55b
commit
05b3a8f989
@ -322,6 +322,9 @@ value_compile = {
|
|||||||
minus = function(self, node)
|
minus = function(self, node)
|
||||||
return self:line("-", self:value(node[2]))
|
return self:line("-", self:value(node[2]))
|
||||||
end,
|
end,
|
||||||
|
number = function(self, node)
|
||||||
|
return 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,
|
||||||
|
@ -183,6 +183,9 @@ value_compile =
|
|||||||
minus: (node) =>
|
minus: (node) =>
|
||||||
@line "-", @value node[2]
|
@line "-", @value node[2]
|
||||||
|
|
||||||
|
number: (node) =>
|
||||||
|
node[2]
|
||||||
|
|
||||||
length: (node) =>
|
length: (node) =>
|
||||||
@line "#", @value node[2]
|
@line "#", @value node[2]
|
||||||
|
|
||||||
|
@ -39,7 +39,11 @@ local SomeSpace = S" \t"^1 * Comment^-1
|
|||||||
|
|
||||||
local _Name = C(R("az", "AZ", "__") * R("az", "AZ", "09", "__")^0)
|
local _Name = C(R("az", "AZ", "__") * R("az", "AZ", "09", "__")^0)
|
||||||
local Name = Space * _Name
|
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 FactorOp = Space * C(S"+-")
|
||||||
local TermOp = Space * C(S"*/%^")
|
local TermOp = Space * C(S"*/%^")
|
||||||
|
21
tests/inputs/literals.moon
Normal file
21
tests/inputs/literals.moon
Normal file
@ -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'
|
21
tests/inputs/using.moon
Normal file
21
tests/inputs/using.moon
Normal file
@ -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"
|
||||||
|
|
||||||
|
|
14
tests/outputs/literals.lua
Normal file
14
tests/outputs/literals.lua
Normal file
@ -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'
|
@ -176,7 +176,7 @@ x = hello - world - something
|
|||||||
return print(something)
|
return print(something)
|
||||||
end)()
|
end)()
|
||||||
if something then
|
if something then
|
||||||
_ = 3589
|
_ = 03589
|
||||||
else
|
else
|
||||||
_ = 3434
|
_ = 3434
|
||||||
end
|
end
|
||||||
|
20
tests/outputs/using.lua
Normal file
20
tests/outputs/using.lua
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user