2929-- | a sequence of lines need to be /folded/ to a single line. An example
3030-- | is MIME headers. Line folding based binding separation is used in
3131-- | Haskell as well.
32- module Text. Parsing.Indent
32+ module Parsing.Indent
3333 ( IndentParser
3434 , runIndent
3535 , withBlock
@@ -61,25 +61,20 @@ import Prelude
6161
6262import Control.Alt ((<|>))
6363import Control.Apply (lift2 )
64- import Control.Monad.State (State , evalState , gets )
64+ import Control.Monad.State (State , evalState )
6565import Control.Monad.State.Trans (get , put )
6666import Control.Monad.Trans.Class (lift )
6767import Data.List (List (..), many )
6868import Data.Maybe (Maybe (..))
69- import Text. Parsing.Parser ( ParseState (ParseState), ParserT , fail )
70- import Text. Parsing.Parser .Combinators (option , optionMaybe )
71- import Text. Parsing.Parser .Pos (Position (..), initialPos )
72- import Text. Parsing.Parser .String (oneOf , string )
69+ import Parsing ( ParserT , fail , position )
70+ import Parsing.Combinators (option , optionMaybe )
71+ import Parsing.Pos (Position (..), initialPos )
72+ import Parsing.String (oneOf , string )
7373
7474-- | Indentation sensitive parser type. Usually @ m @ will
7575-- | be @ Identity @ as with any @ ParserT @
7676type IndentParser s a = ParserT s (State Position ) a
7777
78- -- | @ getPosition @ returns current position
79- -- | should probably be added to Text.Parsing.Parser.Pos
80- getPosition :: forall m s . ParserT s m Position
81- getPosition = gets \(ParseState _ pos _) -> pos
82-
8378-- | simple helper function to avoid typ-problems with MonadState instance
8479get' :: forall s . IndentParser s Position
8580get' = do
@@ -102,7 +97,6 @@ setSourceLine (Position { line: _, column: c }) l = Position { line: l, column:
10297biAp :: forall a b c . (a -> b ) -> (b -> b -> c ) -> a -> a -> c
10398biAp f c v1 v2 = c (f v1) (f v2)
10499
105- -- | @ many1 @ should prabably be inside Text.Parsing.Parser.Combinators
106100many1 :: forall s m a . ParserT s m a -> ParserT s m (List a )
107101many1 p = lift2 Cons p (many p)
108102
@@ -127,7 +121,7 @@ withBlock' = withBlock (flip const)
127121-- | Parses only when indented past the level of the reference
128122indented :: forall s . IndentParser s Unit
129123indented = do
130- pos <- getPosition
124+ pos <- position
131125 s <- get'
132126 if biAp sourceColumn (<=) pos s then fail " not indented"
133127 else do
@@ -137,7 +131,7 @@ indented = do
137131-- | Same as `indented`, but does not change internal state
138132indented' :: forall s . IndentParser s Unit
139133indented' = do
140- pos <- getPosition
134+ pos <- position
141135 s <- get'
142136 if biAp sourceColumn (<=) pos s then fail " not indented" else pure unit
143137
@@ -148,7 +142,7 @@ sameOrIndented = sameLine <|> indented
148142-- | Parses only on the same line as the reference
149143sameLine :: forall s . IndentParser s Unit
150144sameLine = do
151- pos <- getPosition
145+ pos <- position
152146 s <- get'
153147 if biAp sourceLine (==) pos s then pure unit else fail " over one line"
154148
@@ -168,15 +162,15 @@ block p = withPos $ do
168162withPos :: forall s a . IndentParser s a -> IndentParser s a
169163withPos x = do
170164 a <- get'
171- p <- getPosition
165+ p <- position
172166 r <- put' p *> x
173167 put' a *> pure r
174168
175169-- | Ensures the current indentation level matches that of the reference
176170checkIndent :: forall s . IndentParser s Unit
177171checkIndent = do
178172 s <- get'
179- p <- getPosition
173+ p <- position
180174 if biAp sourceColumn (==) p s then pure unit else fail " indentation doesn't match"
181175
182176-- | Run the result of an indentation sensitive parse
0 commit comments