on master help sign in
Added span in parser state
419b35cAhmad Salim Al-Sibahi
src/Idris/AbsSyntaxTree.hs+2−1
@@ -137,6 +137,7 @@ data IState = IState {
137 lastParse :: Maybe Name,
137 lastParse :: Maybe Name,
138 indent_stack :: [Int],
138 indent_stack :: [Int],
139 brace_stack :: [Maybe Int],
139 brace_stack :: [Maybe Int],
140+ lastTokenSpan :: Maybe (FC, FC), -- ^ What was the span of the latest token parsed?
140 hide_list :: [(Name, Maybe Accessibility)],
141 hide_list :: [(Name, Maybe Accessibility)],
141 default_access :: Accessibility,
142 default_access :: Accessibility,
142 default_total :: Bool,
143 default_total :: Bool,
@@ -221,7 +222,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
221 emptyContext emptyContext emptyContext emptyContext
222 emptyContext emptyContext emptyContext emptyContext
222 emptyContext emptyContext
223 emptyContext emptyContext
223 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
224 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
224− [] Nothing [] Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
225+ [] Nothing [] Nothing [] [] Nothing [] Hidden False [] Nothing [] [] RawOutput
225 True defaultTheme stdout [] (0, emptyContext) emptyContext M.empty
226 True defaultTheme stdout [] (0, emptyContext) emptyContext M.empty
226 AutomaticWidth
227 AutomaticWidth
227
228
src/Idris/ParseHelpers.hs+10−4
@@ -1,4 +1,4 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving, ConstraintKinds, PatternGuards #-}
1+{-# LANGUAGE GeneralizedNewtypeDeriving, ConstraintKinds, PatternGuards, OverlappingInstances #-}
2module Idris.ParseHelpers where
2module Idris.ParseHelpers where
3
3
4import Prelude hiding (pi)
4import Prelude hiding (pi)
@@ -41,11 +41,17 @@ import Debug.Trace
41type IdrisParser = StateT IState IdrisInnerParser
41type IdrisParser = StateT IState IdrisInnerParser
42
42
43newtype IdrisInnerParser a = IdrisInnerParser { runInnerParser :: Parser a }
43newtype 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)
45
45
46−instance TokenParsing IdrisInnerParser where
46+instance TokenParsing IdrisParser where
47 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
47 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
49-- | Generalized monadic parsing constraint type
55-- | Generalized monadic parsing constraint type
50type MonadicParsing m = (DeltaParsing m, LookAheadParsing m, TokenParsing m, Monad m)
56type MonadicParsing m = (DeltaParsing m, LookAheadParsing m, TokenParsing m, Monad m)
51
57