org.eclipse.xtext.UnorderedGroup Java Examples

The following examples show how to use org.eclipse.xtext.UnorderedGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseInternalContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void after(EObject grammarElement) {
	EObject foundGrammarElement = removeLast(grammarElements);
	if (grammarElement != foundGrammarElement)
		throw new IllegalStateException(
				"expected element: '" + grammarElement + "', but was: '" + foundGrammarElement + "'");
	if (grammarElement instanceof UnorderedGroup && indexToHandledElements != null) {
		indexToHandledElements.removeAll(grammarElements.size());
	} else if (!grammarElements.isEmpty()) {
		int index = grammarElements.size() - 1;
		if (grammarElements.get(index) instanceof UnorderedGroup) {
			if (indexToHandledElements == null) {
				indexToHandledElements = LinkedHashMultimap.create();
			}
			indexToHandledElements.put(index, (AbstractElement) grammarElement);
		}
	}
}
 
Example #2
Source File: EofListener.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void announceEof(int lookAhead) {
	if (!wasRecovering) {
		parser.announceEof(lookAhead);
		if (lookAhead > 1)
			announcedEofWithLA = true;
	}
	if (parser.isDFAPrediction()) {
		int lastGrammarElement = parser.getGrammarElements().size() - 1;
		if (elementToParse instanceof UnorderedGroup && parser.getGrammarElements().get(lastGrammarElement) == elementToParse) {
			IUnorderedGroupHelper helper = parser.getUnorderedGroupHelper();
			if (!helper.canLeave((UnorderedGroup) elementToParse)) {
				wasEof = true;		
			}
		}
	} else {
		wasEof = true;
	}
}
 
Example #3
Source File: PredicateUsesUnorderedGroupInspector.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void createErrorMessages(UnorderedGroup object) {
	acceptError(
			"Cannot use unordered groups in syntactic predicates.", 
			object, 
			null,
			ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
			null);
	for(AbstractElement element: elementStack) {
		acceptError(
				"A predicate may not use an unordered group.", 
				element, 
				XtextPackage.Literals.ABSTRACT_ELEMENT__PREDICATED,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				null);
	}
	for(RuleCall ruleCall: callHierarchy) {
		if (!ruleCall.isPredicated())
			acceptError(
					"The rule call is part of a call hierarchy that leads to a predicated unordered group.", 
					ruleCall, 
					XtextPackage.Literals.RULE_CALL__RULE,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
					null);
	}
}
 
Example #4
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_05() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
	typeRef.setClassifier(EcorePackage.Literals.EOBJECT);
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setType(typeRef);
	ruleCall.setRule(parserRule);
	Assignment assignment = XtextFactory.eINSTANCE.createAssignment();
	assignment.setTerminal(ruleCall);
	unorderedGroup.getElements().add(assignment);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #5
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
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 Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #6
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
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 Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #7
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String _ebnf2(final UnorderedGroup it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("(");
  {
    EList<AbstractElement> _elements = it.getElements();
    boolean _hasElements = false;
    for(final AbstractElement element : _elements) {
      if (!_hasElements) {
        _hasElements = true;
      } else {
        _builder.appendImmediate("\n    |", "");
      }
      String _ebnf = this.ebnf(element, options, supportActions);
      _builder.append(_ebnf);
    }
  }
  _builder.append(")*");
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #8
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) {
  if (it instanceof Alternatives) {
    return _compileRule((Alternatives)it, grammar, options);
  } else if (it instanceof Group) {
    return _compileRule((Group)it, grammar, options);
  } else if (it instanceof UnorderedGroup) {
    return _compileRule((UnorderedGroup)it, grammar, options);
  } else if (it instanceof Assignment) {
    return _compileRule((Assignment)it, grammar, options);
  } else if (it instanceof EnumRule) {
    return _compileRule((EnumRule)it, grammar, options);
  } else if (it instanceof ParserRule) {
    return _compileRule((ParserRule)it, grammar, options);
  } else if (it instanceof TerminalRule) {
    return _compileRule((TerminalRule)it, grammar, options);
  } else if (it instanceof String) {
    return _compileRule((String)it, grammar, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, grammar, options).toString());
  }
}
 
