summary refs log tree commit diff stats
path: root/luatokens.lua
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2019-04-06 13:32:37 -0300
committerSoniEx2 <endermoneymod@gmail.com>2019-04-06 13:32:37 -0300
commit1f1f6c0732ddb22c7d102a810b6c24724a5b6d3b (patch)
treea83cefd7cb2c3bc8401d23a2cc667f3be069765b /luatokens.lua
parenta6372171c08b21adfc1c9879bd195fcd6a658d18 (diff)
it works?
Diffstat (limited to 'luatokens.lua')
-rw-r--r--luatokens.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/luatokens.lua b/luatokens.lua
index 2ac2cc3..28944c1 100644
--- a/luatokens.lua
+++ b/luatokens.lua
@@ -109,6 +109,7 @@ do local tstring = selfify({})
             ["\n"] = setmetatable({["\r"] = setmetatable({}, {__index=tstring})}, {__index=tstring}),
             ["\r"] = setmetatable({["\n"] = setmetatable({}, {__index=tstring})}, {__index=tstring}),
             [1] = linecount,
+            [2] = function(state, token, rule) if token == "\r" or token == "\n" then collect_fallback(state, "\n") end end,
         }, {__index = tokens.base})
         tokens.string.escapes = tsescapes
         tsescapes.string = tokens.string
@@ -127,7 +128,6 @@ do local tstring = selfify({})
         end
 
         function tsescapes.digit(state, token)
-            print(state, token)
             local digit = string.find("1234567890", token, 1, true)
             local num = state.in_digit
             if digit then
@@ -144,9 +144,19 @@ do local tstring = selfify({})
             collect_fallback(state, string.char(num))
             state.in_digit = nil
             state.c = nil
+            if not digit then
+                collect_fallback(state, token)
+            end
             return "string"
         end
-        tsescapes.digitc = setmetatable(selfify({[""] = tsescapes.digit, digitc = "self", string = tstring}), {__index=tstring})
+        tsescapes.digitc = setmetatable(selfify({[""] = tsescapes.digit, string = tstring}, "digitc"), {__index=tstring})
+        tsescapes.digitc[1]=function(state, token, rule)
+            if rule == nil then
+                collect_fallback(state, string.char(state.in_digit))
+                state.in_digit = nil
+                state.c = nil
+            end
+        end
 
         tsescapes.hex = setmetatable(selfify({string = tokens.string, digit = "hexdigit"}), {__index=tokens.base})
         function tsescapes.hex.hexdigit(state, token)
@@ -197,7 +207,7 @@ do local tstring = selfify({})
             state[COLLECT] = nil
             return "tokens"
         else
-            state[#state+1] = token
+            collect_fallback(state, token)
             return "self"
         end
     end