on master help sign in
Added span in parser state
commit419b35c2a4eb372b13db00e6abc951fd76be26d7 authorAhmad Salim Al-Sibahi <asal@itu.dk> dateThu 6 Mar 2014, 10:52 (13 years ago) parent66ac8da
2 files changed+12−5
src/Idris/AbsSyntaxTree.hs+2−1 src/Idris/ParseHelpers.hs+10−4
src/Idris/AbsSyntaxTree.hs+2−1
@@ -137,6 +137,7 @@ data IState = IState {
137137 lastParse :: Maybe Name,
138138 indent_stack :: [Int],
139139 brace_stack :: [Maybe Int],
140+ lastTokenSpan :: Maybe (FC, FC), -- ^ What was the span of the latest token parsed?
140141 hide_list :: [(Name, Maybe Accessibility)],
141142 default_access :: Accessibility,
142143 default_total :: Bool,
@@ -221,7 +222,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
221222 emptyContext emptyContext emptyContext emptyContext
222223 emptyContext emptyContext
223224 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
224− [] Nothing [] Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
225+ [] Nothing [] Nothing [] [] Nothing [] Hidden False [] Nothing [] [] RawOutput
225226 True defaultTheme stdout [] (0, emptyContext) emptyContext M.empty
226227 AutomaticWidth
227228
src/Idris/ParseHelpers.hs+10−4
@@ -1,4 +1,4 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving, ConstraintKinds, PatternGuards #-}
1+{-# LANGUAGE GeneralizedNewtypeDeriving, ConstraintKinds, PatternGuards, OverlappingInstances #-}
22module Idris.ParseHelpers where
33
44import Prelude hiding (pi)
@@ -41,11 +41,17 @@ import Debug.Trace
4141type IdrisParser = StateT IState IdrisInnerParser
4242
4343newtype IdrisInnerParser a = IdrisInnerParser { runInnerParser :: Parser a }
44− deriving (Monad, Functor, MonadPlus, Applicative, Alternative, CharParsing, LookAheadParsing, Parsing, DeltaParsing, MarkParsing Delta, Monoid)
44+ deriving (Monad, Functor, MonadPlus, Applicative, Alternative, CharParsing, LookAheadParsing, Parsing, DeltaParsing, MarkParsing Delta, Monoid, TokenParsing)
4545
46−instance TokenParsing IdrisInnerParser where
46+instance TokenParsing IdrisParser where
4747 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
48−
48+ token p = do s <- get
49+ startFC <- getFC
50+ r <- p
51+ endFC <- getFC
52+ whiteSpace
53+ put (s { lastTokenSpan = Just (startFC, endFC) })
54+ return r
4955-- | Generalized monadic parsing constraint type
5056type MonadicParsing m = (DeltaParsing m, LookAheadParsing m, TokenParsing m, Monad m)
5157