Example #9
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_03() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	EnumRule enumRule = XtextFactory.eINSTANCE.createEnumRule();
	ruleCall.setRule(enumRule);
	unorderedGroup.getElements().add(ruleCall);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #10
Source File: BaseContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.14
 */
protected IUnorderedGroupHelper getInitializedUnorderedGroupHelper(FE element, InternalParser parser,
		UnorderedGroup group) {
	final IUnorderedGroupHelper helper = parser.getUnorderedGroupHelper();
	helper.enter(group);
	for (AbstractElement consumed : element.getHandledUnorderedGroupElements()) {
		parser.before(consumed);
		helper.select(group, group.getElements().indexOf(consumed));
		helper.returnFromSelection(group);
		parser.after(consumed);
	}
	return helper;
}
 
Example #11
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String _ebnf2(final UnorderedGroup it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
  _builder.append(_contentAssistRuleName);
  _builder.append("__");
  String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
  _builder.append(_gaElementIdentifier);
  return _builder.toString();
}
 
Example #12
Source File: AbstractAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean containsUnorderedGroup(Grammar grammar) {
	for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
		if (Iterators.filter(rule.eAllContents(), UnorderedGroup.class).hasNext()) {
			return true;
		}
	}
	return false;
}
 
Example #13
Source File: ParserBasedContentAssistContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void doSwitch(UnorderedGroup group, List<AbstractElement> handledAlternatives) {
	this.group = group;
	this.handledAlternatives = handledAlternatives;
	try {
		doSwitch(group);
	} finally {
		this.handledAlternatives = null;
		this.group = null;
	}
}
 
Example #14
Source File: ParserBasedContentAssistContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseUnorderedGroup(UnorderedGroup object) {
	if (!checkFurther(object))
		return result;
	// elements may occur in any order - treat them as looped alternatives
	if (caseAlternatives(object.getElements()))
		return true;
	if (!checkFurther(object))
		return result;
	return caseAlternatives(object.getElements());
}
 
Example #15
Source File: NonTerminalConsumer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private int doConsumeUnorderedGroup(ElementConsumer<UnorderedGroup> groupConsumer, IElementConsumer[] groupElements, 
			IFurtherParsable.Source<UnorderedGroupToken> source, boolean optional) throws Exception {
		final UnorderedGroupResult result = createUnorderedGroupResult(groupConsumer, source, optional);
		result.reset();
		for(IElementConsumer consumer: groupElements) {
			if (result.didGroupFail(consumer.consume())) {
				if (result.result == ConsumeResult.EMPTY_MATCH) {
					result.error(groupConsumer.getErrorMessage());
					result.getResult();
					return getOffset();
				}
				return result.getResult();
			}
		}
		return result.getResult();
//		result.reset();
//		result.setAlternative(entry - 1);
//		for (int i = entry; i < alternativesElements.length; i++) {
//			result.nextAlternative();
//			if (result.isAlternativeDone(alternativesElements[i].consume()))
//				return result.getResult();
//		}
//		if (result.bestResult == ConsumeResult.EMPTY_MATCH) {
//			result.fakeNextAlternative();
//			result.error(alternativesConsumer.getErrorMessage());
//			result.isAlternativeDone(ConsumeResult.SUCCESS);
//			result.getResult();
//			return getOffset();
//		}
//		return result.getResult();
	}
 
Example #16
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkActionInUnorderedGroup(final Action action) {
	if (EcoreUtil2.getContainerOfType(action, UnorderedGroup.class) != null)
		addIssue("Actions may not be used in unordered groups.", 
				action, 
				null,
				INVALID_ACTION_USAGE);
}
 
Example #17
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_04() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	TerminalRule terminalRule = XtextFactory.eINSTANCE.createTerminalRule();
	ruleCall.setRule(terminalRule);
	unorderedGroup.getElements().add(ruleCall);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #18
