Closed kjosib closed 4 years ago
This concept is now supported on the miniparse
side with the void_symbols
parser attribute. While I see how to add it to the macroparse
side, it seems the best approach might be to reconsider the design of the macroparse
module in light of certain recent developments.
The "void token" idea does have an interaction with the macro system: if a macro's production rule fails to explicitly specify semantic capture positions, then textual substitution of different tokens could yield inconsistent behavior. The system ought to decide which positions in macro-rules to capture once only, rather than again for each instantiation of the macro. And indeed this is how it works.
Main Idea
In any given language, there are likely to be terminals which contribute only syntactic, not semantic information. Examples include most punctuation and reserved words. Let's call these "void terminals", because the type of their semantic content is -- well -- vacuous.
If we have a list of (or criterion for recognizing) void terminals, then there's no need to explicitly filter them out of the set of right-hand-side symbols relevant to a parse-action. This could result in cleaner-looking production rules.
For Example:
stmt -> IF .expr THEN .stmt ELSE .stmt :test
%void IF THEN ELSE
in a declarations block, and later
stmt -> IF expr THEN stmt ELSE stmt :test
Expanding on the Idea:
'['
or'=='
are generally void, but this may depend on the application. It may be worth allowing something like%void %quoted
as a declaration to indicate this.%token
could allow you to opt into strictness: if it appears, then every grammar symbol must either be declared somehow as a terminal or be a non-terminal with production rules reachable from the start symbol(s).Relatedly:
This suggests perhaps "Precedence" is the wrong name for its block. Perhaps it should be called "Declarations", of which precedence and associativity rules are just one kind.
Caveat: This is not, and cannot be, a perfect be-all, end-all solution. But it should make a big dent in the vast majority of