[Haskell-cafe] parsec manyTill stack overflow

Jonathan Cast jonathanccast at fastmail.fm
Fri Jul 4 18:29:33 EDT 2008

On Fri, 2008-07-04 at 15:15 -0700, Badea Daniel wrote:
> The file I'm trying to parse contains mixed sections like:
> ...
> <start_section=
> ... script including arithmetic expressions ...
> /end_section>
> ...
> so I defined two parsers: one for the 'outer' language and 
> the other one for the 'inner' language.  I used (manyTill 
> inner_parser end_section_parser)

Does inner_parser (or a parser it calls) recognize `/end_section'?  If
not, I don't think you actually need manyTill.  If so, that's more
difficult.  Two thoughts:

* This design looks vaguely XML-ish; is it possible to use a two-stage
parser, recognizing but not parsing the arithmetic expressions and then
looping back over the parse tree later?

* If the part of inner_parser that would recognize /end_section
(presumably as a division operator followed by an identifier?) is well
isolated, you could locally exclude it there; e.g., instead of

divison_operator = operator "/"


division_operatory = try $ do
  satisfy (=='/')
  notFollowedBy (string "end_section")

(Or reverse the order or notFollowedBy and whitespace).


More information about the Haskell-Cafe mailing list