use of org.eclipse.xtext.UnorderedGroup in project xtext-eclipse by eclipse.
the class AbstractAntlrGrammarWithActionsGenerator method _compileInitUnorderedGroups.
protected CharSequence _compileInitUnorderedGroups(final ParserRule it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
{
boolean _definesUnorderedGroups = this._grammarAccessExtensions.definesUnorderedGroups(it, options);
if (_definesUnorderedGroups) {
_builder.newLineIfNotEmpty();
_builder.append("UnorderedGroupState myUnorderedGroupState = getUnorderedGroupHelper().snapShot(");
_builder.newLine();
{
Iterable<UnorderedGroup> _filter = Iterables.<UnorderedGroup>filter(EcoreUtil2.eAllContentsAsList(it), UnorderedGroup.class);
boolean _hasElements = false;
for (final UnorderedGroup group : _filter) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "");
}
_builder.append("grammarAccess.");
String _gaRuleElementAccessor = this._grammarAccess.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(group));
_builder.append(_gaRuleElementAccessor);
_builder.newLineIfNotEmpty();
}
}
_builder.append(");");
}
}
return _builder;
}
use of org.eclipse.xtext.UnorderedGroup in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileParserImports.
@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("import org.eclipse.xtext.*;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.*;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.impl.*;");
_builder.newLine();
_builder.append("import org.eclipse.emf.ecore.util.EcoreUtil;");
_builder.newLine();
_builder.append("import org.eclipse.emf.ecore.EObject;");
_builder.newLine();
{
boolean _isEmpty = GrammarUtil.allEnumRules(it).isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("import org.eclipse.emf.common.util.Enumerator;");
_builder.newLine();
}
}
_builder.append("import org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
_builder.newLine();
{
if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
return EcoreUtil2.eAllContentsAsList(it_1);
}))), UnorderedGroup.class))) && options.isBacktrack())) {
_builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
_builder.newLine();
}
}
_builder.append("import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;");
_builder.newLine();
_builder.append("import ");
String _gaFQName = this._grammarAccess.gaFQName(it);
_builder.append(_gaFQName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
return _builder.toString();
}
use of org.eclipse.xtext.UnorderedGroup in project xtext-eclipse by eclipse.
the class PsiAntlrGrammarGenerator method compileParserImports.
@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("import org.eclipse.xtext.idea.parser.AbstractPsiAntlrParser;");
_builder.newLine();
_builder.append("import ");
String _elementTypeProviderName = this._ideaPluginClassNames.getElementTypeProviderName(GrammarUtil.getGrammar(it));
_builder.append(_elementTypeProviderName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import org.eclipse.xtext.idea.parser.TokenTypeProvider;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
_builder.newLine();
{
if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
return EcoreUtil2.eAllContentsAsList(it_1);
}))), UnorderedGroup.class))) && options.isBacktrack())) {
_builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
_builder.newLine();
}
}
_builder.append("import ");
String _gaFQName = this._grammarAccess.gaFQName(it);
_builder.append(_gaFQName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.intellij.lang.PsiBuilder;");
_builder.newLine();
return _builder.toString();
}
use of org.eclipse.xtext.UnorderedGroup in project xtext-core by eclipse.
the class BaseContentAssistParser method getFollowElements.
public Collection<FE> getFollowElements(FE element) {
if (element.getLookAhead() <= 1)
throw new IllegalArgumentException("lookahead may not be less than or equal to 1");
Collection<FE> result = new ArrayList<FE>();
for (AbstractElement elementToParse : getElementsToParse(element)) {
elementToParse = unwrapSingleElementGroups(elementToParse);
String ruleName = getRuleName(elementToParse);
String[][] allRuleNames = getRequiredRuleNames(ruleName, element.getParamStack(), elementToParse);
for (String[] ruleNames : allRuleNames) {
for (int i = 0; i < ruleNames.length; i++) {
InternalParser parser = createParser();
parser.setUnorderedGroupHelper(createUnorderedGroupHelper());
parser.getUnorderedGroupHelper().initializeWith(parser);
ObservableXtextTokenStream tokens = setTokensFromFollowElement(parser, element);
tokens.setListener(parser);
parser.getGrammarElements().addAll(element.getTrace());
parser.getGrammarElements().add(elementToParse);
parser.getLocalTrace().addAll(element.getLocalTrace());
parser.getLocalTrace().add(elementToParse);
parser.getParamStack().addAll(element.getParamStack());
if (elementToParse instanceof UnorderedGroup && element.getGrammarElement() == elementToParse) {
UnorderedGroup group = (UnorderedGroup) elementToParse;
IUnorderedGroupHelper helper = getInitializedUnorderedGroupHelper(element, parser, group);
parser.setUnorderedGroupHelper(ignoreFirstEntrance(helper));
}
Collection<FE> elements = getFollowElements(parser, elementToParse, ruleNames, i);
result.addAll(elements);
}
}
}
return result;
}
use of org.eclipse.xtext.UnorderedGroup in project xtext-core by eclipse.
the class ConcreteSyntaxConstraintProvider method createElement.
protected ISyntaxConstraint createElement(EObject obj) {
if (!(obj instanceof AbstractElement))
return null;
AbstractElement ele = (AbstractElement) obj;
boolean multiple = false;
boolean optional = false;
EClass semanticType = null;
while (true) {
multiple = multiple || isMultipleCardinality(ele);
optional = optional || isOptionalCardinality(ele);
if (ele.eContainer() instanceof ParserRule && ((ParserRule) ele.eContainer()).getType().getClassifier() instanceof EClass)
semanticType = (EClass) ((ParserRule) ele.eContainer()).getType().getClassifier();
if (ele instanceof Assignment) {
return createElement(ConstraintType.ASSIGNMENT, ele, semanticType, multiple, optional);
} else if (ele instanceof Group || ele instanceof UnorderedGroup) {
CompoundElement comp = (CompoundElement) ele;
AbstractElement lastChild = null;
for (AbstractElement o : comp.getElements()) if (containsRelevantElement(o)) {
if (lastChild == null)
lastChild = o;
else {
List<AbstractElement> c = new ArrayList<AbstractElement>(comp.getElements());
List<ISyntaxConstraint> e = createSummarizedAssignments(comp, c, semanticType, optional);
if (e.size() == 1 && c.size() == 0)
return e.get(0);
return createElement(ConstraintType.GROUP, ele, c, e, semanticType, multiple, optional);
}
}
if (lastChild == null)
return null;
ele = lastChild;
continue;
} else if (ele instanceof Alternatives) {
int relevantChildren = 0;
AbstractElement lastChild = null;
for (AbstractElement o : ((CompoundElement) ele).getElements()) if (containsRelevantElement(o)) {
relevantChildren++;
lastChild = o;
}
if (relevantChildren < ((CompoundElement) ele).getElements().size())
optional = true;
if (relevantChildren > 1)
return createElement(ConstraintType.ALTERNATIVE, ele, semanticType, multiple, optional);
if (lastChild == null)
return null;
ele = lastChild;
continue;
} else if (ele instanceof Action) {
semanticType = (EClass) ((Action) ele).getType().getClassifier();
return createElement(ConstraintType.ACTION, ele, semanticType, multiple, optional);
} else if (ele instanceof RuleCall) {
AbstractRule rule = ((RuleCall) ele).getRule();
if (rule.getType().getClassifier() instanceof EClass) {
ele = rule.getAlternatives();
continue;
}
}
return null;
}
}
Aggregations