summary refs log tree commit diff stats
path: root/parser.lua
diff options
context:
space:
mode:
Diffstat (limited to 'parser.lua')
-rw-r--r--parser.lua17
1 files changed, 10 insertions, 7 deletions
diff --git a/parser.lua b/parser.lua
index 12397ef..7410571 100644
--- a/parser.lua
+++ b/parser.lua
@@ -95,7 +95,11 @@ end
 
 local function get_next_table(state, in_pos)
     if state[DATA] == nil or #state[DATA] == 0 then
-        return get_next_common(state, in_pos, EOZ)
+        if state[STATE] == nil then
+            return in_pos, state
+        else
+            return get_next_common(state, in_pos, EOZ)
+        end
     end
     in_pos = in_pos + 1
     local token = state[DATA][in_pos - state[OFFDATA]]
@@ -129,15 +133,14 @@ local function stream(defs, data)
     local state = {}
     local fn
     state[STATE] = defs
-    if type(data) == "string" then
-        state[DATA] = data
-        state[GEN] = function() end
-        fn = get_next_string
-    else
+    if type(data) == "function" then
         state[DATA] = data()
         state[GEN] = data
-        fn = type(state[DATA]) == "string" and get_next_string or get_next_table
+    else
+        state[DATA] = data
+        state[GEN] = function() end
     end
+    fn = type(state[DATA]) == "table" and get_next_table or get_next_string
     state[OFFDATA] = 0
     return fn, state, state[OFFDATA]
 end