From cc8eb0a7da2cbb08029d64e59c5650b428cc420c Mon Sep 17 00:00:00 2001 From: overflowerror Date: Thu, 20 Jan 2022 18:18:32 +0100 Subject: [PATCH] fixed problem with antlr content assist grammar generator predicates in non-trivial cardinalities are not hoisted fix: render hoisting guard in content assist grammar generator. --- .../AntlrContentAssistGrammarGenerator.xtend | 14 ++++++- .../AntlrContentAssistGrammarGenerator.java | 38 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.xtend b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.xtend index 6dc5094f1..871b7669c 100644 --- a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.xtend +++ b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.xtend @@ -328,14 +328,24 @@ class AntlrContentAssistGrammarGenerator extends AbstractAntlrGrammarWithActions ) ( { before(grammarAccess.«originalElement.grammarElementAccess»«paramConfig»); } - («ebnf2(options, supportsActions)»)* + ( + «findHoistingGuardIgnoreCardinality.renderPredicate» + «ebnf2(options, supportsActions)» + )* { after(grammarAccess.«originalElement.grammarElementAccess»«paramConfig»); } ) ) «ELSE» ( { before(grammarAccess.«originalElement.grammarElementAccess»«paramConfig»); } - «IF mustBeParenthesized()»(«ebnf2(options, supportsActions)»)«ELSE»«ebnf2(options, supportsActions)»«ENDIF»«cardinality» + «IF mustBeParenthesized()» + ( + «IF !isTrivialCardinality»«findHoistingGuardIgnoreCardinality.renderPredicate»«ENDIF» + «ebnf2(options, supportsActions)» + ) + «ELSE» + «ebnf2(options, supportsActions)» + «ENDIF»«cardinality» { after(grammarAccess.«originalElement.grammarElementAccess»«paramConfig»); } ) «ENDIF» diff --git a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.java b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.java index 5f835ccda..d7c74b2b5 100644 --- a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.java +++ b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/AntlrContentAssistGrammarGenerator.java @@ -1026,10 +1026,18 @@ public class AntlrContentAssistGrammarGenerator extends AbstractAntlrGrammarWith _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("("); - String _ebnf2_1 = this.ebnf2(it, options, supportsActions); - _builder.append(_ebnf2_1, "\t\t"); - _builder.append(")*"); + _builder.newLine(); + _builder.append("\t\t\t"); + String _renderPredicate = this._hoistingProcessor.findHoistingGuardIgnoreCardinality(it).renderPredicate(); + _builder.append(_renderPredicate, "\t\t\t"); _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + String _ebnf2_1 = this.ebnf2(it, options, supportsActions); + _builder.append(_ebnf2_1, "\t\t\t"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append(")*"); + _builder.newLine(); _builder.append("\t\t"); _builder.append("{ after(grammarAccess."); String _grammarElementAccess_3 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.getOriginalElement(it)); @@ -1054,17 +1062,37 @@ public class AntlrContentAssistGrammarGenerator extends AbstractAntlrGrammarWith _builder.append(_paramConfig_4, "\t"); _builder.append("); }"); _builder.newLineIfNotEmpty(); - _builder.append("\t"); { boolean _mustBeParenthesized = this.mustBeParenthesized(it); if (_mustBeParenthesized) { + _builder.append("\t"); _builder.append("("); + _builder.newLine(); + _builder.append("\t"); + _builder.append("\t"); + { + boolean _isTrivialCardinality = GrammarUtil.isTrivialCardinality(it); + boolean _not = (!_isTrivialCardinality); + if (_not) { + String _renderPredicate_1 = this._hoistingProcessor.findHoistingGuardIgnoreCardinality(it).renderPredicate(); + _builder.append(_renderPredicate_1, "\t\t"); + } + } + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("\t"); String _ebnf2_2 = this.ebnf2(it, options, supportsActions); - _builder.append(_ebnf2_2, "\t"); + _builder.append(_ebnf2_2, "\t\t"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); _builder.append(")"); + _builder.newLine(); } else { + _builder.append("\t"); String _ebnf2_3 = this.ebnf2(it, options, supportsActions); _builder.append(_ebnf2_3, "\t"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t"); } } String _cardinality = it.getCardinality();