on master help sign in
Use Megaparsec builtins, kill lastTokenSpan
commite04da817d826c7071b454e486ed8d461c88efe25 authorJason Felice <jason.m.felice@gmail.com> dateTue 31 Oct 2017, 17:14 (9 years ago) parent09ae716
2 files changed+14−19
src/Idris/AbsSyntaxTree.hs+1−2 src/Idris/Parser/Helpers.hs+13−17
src/Idris/AbsSyntaxTree.hs+1−2
@@ -269,7 +269,6 @@ data IState = IState {
269269 , lastParse :: Maybe Name
270270 , indent_stack :: [Int]
271271 , brace_stack :: [Maybe Int]
272− , lastTokenSpan :: Maybe FC -- ^ What was the span of the latest token parsed?
273272 , idris_parsedSpan :: Maybe FC
274273 , hide_list :: Ctxt Accessibility
275274 , default_access :: Accessibility
@@ -407,7 +406,7 @@ idrisInit = IState initContext S.empty []
407406 emptyContext emptyContext emptyContext emptyContext
408407 emptyContext
409408 [] [] [] defaultOpts 6 [] [] [] [] [] emptySyntaxRules [] [] [] [] [] [] []
410− [] [] Nothing [] Nothing [] [] Nothing Nothing emptyContext Private DefaultCheckingPartial [] Nothing [] []
409+ [] [] Nothing [] Nothing [] [] Nothing emptyContext Private DefaultCheckingPartial [] Nothing [] []
411410 (RawOutput stdout) True defaultTheme [] (0, emptyContext) emptyContext M.empty
412411 AutomaticWidth S.empty S.empty [] [] [] M.empty [] [] []
413412 emptyContext S.empty M.empty emptyContext initialInteractiveOpts
src/Idris/Parser/Helpers.hs+13−17
@@ -72,16 +72,18 @@ instance Text.Parser.Char.CharParsing IdrisInnerParser where
7272 char = P.char
7373 string = P.string
7474
75−instance {-# OVERLAPPING #-} Tok.TokenParsing IdrisParser where
76− someSpace = someSpace'
77− token p = do s <- get
75+tokenFC :: IdrisParser a -> IdrisParser (a, FC)
76+tokenFC p = do s <- get
7877 (FC fn (sl, sc) _) <- getFC --TODO: Update after fixing getFC
7978 -- See Issue #1594
8079 r <- p
8180 (FC fn _ (el, ec)) <- getFC
8281 whiteSpace
83− put (s { lastTokenSpan = Just (FC fn (sl, sc) (el, ec)) })
84− return r
82+ return (r, FC fn (sl, sc) (el, ec))
83+
84+instance {-# OVERLAPPING #-} Tok.TokenParsing IdrisParser where
85+ someSpace = someSpace'
86+ token p = p <* whiteSpace
8587
8688-- | Helper to run Idris inner parser based stateT parsers
8789runparser :: StateT st IdrisInnerParser res -> st -> String -> String -> Either ParseError res
@@ -227,27 +229,21 @@ whiteSpace = someSpace' <|> pure ()
227229
228230-- | Parses a string literal
229231stringLiteral :: IdrisParser (String, FC)
230−stringLiteral = do str <- Tok.stringLiteral
231− fc <- lastTokenSpan <$> get
232− return (str, fromMaybe NoFC fc)
232+stringLiteral = tokenFC . P.try $ P.char '"' *> P.manyTill P.charLiteral (P.char '"')
233233
234234-- | Parses a char literal
235235charLiteral :: IdrisParser (Char, FC)
236−charLiteral = do ch <- Tok.charLiteral
237− fc <- lastTokenSpan <$> get
238− return (ch, fromMaybe NoFC fc)
236+charLiteral = tokenFC . P.try $ P.char '\'' *> P.charLiteral <* P.char '\''
239237
240238-- | Parses a natural number
241239natural :: IdrisParser (Integer, FC)
242−natural = do n <- Tok.natural
243− fc <- lastTokenSpan <$> get
244− return (n, fromMaybe NoFC fc)
240+natural = tokenFC ( P.try (P.char '0' *> P.char' 'x' *> P.hexadecimal)
241+ <|> P.try (P.char '0' *> P.char' 'o' *> P.octal)
242+ <|> P.try P.decimal)
245243
246244-- | Parses a floating point number
247245float :: IdrisParser (Double, FC)
248−float = do f <- Tok.double
249− fc <- lastTokenSpan <$> get
250− return (f, fromMaybe NoFC fc)
246+float = tokenFC . P.try $ P.float
251247
252248{- * Symbols, identifiers, names and operators -}
253249