How do I make this parser recursive?

I want to make a parser that can handle a recursive data structure. E.g.

["a", ["b"]]

["a", ["b", ["c", "d"]]]

Here is my attempt

The first example above should parse into AstList [AstVal "a", AstList [AstVal "b" ] ]

In listParser I tried setting item = parser, but the compiler complains with:

The `listParser` value depends on itself through the following chain of

    │    listParser
    │     ↓
    │    parser

How can I make this parser recursive? Thanks

You are looking for Parser.lazy ?

1 Like

That was it, so simple, thanks

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.