Java Code Examples for org.eclipse.xtext.GrammarUtil#isAssignedAction()

The following examples show how to use org.eclipse.xtext.GrammarUtil#isAssignedAction() . 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: Context2NameFunction.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public String getContextName(Grammar grammar, EObject ctx) {
	if (GrammarUtil.isEObjectRule(ctx))
		return getContextName(grammar, (ParserRule) ctx);
	if (GrammarUtil.isAssignedAction(ctx))
		return getContextName(grammar, (Action) ctx);
	throw new RuntimeException("Invalid Context: " + EmfFormatter.objPath(ctx));
}
 
Example 2
Source File: SyntacticSequencerPDAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isMandatoryAbsorber(AbstractElement ele) {
	if (ele == null)
		return true;
	if (GrammarUtil.isAssigned(ele))
		return true;
	if (GrammarUtil.isAssignedAction(ele))
		return true;
	//		if (GrammarUtil.isDatatypeRuleCall(ele))
	//			return true;
	return false;
}
 
Example 3
Source File: ContextPDAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EObject getContext(AbstractElement ele) {
	if (ele instanceof RuleCall) {
		if (GrammarUtil.isAssignedEObjectRuleCall(ele))
			return ((RuleCall) ele).getRule();
	} else if (GrammarUtil.isAssignedAction(ele))
		return ele;
	return null;
}
 
Example 4
Source File: AbstractCodeElementExtractor.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the assignment component with the given nazme in the given grammar component.
 *
 * @param grammarComponent the component to explore.
 * @param assignmentName the name of the assignment to search for.
 * @return the assignment component.
 */
protected static Action findAction(EObject grammarComponent, String assignmentName) {
	for (final Action action : GrammarUtil.containedActions(grammarComponent)) {
		if (GrammarUtil.isAssignedAction(action)) {
			if (Objects.equals(assignmentName, action.getFeature())) {
				return action;
			}
		}
	}
	return null;
}
 
Example 5
Source File: SerializerPDA.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean apply(ISerState input) {
	return input != null && GrammarUtil.isAssignedAction(input.getGrammarElement());
}
 
Example 6
Source File: ContextPDAProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void collectExtracted(ISerState orig, Collection<? extends ISerState> precedents, SerializerPDAState copy,
		Map<Pair<AbstractElement, SerStateType>, SerializerPDAState> oldToNew, final CallStack inTop,
		SerializerPDAState start) {
	for (ISerState pre : precedents) {
		CallStack top = inTop;
		AbstractElement element = pre.getGrammarElement();
		switch (pre.getType()) {
		case START:
			if (top.call == null)
				connect(start, copy);
			continue;
		case POP:
			top = new CallStack(top, (RuleCall) element);
			if (top.isLoop())
				continue;
			break;
		case PUSH:
			if (top.call == null) {
				connect(start, copy);
				continue;
			} else if (top.call == element) {
				top = top.parent;
			} else {
				continue;
			}
		default:
			break;
		}
		Pair<AbstractElement, SerStateType> key = Tuples.create(element, pre.getType());
		SerializerPDAState pre2 = oldToNew.get(key);
		if (pre2 == null) {
			pre2 = new SerializerPDAState(element, pre.getType());
			oldToNew.put(key, pre2);
		}
		if (GrammarUtil.isAssignedAction(
				pre.getGrammarElement()) /* && pre.getType() != STOP */) {
			Set<ISerState> entries = collectPushForAction(pre);
			collectExtracted(pre, entries, pre2, oldToNew, top, start);
		} else {
			if (top.visited.add(pre))
				collectExtracted(pre, pre.getPrecedents(), pre2, oldToNew, top, start);
		}
		connect(pre2, copy);
	}
}