From d0c71a09ad4aa6f3b8c4ef8a406e2401ffce9e83 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Wed, 29 Dec 2021 15:22:25 -0500 Subject: 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 --- piecemeal.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'piecemeal.lua') 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, } -- cgit v1.2.3