I am trying to parse a recursive structure using 
http://package.elm-lang.org/packages/elm-tools/parser/latest . 

Here is an try: https://ellie-app.com/WwGfQGWRHfa1/9 

For example, I'd like to parse something like this:
>> "ab"
  >> "cd"
    >> "ef"
  >> "gh"
    >> "ij"
      >> "kl"
      >> "mn"

into a data structure like this:
type Step
    = Step String (List Step)

The parser basically comes down to this:
step : Int -> Parser Step
step i =
    inContext ("step with indent " ++ (toString i)) <|
        succeed
            Step
            |. (indent i)
            |. keyword ">>"
            |. spaces
            |= string
            |. eol
            |= repeat zeroOrMore (lazy (\_ -> (step (i + 2))))


This works fine for 
>> "ab"
  >> "cd"
    >> "ef"
      >> "gh"
        >> "ij"

But not for the example given above, or something like
>> "ab"
  >> "cd"
    >> "ef"
    >> "gh"
      >> "ij"


The error is a *BadRepeat*, of which the documentation says you get it for 
parsers that use a *repeat zeroOrMore* and always succeed, which is clearly 
the case with the parser above. The thing, is, i don't know how to create a 
parser that fails. I have tried avoiding the zeroOrMore, and use a 
oneOrMore instead: 
            |= oneOf 
                [ repeat oneOrMore (lazy (\_ -> (step (i + 2))))
                , succeed []
                ]
But fundamentally, that has the same problem, i think.

Since the library is quite new, there is not that much to find on the 
strategies to be used. Can anyone point me in a direction i could try? I am 
stuck. (Can't get it to work with elm-community/parser-combinators either).

thanks,

eelco


Extra question: the elm-tools/parser library comes with indent tooling, but 
i can't figure out how to get it to work. Any pointers there would also be 
highly appreciated.


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to