Text.Parsec.Indent collects indented content

import Control.Applicative
import Text.Parsec hiding (many, (<|>))
import Text.Parsec.Indent
data Markup = Tag String [Markup] deriving (Show)

run sourceName p source = runIndent sourceName (runParserT (many1 p <* eof) () sourceName source)

parser = withBlock ($) (tag <* spaces) parser
tag = Tag <$> many1 alphaNum

This basically works as I expect, but when I give it a line like "hello \ n \ twoo \ nhai hai" - the second "hai" is inserted inside the first, although there are no indents? What's going on here?

UPDATE: looks like this:

parser = withBlock ($) (tag <* inlineSpace <* newline <* inlineSpace) parser
inlineSpace = skipMany (satisfy isInlineSpace) <?> "inline white space"
isInlineSpace c = c /= '\n' && isSpace c

So it seems that it withBlockexpects the parser that you give it to itself to fulfill the line requirement of a new line and not check the line position of the allegedly nested elements.

+4
source share

Source: https://habr.com/ru/post/1525515/


All Articles