Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix commitment issue with "union nonterminals" #62

Open
quasarbright opened this issue Nov 27, 2024 · 1 comment
Open

fix commitment issue with "union nonterminals" #62

quasarbright opened this issue Nov 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@quasarbright
Copy link
Collaborator

example:

#lang racket

(require syntax-spec)

(syntax-spec
 (nonterminal a-expr
   (a))
 (nonterminal b-expr
   (b))
 (nonterminal a-or-b-expr
   a:a-expr
   b:b-expr)
 (host-interface/expression
   (dsl e:a-or-b-expr)
   #''good))

(dsl (b))

the parsing of a-or-b-expr seems to commit to the a-expr and not backtrack and try b-expr once a-expr fails. this naturally comes up when you want to do something like defn-or-expr in a block dsl. for the stlc dsl, I had to inline defns into defn-or-expr to get around this

@quasarbright quasarbright added the bug Something isn't working label Nov 27, 2024
@quasarbright
Copy link
Collaborator Author

from michael:

Yeah this is maybe more of a misfeature than a bug. It’s the result of straightforwardly compiling nonterminals to syntax-parse. Getting the behavior you want would require backtracking across nonterminals, which would bring up issues of backtracking through macro expansions when the nonterminals allow extension. And also possibly backtracking across binding, if an unbound reference could trigger backtracking. There’s probably a safe subset but we’d need to think hard and maybe implement a static check to recognize it. Would definitely be nice to do eventually, but for now understand matching a production as committed choice before examining subexpressions or checking references are well bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant