diff options
| author | 2021-12-29 15:22:25 -0500 | |
|---|---|---|
| committer | 2021-12-29 15:22:25 -0500 | |
| commit | d0c71a09ad4aa6f3b8c4ef8a406e2401ffce9e83 (patch) | |
| tree | 41f53d39c951587d4972ba37dd445ac25233fa90 /piecemeal.lua | |
| parent | add rockspec (diff) | |
change pm.parse api
before: returns eind, out as-is from the top parser
after: returns the output, the string index of the final token, and
(in the case of failure) the string index of the would-be next token
Diffstat (limited to 'piecemeal.lua')
| -rw-r--r-- | piecemeal.lua | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/piecemeal.lua b/piecemeal.lua index 0f6dd6c..bec9c04 100644 --- a/piecemeal.lua +++ b/piecemeal.lua @@ -101,6 +101,12 @@ return { next = lexer:next() if next then table.insert(tokens, next) end until next == nil - return parser(tokens, 1) + local eind, out = parser(tokens, 1) + -- a successful parse means eind is >1 the length of tokens + if tokens[eind] then -- so this is unsuccessful + return out, tokens[eind-1].stop, tokens[eind].start + else -- and this is + return out, tokens[eind-1].stop, nil + end end, } |
