added disambiguating predicates to code generation and hoisting

at the moment they are treated like gated semantic predicates
This commit is contained in:
overflowerror 2021-11-23 18:24:13 +01:00
parent 6378a70180
commit b442f27a0f
5 changed files with 37 additions and 4 deletions

View file

@ -40,6 +40,7 @@ import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.HoistingProcessor
import java.lang.reflect.Parameter
import org.eclipse.xtext.AbstractSemanticPredicate
import org.eclipse.xtext.JavaAction
import org.eclipse.xtext.GatedSemanticPredicate
abstract class AbstractAntlrGrammarGenerator {
@ -377,10 +378,14 @@ abstract class AbstractAntlrGrammarGenerator {
''
}
protected dispatch def String ebnf2(AbstractSemanticPredicate it, AntlrOptions options, boolean supportActions) '''
protected dispatch def String ebnf2(GatedSemanticPredicate it, AntlrOptions options, boolean supportActions) '''
{«JavaCodeUtils.getSource(code)»}?=>
'''
protected dispatch def String ebnf2(AbstractSemanticPredicate it, AntlrOptions options, boolean supportActions) '''
{«JavaCodeUtils.getSource(code)»}?
'''
protected dispatch def String ebnf2(JavaAction it, AntlrOptions options, boolean supportActions) '''
{«JavaCodeUtils.getSource(code)»}
'''

View file

@ -30,8 +30,11 @@ import org.eclipse.xtext.AbstractSemanticPredicate;
import org.eclipse.xtext.Action;
import org.eclipse.xtext.Alternatives;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.DisambiguatingSemanticPredicate;
import org.eclipse.xtext.GatedSemanticPredicate;
import org.eclipse.xtext.Group;
import org.eclipse.xtext.JavaAction;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.UnorderedGroup;
@ -334,7 +337,7 @@ public class HoistingProcessor {
new XtextSwitch<Boolean>(){
@Override
public Boolean caseKeyword(org.eclipse.xtext.Keyword object) {
public Boolean caseKeyword(Keyword object) {
builder.append(indentationString);
builder.append("Keyword (").append(object.getValue()).append(")");
return true;
@ -383,12 +386,18 @@ public class HoistingProcessor {
return true;
};
@Override
public Boolean caseGatedSemanticPredicate(org.eclipse.xtext.GatedSemanticPredicate object) {
public Boolean caseGatedSemanticPredicate(GatedSemanticPredicate object) {
builder.append(indentationString);
builder.append("GatedSemanticPredicate (").append(object.getCode().getSource()).append(")");
return true;
};
@Override
public Boolean caseDisambiguatingSemanticPredicate(DisambiguatingSemanticPredicate object) {
builder.append(indentationString);
builder.append("DisambiguatingSemanticPredicate (").append(object.getCode().getSource()).append(")");
return true;
};
@Override
public Boolean caseAssignment(Assignment object) {
builder.append(indentationString);
builder.append("Assignment (\n");

View file

@ -25,6 +25,7 @@ import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.EnumLiteralDeclaration;
import org.eclipse.xtext.EnumRule;
import org.eclipse.xtext.GatedSemanticPredicate;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.Group;
@ -945,7 +946,7 @@ public abstract class AbstractAntlrGrammarGenerator {
return "";
}
protected String _ebnf2(final AbstractSemanticPredicate it, final AntlrOptions options, final boolean supportActions) {
protected String _ebnf2(final GatedSemanticPredicate it, final AntlrOptions options, final boolean supportActions) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
String _source = JavaCodeUtils.getSource(it.getCode());
@ -955,6 +956,16 @@ public abstract class AbstractAntlrGrammarGenerator {
return _builder.toString();
}
protected String _ebnf2(final AbstractSemanticPredicate it, final AntlrOptions options, final boolean supportActions) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
String _source = JavaCodeUtils.getSource(it.getCode());
_builder.append(_source);
_builder.append("}?");
_builder.newLineIfNotEmpty();
return _builder.toString();
}
protected String _ebnf2(final JavaAction it, final AntlrOptions options, final boolean supportActions) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
@ -1187,6 +1198,8 @@ public abstract class AbstractAntlrGrammarGenerator {
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
if (it instanceof Alternatives) {
return _ebnf2((Alternatives)it, options, supportActions);
} else if (it instanceof GatedSemanticPredicate) {
return _ebnf2((GatedSemanticPredicate)it, options, supportActions);
} else if (it instanceof Group) {
return _ebnf2((Group)it, options, supportActions);
} else if (it instanceof UnorderedGroup) {

View file

@ -22,6 +22,7 @@ import org.eclipse.xtext.Condition;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.EnumLiteralDeclaration;
import org.eclipse.xtext.GatedSemanticPredicate;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.Group;
import org.eclipse.xtext.JavaAction;
@ -667,6 +668,8 @@ public abstract class AbstractAntlrGrammarWithActionsGenerator extends AbstractA
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
if (it instanceof Alternatives) {
return _ebnf2((Alternatives)it, options, supportActions);
} else if (it instanceof GatedSemanticPredicate) {
return _ebnf2((GatedSemanticPredicate)it, options, supportActions);
} else if (it instanceof Group) {
return _ebnf2((Group)it, options, supportActions);
} else if (it instanceof UnorderedGroup) {

View file

@ -25,6 +25,7 @@ import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.EnumLiteralDeclaration;
import org.eclipse.xtext.EnumRule;
import org.eclipse.xtext.GatedSemanticPredicate;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.Group;
@ -1388,6 +1389,8 @@ public class AntlrContentAssistGrammarGenerator extends AbstractAntlrGrammarWith
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
if (it instanceof Alternatives) {
return _ebnf2((Alternatives)it, options, supportActions);
} else if (it instanceof GatedSemanticPredicate) {
return _ebnf2((GatedSemanticPredicate)it, options, supportActions);
} else if (it instanceof Group) {
return _ebnf2((Group)it, options, supportActions);
} else if (it instanceof UnorderedGroup) {