Skip to content

lazy not working for recursive parser #11

Description

@megakilo

I have this mini parser for add expression. But compiler overflows due to the recursive structure. I saw lazy seems to be the solution for this but can't figure out why it doesn't work.

term : Parser Utf8 U64
term = alt digits (lazy (\_ -> expr) |> between (codeunit '(') (codeunit ')'))

expr : Parser Utf8 U64
expr = const (\x -> \y -> x + y) |> apply (lazy \_ -> term) |> skip (codeunit '+') |> apply (lazy \_ -> term)

expect parseStr expr "1+2" == Ok 3u64
expect parseStr expr "1+(1+2)" == Ok 4u64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions