Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Runtime crash with simple recursive grammar #7

Closed
newlandsvalley opened this issue Jan 31, 2016 · 3 comments
Closed

Runtime crash with simple recursive grammar #7

newlandsvalley opened this issue Jan 31, 2016 · 3 comments

Comments

@newlandsvalley
Copy link

I'm still finding this a wonderful parser. However, I've managed to crash the elm runtime with the error - cannot read property 'ctor' of undefined. I'm simply trying to parse lists of characters between brackets where the brackets can be nested - for example (AB (C D) E F). See this gist - https://gist.github.com/newlandsvalley/96dabd17480609ab4000. If I remove from the grammar the possibility of brackets being nested, the problem goes away.

It's strange because there's no such problem with your Calc example.

I suspect this is an Elm problem rather than a Combine one, but I thought I'd better post it here first.

@Bogdanp
Copy link
Collaborator

Bogdanp commented Jan 31, 2016

Elm is eagerly evaluated so in your example slur and slurContent end up creating a circular dependency that gets evaluated as soon as the output JS does, which means one function ends up calling the constructor of the other before the other is defined :). You can get around this using the rec combinator. For example you can rewrite slurContent to

slurContent : Parser Music
slurContent = rec <| \() -> choice [note , slur, spacer]

which should fix your problem.

@newlandsvalley
Copy link
Author

Ah, of course - what wonderful support you give. Fixes the problem immediately.

@alech
Copy link

alech commented Jul 28, 2016

I had a very similar issue and the "rec <| () ->" trick solved it for me, too. I was wondering if this could be documented more clearly, for example in the documentation of "rec", since more people might stumble upon this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants