on master help sign in
Use Megaparsec builtins, kill lastTokenSpan
e04da81Jason Felice
src/Idris/AbsSyntaxTree.hs+1−2
@@ -269,7 +269,6 @@ data IState = IState {
269 , lastParse :: Maybe Name
269 , lastParse :: Maybe Name
270 , indent_stack :: [Int]
270 , indent_stack :: [Int]
271 , brace_stack :: [Maybe Int]
271 , brace_stack :: [Maybe Int]
272− , lastTokenSpan :: Maybe FC -- ^ What was the span of the latest token parsed?
273 , idris_parsedSpan :: Maybe FC
272 , idris_parsedSpan :: Maybe FC
274 , hide_list :: Ctxt Accessibility
273 , hide_list :: Ctxt Accessibility
275 , default_access :: Accessibility
274 , default_access :: Accessibility
@@ -407,7 +406,7 @@ idrisInit = IState initContext S.empty []
407 emptyContext emptyContext emptyContext emptyContext
406 emptyContext emptyContext emptyContext emptyContext
408 emptyContext
407 emptyContext
409 [] [] [] defaultOpts 6 [] [] [] [] [] emptySyntaxRules [] [] [] [] [] [] []
408 [] [] [] defaultOpts 6 [] [] [] [] [] emptySyntaxRules [] [] [] [] [] [] []
410− [] [] Nothing [] Nothing [] [] Nothing Nothing emptyContext Private DefaultCheckingPartial [] Nothing [] []
409+ [] [] Nothing [] Nothing [] [] Nothing emptyContext Private DefaultCheckingPartial [] Nothing [] []
411 (RawOutput stdout) True defaultTheme [] (0, emptyContext) emptyContext M.empty
410 (RawOutput stdout) True defaultTheme [] (0, emptyContext) emptyContext M.empty
412 AutomaticWidth S.empty S.empty [] [] [] M.empty [] [] []
411 AutomaticWidth S.empty S.empty [] [] [] M.empty [] [] []
413 emptyContext S.empty M.empty emptyContext initialInteractiveOpts
412 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
72 char = P.char
72 char = P.char
73 string = P.string
73 string = P.string
74
74
75−instance {-# OVERLAPPING #-} Tok.TokenParsing IdrisParser where
75+tokenFC :: IdrisParser a -> IdrisParser (a, FC)
76− someSpace = someSpace'
77− token p = do s <- get
76+tokenFC p = do s <- get
78 (FC fn (sl, sc) _) <- getFC --TODO: Update after fixing getFC
77 (FC fn (sl, sc) _) <- getFC --TODO: Update after fixing getFC
79 -- See Issue #1594
78 -- See Issue #1594
80 r <- p
79 r <- p
81 (FC fn _ (el, ec)) <- getFC
80 (FC fn _ (el, ec)) <- getFC
82 whiteSpace
81 whiteSpace
83− put (s { lastTokenSpan = Just (FC fn (sl, sc) (el, ec)) })
82+ return (r, FC fn (sl, sc) (el, ec))
84− return r
83+
84+instance {-# OVERLAPPING #-} Tok.TokenParsing IdrisParser where
85+ someSpace = someSpace'
86+ token p = p <* whiteSpace
85
87
86-- | Helper to run Idris inner parser based stateT parsers
88-- | Helper to run Idris inner parser based stateT parsers
87runparser :: StateT st IdrisInnerParser res -> st -> String -> String -> Either ParseError res
89runparser :: StateT st IdrisInnerParser res -> st -> String -> String -> Either ParseError res
@@ -227,27 +229,21 @@ whiteSpace = someSpace' <|> pure ()
227
229
228-- | Parses a string literal
230-- | Parses a string literal
229stringLiteral :: IdrisParser (String, FC)
231stringLiteral :: IdrisParser (String, FC)
230−stringLiteral = do str <- Tok.stringLiteral
232+stringLiteral = tokenFC . P.try $ P.char '"' *> P.manyTill P.charLiteral (P.char '"')
231− fc <- lastTokenSpan <$> get
232− return (str, fromMaybe NoFC fc)
233
233
234-- | Parses a char literal
234-- | Parses a char literal
235charLiteral :: IdrisParser (Char, FC)
235charLiteral :: IdrisParser (Char, FC)
236−charLiteral = do ch <- Tok.charLiteral
236+charLiteral = tokenFC . P.try $ P.char '\'' *> P.charLiteral <* P.char '\''
237− fc <- lastTokenSpan <$> get
238− return (ch, fromMaybe NoFC fc)
239
237
240-- | Parses a natural number
238-- | Parses a natural number
241natural :: IdrisParser (Integer, FC)
239natural :: IdrisParser (Integer, FC)
242−natural = do n <- Tok.natural
240+natural = tokenFC ( P.try (P.char '0' *> P.char' 'x' *> P.hexadecimal)
243− fc <- lastTokenSpan <$> get
241+ <|> P.try (P.char '0' *> P.char' 'o' *> P.octal)
244− return (n, fromMaybe NoFC fc)
242+ <|> P.try P.decimal)
245
243
246-- | Parses a floating point number
244-- | Parses a floating point number
247float :: IdrisParser (Double, FC)
245float :: IdrisParser (Double, FC)
248−float = do f <- Tok.double
246+float = tokenFC . P.try $ P.float
249− fc <- lastTokenSpan <$> get
250− return (f, fromMaybe NoFC fc)
251
247
252{- * Symbols, identifiers, names and operators -}
248{- * Symbols, identifiers, names and operators -}
253
249