Text.Parsing.Indent
- Package
- purescript-parsing
- Repository
- purescript-contrib/purescript-parsing
This is purescript-port of Text.Parsing.Indent https://hackage.haskell.org/package/indents-0.3.3/docs/Text-Parsec-Indent.html, 05.07.2016. A module to construct indentation aware parsers. Many programming language have indentation based syntax rules e.g. python and Haskell. This module exports combinators to create such parsers.
The input source can be thought of as a list of tokens. Abstractly each token occurs at a line and a column and has a width. The column number of a token measures is indentation. If t1 and t2 are two tokens then we say that indentation of t1 is more than t2 if the column number of occurrence of t1 is greater than that of t2.
Currently this module supports two kind of indentation based syntactic structures which we now describe:
Block
A block of indentation /c/ is a sequence of tokens with indentation at least /c/. Examples for a block is a where clause of Haskell with no explicit braces.
Line fold
A line fold starting at line /l/ and indentation /c/ is a sequence of tokens that start at line /l/ and possibly continue to subsequent lines as long as the indentation is greater than /c/. Such a sequence of lines need to be /folded/ to a single line. An example is MIME headers. Line folding based binding separation is used in Haskell as well.
#IndentParser Source
type IndentParser s a = ParserT s (State Position) a
Indentation sensitive parser type. Usually @ m @ will be @ Identity @ as with any @ ParserT @
#withBlock Source
withBlock :: forall s c b a. (a -> List b -> c) -> IndentParser s a -> IndentParser s b -> IndentParser s c
withBlock f a p
parses a
followed by an indented block of p
combining them with f
.
#withBlock' Source
withBlock' :: forall s b a. IndentParser s a -> IndentParser s b -> IndentParser s (List b)
Like 'withBlock', but throws away initial parse result
#block Source
block :: forall a s. IndentParser s a -> IndentParser s (List a)
Parses a block of lines at the same indentation level , empty Blocks allowed
#block1 Source
block1 :: forall a s. IndentParser s a -> IndentParser s (List a)
Parses a block of lines at the same indentation level
#indented Source
indented :: forall s. IndentParser s Unit
Parses only when indented past the level of the reference
#indented' Source
indented' :: forall s. IndentParser s Unit
Same as indented
, but does not change internal state
#sameLine Source
sameLine :: forall s. IndentParser s Unit
Parses only on the same line as the reference
#sameOrIndented Source
sameOrIndented :: forall s. IndentParser s Unit
Parses only when indented past the level of the reference or on the same line
#checkIndent Source
checkIndent :: forall s. IndentParser s Unit
Ensures the current indentation level matches that of the reference
#withPos Source
withPos :: forall a s. IndentParser s a -> IndentParser s a
Parses using the current location for indentation reference
#indentAp Source
indentAp :: forall b a s. IndentParser s (a -> b) -> IndentParser s a -> IndentParser s b
<+/>
is to indentation sensitive parsers what ap
is to monads
#indentNoAp Source
indentNoAp :: forall b a s. IndentParser s a -> IndentParser s b -> IndentParser s a
Like <+/>
but doesn't apply the function to the parsed value
#indentMany Source
indentMany :: forall b a s. IndentParser s (List a -> b) -> IndentParser s a -> IndentParser s b
Like <+/>
but applies the second parser many times
#indentOp Source
indentOp :: forall b a s. IndentParser s (a -> b) -> Optional s a -> IndentParser s b
Like <+/>
but applies the second parser optionally using the Optional
datatype