-
Notifications
You must be signed in to change notification settings - Fork 149
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
Ordered choice operator, grammar fragments and namespacing #139
Comments
If a grammar is broken up into multiple files, one strategy would be to process each file with combinators/ebnf, which will build a "grammar map" from each file. These maps can then be merged, and then you can build a parser with core/parser from the grammar map (use I've never thought about namespacing the grammar rule names before, and as you point out, that might be difficult to do while remaining backwards compatible with the current use of One possibility would be to make this an enhancement of the That would prevent collisions, but it wouldn't allow you to easily reference a rule from one file from a rule in another file, though. |
Re: ordered choice, would it be possible to parameterize the bnf parser on the ordered choice (or other) operators? I'm thinking something like Re: files, Okay cool. it shouldn't be too hard to put a wrapper together around these supporting loading several files together so long as when the last file is processed all nonterminals resolve. Doesn't matter for my use case since this was some throwaway code, but could be nice for someone else in the future. |
It's possible to parameterize the ordered choice symbol, but also a little risky, in the sense that the existing grammar for instaparse grammars is well-tested, and if someone inadvertently replaces the ordered choice symbol with something that interacts oddly with the other regular expressions that define the various tokens, weird behavior could result that might be hard to pinpoint. One possibility to support namespaced rule names would be to special-case things of the form I agree that tying the existing behavior into something that just loads multiple files is not a hard problem. Only non-trivial part would be giving meaningful error messages that pinpoint the correct file in the event that a nonterminal doesn't resolve once things are merged together. |
One idea: in EBNF syntax, allow rules to be namespaced with a dot separator, which get converted to namespaced keywords for hiccup.
Parse tree:
And potentially allow |
I agree that making Honestly rather than trying to do something weird with symbol parsing I think it'd make more sense to just give an optional namespace parameter when loading a resource. Keywords from that resource get namespaced, and it defaults to |
Hey,
I don't have a solution to propose, I just thought I'd mention a point of friction I came across recently in using instaparse to manipulate some internal DSLs.
/
, it isn't possible to take advantage of keyword namespacing when naming grammar terms.:auto-whitespace
directive, there doesn't seem to be a good way to break up grammars between several files.My specific use case was that I had a configuration DSL containing expressions written in two other languages. It would have been awesome if there had been a clear way for me to break the other languages out into their own grammars and use keyword namespacing to make sure that there weren't name collisions. With the advent of
clojure.spec
this is I suggest likely to be a trend in data design.Cheers!
The text was updated successfully, but these errors were encountered: