render predicates for non-trivial-cardinalities

This commit is contained in:
overflowerror 2021-12-04 18:03:41 +01:00
parent 1058d2bf3c
commit 0ad55d42cc
3 changed files with 34 additions and 0 deletions

View file

@ -315,6 +315,7 @@ abstract class AbstractAntlrGrammarGenerator {
protected def String ebnf(AbstractElement it, AntlrOptions options, boolean supportActions) '''
«IF mustBeParenthesized»(
«IF !isTrivialCardinality»«findHoistingGuardIgnoreCardinality.renderPredicate»«ENDIF»
«ebnfPredicate(options)»«ebnf2(options, supportActions)»
)«ELSE»«ebnf2(options, supportActions)»«ENDIF»«cardinality»
'''
@ -325,6 +326,7 @@ abstract class AbstractAntlrGrammarGenerator {
protected def String dataTypeEbnf(AbstractElement it, boolean supportActions) '''
«IF mustBeParenthesized»(
«IF !isTrivialCardinality»«findHoistingGuardIgnoreCardinality.renderPredicate»«ENDIF»
«dataTypeEbnfPredicate»«dataTypeEbnf2(supportActions)»
)«ELSE»«dataTypeEbnf2(supportActions)»«ENDIF»«cardinality»
'''

View file

@ -310,6 +310,18 @@ public class HoistingProcessor {
}
}
public HoistingGuard findHoistingGuardIgnoreCardinality(AbstractElement element) {
log.info("hoisting (trivial) guard of: \n" + abstractElementToString(element));
// should only be called for valid AST elements, so element can never be floating
AbstractRule rule = containingParserRule(element);
if (element instanceof UnorderedGroup) {
return findGuardForAlternatives(((CompoundElement) element), rule);
} else {
return findGuardForElementWithTrivialCardinality(element, rule);
}
}
public HoistingGuard findHoistingGuard(AbstractElement element) {
log.info("hoisting guard of: \n" + abstractElementToString(element));
// should only be called for valid AST elements, so element can never be floating

View file

@ -690,6 +690,16 @@ public abstract class AbstractAntlrGrammarGenerator {
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t");
{
boolean _isTrivialCardinality = GrammarUtil.isTrivialCardinality(it);
boolean _not = (!_isTrivialCardinality);
if (_not) {
String _renderPredicate = this._hoistingProcessor.findHoistingGuardIgnoreCardinality(it).renderPredicate();
_builder.append(_renderPredicate, "\t");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t");
String _ebnfPredicate = this.ebnfPredicate(it, options);
_builder.append(_ebnfPredicate, "\t");
String _ebnf2 = this.ebnf2(it, options, supportActions);
@ -748,6 +758,16 @@ public abstract class AbstractAntlrGrammarGenerator {
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t");
{
boolean _isTrivialCardinality = GrammarUtil.isTrivialCardinality(it);
boolean _not = (!_isTrivialCardinality);
if (_not) {
String _renderPredicate = this._hoistingProcessor.findHoistingGuardIgnoreCardinality(it).renderPredicate();
_builder.append(_renderPredicate, "\t");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t");
String _dataTypeEbnfPredicate = this.dataTypeEbnfPredicate(it);
_builder.append(_dataTypeEbnfPredicate, "\t");
String _dataTypeEbnf2 = this.dataTypeEbnf2(it, supportActions);