From 1699c9e9ba597dacd405c9bef5768fad35f12344 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Tue, 12 Jun 2018 21:56:53 -0700 Subject: [PATCH] Add api to begin and end a span of source code --- src/ShellCheck/Parser.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index a608403..3cb2411 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -188,6 +188,27 @@ getNextId = do pos <- getPosition getNextIdAt pos +data IncompleteInterval = IncompleteInterval SourcePos + +startSpan = IncompleteInterval <$> getPosition + +endSpan (IncompleteInterval start) = do + id <- getNextIdAt start + endPos <- getPosition + state <- getState + let setEndPos (start, _) = Just (start, Just endPos) + let newMap = Map.update setEndPos id (positionMap state) + putState $ state { + lastId = id, + positionMap = newMap + } + return id + +zeroWidthSpan = do + start <- startSpan + id <- endSpan start + return id + endPosOfStartId s = do endPos <- getPosition state <- getState