use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method testAmbiguousRecursion.
@Test
public void testAmbiguousRecursion() throws Exception {
StringBuilder grammar = new StringBuilder();
grammar.append("Addition returns Expr: Prim ({Add.left=current} '+' right=Prim)*;\n");
grammar.append("Prim returns Expr: {Val} name=ID | '(' Addition ')';\n");
ISynAbsorberState start = getParserRule(grammar.toString(), "Prim", "Val");
ISynTransition trans1 = findTransition(start, "start", "name=ID");
assertFalse(trans1.involvesUnassignedTokenRuleCalls());
assertTrue(trans1.isSyntacticallyAmbiguous());
// assertEquals(1, trans1.getDistanceWithStackToAbsorber(newStack()));
assertEquals("[{Val}]", trans1.getShortestPathToAbsorber(newStack()).toString());
RuleCallStack stack2 = newStack();
ISynTransition trans2 = findTransition(start, "name=ID", "stop");
assertFalse(trans2.involvesUnassignedTokenRuleCalls());
assertFalse(trans2.isSyntacticallyAmbiguous());
// assertEquals(0, trans2.getDistanceWithStackToAbsorber(stack2));
assertEquals("[]", trans2.getShortestPathToAbsorber(stack2).toString());
// RuleCallStack stack3 = newStack(trans1, ">>Addition", ">>Prim");
// ISynTransition trans3 = findTransition(start, "name=ID", "stop");
// assertFalse(trans3.involvesUnassignedTokenRuleCalls());
// assertFalse(trans3.isSyntacticallyAmbiguous());
// // assertEquals(3, trans3.getDistanceWithStackToAbsorber(stack3));
// assertEquals("[<<Prim, <<Addition, ')']", trans3.getShortestStackpruningPathToAbsorber(stack3).toString());
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method getParserRule.
protected ISynAbsorberState getParserRule(String body, String name, String typeName) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
// SyntacticSequencerPDA2SimpleDot.drawGrammar("pdf/" + getName(),
// grammar);
// SyntacticSequencerPDA2ExtendedDot.drawGrammar(createSequenceParserPDAProvider(),
// "pdf/" + getName(), grammar);
ISyntacticSequencerPDAProvider pdaProvider = get(ISyntacticSequencerPDAProvider.class);
SerializationContextMap<ISynAbsorberState> pdas = pdaProvider.getSyntacticSequencerPDAs(grammar);
for (SerializationContextMap.Entry<ISynAbsorberState> e : pdas.sortedCopy().values()) {
for (ISerializationContext context : e.getContexts()) {
if (context.getAssignedAction() != null)
continue;
ISynAbsorberState pda = e.getValue();
ParserRule rule = context.getParserRule();
EClass type = context.getType();
boolean nameMatches = rule == null || name == null || rule.getName().equals(name);
boolean typeMatches = type == null || typeName == null || typeName.equals(type.getName());
if (nameMatches && typeMatches)
return pda;
}
}
throw new IllegalStateException();
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderTest method pda2lines2.
private List<String> pda2lines2(ISynAbsorberState start) {
Set<ISynAbsorberState> states = Sets.newHashSet(start);
collectAbsorberStates(start, Sets.<ISynState>newHashSet(), states);
List<String> pdalines = Lists.newArrayList();
for (ISynAbsorberState state : states) for (ISynTransition child : state.getOutTransitions()) pdalines.add(" " + pathToStr2(child));
Collections.sort(pdalines);
return pdalines;
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class SemanticSequencerNfaProvider method getSemanticSequencerNFAs.
@Override
public SerializationContextMap<Nfa<ISemState>> getSemanticSequencerNFAs(Grammar grammar) {
SerializationContextMap<Nfa<ISemState>> cached = cache.get(grammar);
if (cached != null)
return cached;
SerializationContextMap.Builder<Nfa<ISemState>> builder = SerializationContextMap.builder();
SerializationContextMap<ISynAbsorberState> PDAs = pdaProvider.getSyntacticSequencerPDAs(grammar);
for (SerializationContextMap.Entry<ISynAbsorberState> e : PDAs.values()) {
ISynAbsorberState synState = e.getValue();
for (EClass type : e.getTypes()) {
List<ISerializationContext> contexts = e.getContexts(type);
try {
SemNfa nfa = createNfa(grammar, synState, type);
builder.put(contexts, nfa);
} catch (Exception x) {
LOG.error("Error during static analysis of context '" + contexts + "': " + x.getMessage(), x);
}
}
}
SerializationContextMap<Nfa<ISemState>> result = builder.create();
cache.put(grammar, result);
return result;
}
use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method findTransition.
protected ISynTransition findTransition(ISerializationContext context, EObject semanticObject, ISynFollowerOwner fromState, INode fromNode, AbstractElement toEle, INode toNode, RuleCallStack stack) {
if (fromState == null)
return null;
if (fromState instanceof ISynAbsorberState) {
ISynAbsorberState fromAbsorber = (ISynAbsorberState) fromState;
ISynTransition transition = fromAbsorber.getOutTransitionsByElement().get(toEle);
if (transition == null) {
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidFollowingAbsorberDiagnostic(context, semanticObject, fromAbsorber, toEle));
return null;
}
return transition;
}
throw new IllegalStateException();
}
Aggregations