fixed number literals (all lua ones supported)

integer, float and hex
This commit is contained in:
leaf corcoran 2011-08-12 19:33:41 -07:00
parent 0f3ce4b55b
commit 05b3a8f989
8 changed files with 88 additions and 2 deletions

View File

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

View File

@ -183,6 +183,9 @@ value_compile =
minus: (node) =>
@line "-", @value node[2]
number: (node) =>
node[2]
length: (node) =>
@line "#", @value node[2]

View File

@ -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"*/%^")

View 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
View 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"

View 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'

View File

@ -176,7 +176,7 @@ x = hello - world - something
return print(something)
end)()
if something then
_ = 3589
_ = 03589
else
_ = 3434
end

20
tests/outputs/using.lua Normal file
View 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