Source File: FirstSetComputer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseUnorderedGroup(UnorderedGroup object) {
	boolean result = true;
	for(AbstractElement element: object.getElements()) {
		if (!doSwitch(element)) {
			result = false;
		}
	}
	return result || GrammarUtil.isOptionalCardinality(object);
}
 
Example #19
Source File: FollowElementCalculator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void doSwitch(UnorderedGroup group, List<AbstractElement> handledAlternatives) {
	this.group = group;
	this.handledAlternatives = handledAlternatives;
	try {
		doSwitch(group);
	} finally {
		this.handledAlternatives = null;
		this.group = null;
	}
}
 
Example #20
Source File: GrammarElementTitleSwitch.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String toString() {
	if (text != null)
		return text;
	if (children.size() == 1)
		return children.get(0).toString();
	if (compound instanceof Group)
		return "(" + Joiner.on(" ").join(children) + ")";
	if (compound instanceof UnorderedGroup)
		return "(" + Joiner.on("&").join(children) + ")";
	if (compound instanceof Alternatives)
		return "(" + Joiner.on("|").join(children) + ")";
	return "";
}
 
Example #21
Source File: UnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public State(UnorderedGroup group) {
	frames = new Stack<Frame>();
	EList<AbstractElement> elements = group.getElements();
	alternatives = elements.size();
	mandatoryAlternatives = new boolean[alternatives];
	mandatoryAlternativeCount = 0;
	for(int i = 0; i < alternatives; i++) {
		boolean isMandatory = !GrammarUtil.isOptionalCardinality(elements.get(i));
		if (isMandatory) {
			mandatoryAlternatives[i] = true;
			mandatoryAlternativeCount++;
		}
	}
}
 
Example #22
Source File: CallHierarchyHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseUnorderedGroup(UnorderedGroup object) {
	if (!checkFurther(object))
		return result;
	// elements may occur in any order - treat them as looped alternatives
	if (caseAlternatives(object.getElements()))
		return true;
	if (!checkFurther(object))
		return result;
	return caseAlternatives(object.getElements());
}
 
Example #23
Source File: UnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Inject
public UnorderedGroupHelper(Collector collector) {
	groupToState = Maps.newHashMap();
	backtrackingSnapShot = Maps.newTreeMap();
	for(UnorderedGroup group: collector.getGroups())
		configure(group);
	allGroups = collector.getGroups().toArray(new UnorderedGroup[collector.getGroups().size()]);
}
 
Example #24
Source File: UnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected State get(UnorderedGroup group) {
	snapShotForBacktracking();
	State result = groupToState.get(group);
	if (result == null)
		throw new IllegalArgumentException("Unexpected group: " + group);
	return result;
}
 
Example #25
Source File: IUnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean canLeave(UnorderedGroup group) {
	throw new UnsupportedOperationException();
}
 
Example #26
Source File: NonTerminalConsumer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private UnorderedGroupResult createUnorderedGroupResult(ElementConsumer<UnorderedGroup> groupConsumer, 
		IFurtherParsable.Source<UnorderedGroupToken> source, boolean optional) {
	final UnorderedGroupToken begin = new UnorderedGroupToken(getOffset(), groupConsumer.getElement(), source, optional);
	getTokenAcceptor().accept(begin);
	return new UnorderedGroupResult(groupConsumer, begin);
}
 
Example #27
Source File: UnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ImmutableList<UnorderedGroup> getGroups() {
	return groups;
}
 
Example #28
Source File: IgnoreFirstEntranceUnorderedGroupHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void leave(UnorderedGroup group) {
	helper.leave(group);
}
 
Example #29
Source File: UnorderedGroupToken.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public UnorderedGroupToken(int offset, UnorderedGroup group, IFurtherParsable.Source<UnorderedGroupToken> origin, boolean optional) {
			//, int totalAlternatives) {
		super(offset, group, origin, optional);
//		this.totalAlternatives = totalAlternatives;
	}
 
Example #30
Source File: NonTerminalConsumer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public MandatoryLoopUnorderedGroupConsumer(UnorderedGroup element) {
	super(element);
}