-
Notifications
You must be signed in to change notification settings - Fork 204
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
Support for grammar macros #674
Comments
On MacrosMacros are very cool, Chevrotain's heart is actually based on implementing a minimal readonly However because we have fewer levels of abstractions here compared to a parser generator I would be wary of implementing Write macros as well as the existing system is already a little fragile
Do you really need Macros?Is your language partially white space sensitive? or fully white space sensitive?
Maybe the _SEP methods could be upgraded to support more complex separators If you still really want macros and the extra abstractions that enable those.You can build your own custom APIS for using the Chevrotain engine. Those could be generator or combinator styled APIs and because you will have an additional |
It's an indentation based language. Indents, Deindents, Newlines, and Tabs, are always semantic and not allowed just anywhere. It's also a language that parses css selectors, so spaces are semantic to represent nesting of elements vs compounding of elements ( I don't think I want to try using the custom apis system, since I'm building a parser with embedded actions, and I'll need to use parameterized rules. Honestly though, from where I'm standing it seems possible to use the existing I haven't looked through enough of the code to understand this all deeply though, and if what I'm talking about is impractical I completely understand. |
It certainly would be nice if the |
This complexity could indeed explain your use case for macros.
I think it is possible to get something working, I'm just not sure on the complexity of getting That is why I am not sure if I want to introduce this feature to Chevrotain at this time. Way Forward.Option1However, it may be simple to refactor the grammar analysis phase to be extensible so Option2Chevrotain Grammars are plain JavaScript, So why are we trying to solve text replacement macros and general code Some Options: I think the babel-plugin-macros is the better choice as we only need simple text replacements |
From the
MANY_SEP
andAT_LEAST_ONE_SEP
docs:It would be nice to have a generic grammar "macro" that takes more complex formations of rules and intersperses them with each other. Nearley has a concept like this.
A basic example of a time when this becomes very useful is separators that have to be more complex than a token. I'm building a grammar where whitespace can't simply be ignored (even spaces sometimes are mandatory and clarify different options), and it's causing a lot of redundancy and bloat.
This example doesn't show a very terrifying situation, but it shows that this functionality cleans things up.
A possible api:
MACRO
for definitionsMACRO_ARG
for using the parameters within the definitionSUBMACRO
for usesHere's what my above rule could look like:
A more verbose and abstract example:
The text was updated successfully, but these errors were encountered: