summary refs log tree commit diff stats
path: root/luatokens.lua
diff options
context:
space:
mode:
Diffstat (limited to 'luatokens.lua')
-rw-r--r--luatokens.lua82
1 files changed, 75 insertions, 7 deletions
diff --git a/luatokens.lua b/luatokens.lua
index af53d45..5217ab5 100644
--- a/luatokens.lua
+++ b/luatokens.lua
@@ -581,11 +581,14 @@ defs["."] = setmetatable({
         if token ~= "." then
             if rule ~= "digit" then
                 state[#state+1] = "."
-            else
-                error("NYI") -- TODO digit handling
             end
         end
     end,
+    digit = function(state, token, rule)
+        state[#state+1] = TK_FLT
+        state[COLLECT] = {".", coalesce=31}
+        return "in_decimal"
+    end,
     ["."] = setmetatable({
         [-1] = function(state, token, rule)
             if token ~= "." then
@@ -595,17 +598,82 @@ defs["."] = setmetatable({
         ["."] = function(state, token)
             state[#state+1] = TK_DOTS
             return "self" -- actually goes into defs
-        end
+        end,
     }, {__index=defs})
 }, {__index=defs})
 
 function defs.digit(state, token)
-    -- TODO
+    state[COLLECT] = {token, coalesce=31}
+    if token == "0" then
+        return "in_zero"
+    else
+        return "in_integer"
+    end
 end
 
-defs.in_digit = {
-    -- TODO
-}
+defs.in_integer = setmetatable(selfify({
+    hexdigit = "alpha",
+    alpha = false,
+    ['e'] = "exp",
+    ['E'] = "exp",
+    exp = function(state, token)
+        collect_fallback(state, token)
+        return "in_exp"
+    end,
+    ['.'] = function(state, token)
+        collect_fallback(state, token)
+        return "in_decimal"
+    end,
+    digit = function(state, token)
+        collect_fallback(state, token)
+        return "in_digit"
+    end,
+}, "in_digit"), {__index=defs})
+
+defs.in_zero = setmetatable({
+    ['x'] = function(state, token)
+        collect_fallback(state, token)
+        return "in_hex"
+    end,
+}, {__index=defs.in_integer})
+
+defs.in_decimal = setmetatable(selfify({
+    ['.'] = false,
+}, "in_digit"), {__index=defs.in_integer})
+
+defs.in_expnum = setmetatable(selfify({
+    exp = false,
+}, "in_digit"), {__index=defs.in_decimal})
+
+defs.in_subexp = setmetatable({
+    in_expnum = defs.in_expnum,
+    digit = function(state, token)
+        collect_fallback(state, token)
+        return "in_expnum"
+    end,
+}, {__index=defs.base})
+
+defs.in_exp = setmetatable({
+    ["+"] = "sign",
+    ["-"] = "sign",
+    sign = function(state, token)
+        collect_fallback(state, token)
+        return "in_subexp"
+    end,
+}, {__index=defs.in_subexp})
+
+defs.in_hex = setmetatable({
+    in_decimal = "in_hex_fraction",
+    hexdigit = 'digit',
+    ['e'] = 'hexdigit',
+    ['E'] = 'hexdigit',
+    ['p'] = 'exp',
+    ['P'] = 'exp',
+}, {__index=defs.in_integer})
+
+defs.in_hex_fraction = setmetatable({
+    ['.'] = false,
+}, {__index=defs.in_hex})
 
 function defs.simpletoken(state, token)
     state[#state+1] = token