diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2019-04-10 19:41:50 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2019-04-10 19:41:50 -0300 |
commit | 4cff82dd045c8acf5820768d7195327082d55950 (patch) | |
tree | 147bc8c98499e8e226689e9607d53c8d0a4f7605 /parser.lua | |
parent | c77a2df387edc3f975143cf1aaab48e4c761bf5b (diff) |
Allow parser.lua to be used as an argument parser
Diffstat (limited to 'parser.lua')
-rw-r--r-- | parser.lua | 17 |
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 |