indents 0.3.2 → 0.3.3
raw patch · 2 files changed
+17/−17 lines, 2 files
Files
- Text/Parsec/Indent.hs +16/−16
- indents.cabal +1/−1
Text/Parsec/Indent.hs view
@@ -52,7 +52,7 @@ -- | @ 'withBlock' f a p @ parses @ a @ -- followed by an indented block of @ p @ -- combining them with @ f @-withBlock :: (Stream s (State SourcePos) Char) => (a -> [b] -> c) ->+withBlock :: (Stream s (State SourcePos) z) => (a -> [b] -> c) -> IndentParser s u a -> IndentParser s u b -> IndentParser s u c withBlock f a p = withPos $ do r1 <- a@@ -60,12 +60,12 @@ return (f r1 r2) -- | Like 'withBlock', but throws away initial parse result-withBlock' :: (Stream s (State SourcePos) Char) =>+withBlock' :: (Stream s (State SourcePos) z) => IndentParser s u a -> IndentParser s u b -> IndentParser s u [b] withBlock' = withBlock (flip const) -- | Parses only when indented past the level of the reference-indented :: (Stream s (State SourcePos) Char) => IndentParser s u ()+indented :: (Stream s (State SourcePos) z) => IndentParser s u () indented = do pos <- getPosition s <- get@@ -74,24 +74,24 @@ return () -- | Parses only when indented past the level of the reference or on the same line-sameOrIndented :: Stream s (State SourcePos) Char => IndentParser s u ()+sameOrIndented :: Stream s (State SourcePos) z => IndentParser s u () sameOrIndented = same <|> indented -- | Parses only on the same line as the reference-same :: (Stream s (State SourcePos) Char) => IndentParser s u ()+same :: (Stream s (State SourcePos) z) => IndentParser s u () same = do pos <- getPosition s <- get if biAp sourceLine (==) pos s then return () else parserFail "over one line" -- | Parses a block of lines at the same indentation level-block :: (Stream s (State SourcePos) Char) => IndentParser s u a -> IndentParser s u [a]+block :: (Stream s (State SourcePos) z) => IndentParser s u a -> IndentParser s u [a] block p = withPos $ do r <- many1 (checkIndent >> p) return r -- | Parses using the current location for indentation reference-withPos :: (Stream s (State SourcePos) Char) => IndentParser s u a -> IndentParser s u a+withPos :: (Stream s (State SourcePos) z) => IndentParser s u a -> IndentParser s u a withPos x = do a <- get p <- getPosition@@ -99,7 +99,7 @@ put a >> return r -- | Ensures the current indentation level matches that of the reference-checkIndent :: (Stream s (State SourcePos) Char) => IndentParser s u ()+checkIndent :: (Stream s (State SourcePos) z) => IndentParser s u () checkIndent = do s <- get p <- getPosition@@ -110,17 +110,17 @@ runIndent s = flip evalState (initialPos s) -- | '<+/>' is to indentation sensitive parsers what 'ap' is to monads-(<+/>) :: (Stream s (State SourcePos) Char) =>+(<+/>) :: (Stream s (State SourcePos) z) => IndentParser s u (a -> b) -> IndentParser s u a -> IndentParser s u b a <+/> b = ap a (sameOrIndented >> b) -- | '<-/>' is like '<+/>', but doesn't apply the function to the parsed value-(<-/>) :: (Stream s (State SourcePos) Char) =>+(<-/>) :: (Stream s (State SourcePos) z) => IndentParser s u a -> IndentParser s u b -> IndentParser s u a a <-/> b = liftM2 const a (sameOrIndented >> b) -- | Like '<+/>' but applies the second parser many times-(<*/>) :: (Stream s (State SourcePos) Char) =>+(<*/>) :: (Stream s (State SourcePos) z) => IndentParser s u ([a] -> b) -> IndentParser s u a -> IndentParser s u b a <*/> b = ap a (many (sameOrIndented >> b)) @@ -128,22 +128,22 @@ data Optional s u a = Opt a (IndentParser s u a) -- | Like '<+/>' but applies the second parser optionally using the 'Optional' datatype-(<?/>) :: (Stream s (State SourcePos) Char) =>+(<?/>) :: (Stream s (State SourcePos) z) => IndentParser s u (a -> b) -> (Optional s u a) -> IndentParser s u b (<?/>) a (Opt b c) = ap a (option b (sameOrIndented >> c)) -- | parses with surrounding brackets-indentBrackets :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a+indentBrackets :: (Stream s (State SourcePos) z) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentBrackets lexer p = withPos $ return id <-/> symbol lexer "[" <+/> p <-/> symbol lexer "]" -- | parses with surrounding angle brackets-indentAngles :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a+indentAngles :: (Stream s (State SourcePos) z) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentAngles lexer p = withPos $ return id <-/> symbol lexer "<" <+/> p <-/> symbol lexer ">" -- | parses with surrounding braces-indentBraces :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a+indentBraces :: (Stream s (State SourcePos) z) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentBraces lexer p = withPos $ return id <-/> symbol lexer "{" <+/> p <-/> symbol lexer "}" -- | parses with surrounding parentheses -indentParens :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a+indentParens :: (Stream s (State SourcePos) z) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentParens lexer p = withPos $ return id <-/> symbol lexer "(" <+/> p <-/> symbol lexer ")"
indents.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.3.2+Version: 0.3.3 -- A short (one-line) description of the package. Synopsis: indentation sensitive parser-combinators for parsec