[Haskell-cafe] parsec manyTill stack overflow
Badea Daniel
badeadaniel at yahoo.com
Fri Jul 4 18:44:53 EDT 2008
I'm using makeTokenParser and buildExpressionParser for
the inner_parser. Thanks for your thoughts, I'll use a
two-stage parser that looks for /end_section> and stores
tokens in heap and then getInput/setInput to feed the
inner_parser.
--- On Fri, 7/4/08, Jonathan Cast <jonathanccast at fastmail.fm> wrote:
> From: Jonathan Cast <jonathanccast at fastmail.fm>
> Subject: Re: [Haskell-cafe] parsec manyTill stack overflow
> To: badeadaniel at yahoo.com
> Cc: "Derek Elkins" <derek.a.elkins at gmail.com>, haskell-cafe at haskell.org
> Date: Friday, July 4, 2008, 3:29 PM
> 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 "/"
>
> say
>
> division_operatory = try $ do
> satisfy (=='/')
> notFollowedBy (string "end_section")
> whitespace
>
> (Or reverse the order or notFollowedBy and whitespace).
>
> jcc
More information about the Haskell-Cafe
mailing list