-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Grammar syntax for imports/includes #286
Comments
Hi @Schahen, are you referring to something like an E.g.,
If so, then you are correct — it's not something we support today. But I'm definitely open to it if you have a proposal! |
@pdubroy Following up on this, I think this would be a really useful feature but I feel it could be done in the
With the above in mind, is I'd be keen to potentially look at getting this working as it's exactly what I need. |
As mentioned in #457, I think a complete implementation of this feature needs to address a few things.
Regarding (2), a simple approach might be something like the following: ohm.grammar(`
include './foo.ohm'
G {
...
}
`, {
fetchGrammar(relativeUrl) {
return fs.readFileSync(relativeUrl, import.meta.url, 'utf-8');
}
}) The idea would be that when you call Alternatively, we could include default implementations, but that would be a bit more complicated with regards to bundling, etc. |
Implemented the above, awaiting review on the linked #457 |
Any progress on this front? No way to generateBundles of a grammar that extends another. Or is there? |
@marco3479 You can extend grammars but they have to be defined in the same file. For me, this was too restrictive. I have since put together a proposal PR but it was awaiting review for a while and I've had to close it due to lack of time on my end. Hopefully it can be picked up again later. What you can do is write your own pre-processing to automatically search and replace includes... I've seen others using tools for this. Otherwise, you can use my fork which is currently used by my project Solve. |
Noted. Thanks @LiamRiddell. |
@marco3479 Can you share some details about your use case? @LiamRiddell, I appreciate you submitting the PR and I apologize for letting it drop. I'd also like to hear a bit more about the specifics of your use case. I would like to figure out how to best support this, but I had second thoughts about the solution I proposed. It complicates the API and language more than I'd like. |
@pdubroy, I have a two grammars; B extends A. I was trying to keep the grammar definitions in their own |
Correct me if I'm wrong, but from what I see there's no way to include grammar definitions from one file into another one.
My questions are following:
The text was updated successfully, but these errors were encountered: