Search in sources :

Example 11 with ISynAbsorberState

use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.

the class SemanticSequencerNfaProvider method createNfa.

protected SemNfa createNfa(Grammar grammar, ISynAbsorberState synState, EClass type) {
    SynAbsorberNfaAdapter synNfa = new SynAbsorberNfaAdapter(synState);
    // System.out.println(new NfaFormatter().format(synNfa));
    Map<ISynAbsorberState, Integer> distanceMap = util.distanceToFinalStateMap(synNfa);
    SemNfa nfa = util.create(util.sort(synNfa, distanceMap), new SemStateFactory());
    // util.sortInplace(nfa, distanceMap);
    if (type != null)
        initContentValidationNeeded(type, nfa);
    initRemainingFeatures(nfa.getStop(), util.inverse(nfa), Sets.<ISemState>newHashSet());
    initOrderIDs(grammar, nfa);
    // System.out.println(new NfaFormatter().format(nfa));
    return nfa;
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) SynAbsorberNfaAdapter(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.SynAbsorberNfaAdapter)

Example 12 with ISynAbsorberState

use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.

the class AbstractSyntacticSequencer method enterAssignedAction.

@Override
public boolean enterAssignedAction(Action action, EObject semanticChild, ICompositeNode node) {
    navigateToAbsorber(action, node);
    boolean shouldEnter = delegate.enterAssignedAction(action, semanticChild, node);
    if (shouldEnter) {
        ISerializationContext child = SerializationContext.forChild(contexts.peek().context, action, semanticChild);
        ISynAbsorberState pda = syntacticSequencerPDAs.get(child);
        if (pda == null)
            throw new IllegalStateException();
        SyntacticalContext j = new SyntacticalContext(child, semanticChild, pda, node);
        contexts.push(j);
    }
    return shouldEnter;
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext)

Example 13 with ISynAbsorberState

use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.

the class AbstractSyntacticSequencer method navigateToEmitter.

protected ISynFollowerOwner navigateToEmitter(ISynFollowerOwner fromState, INode fromNode, AbstractElement toEle, INode toNode, RuleCallStack stack) {
    if (fromState instanceof ISynAbsorberState)
        return fromState;
    if (fromState instanceof ISynNavigable) {
        ISynNavigable fromEmitter = (ISynNavigable) fromState;
        if (!fromEmitter.hasEmitters())
            return fromEmitter.getTarget();
        List<ISynState> pathAndElement = fromEmitter.getShortestPathTo(toEle, stack);
        if (pathAndElement == null) {
            if (errorAcceptor != null)
                errorAcceptor.accept(diagnosticProvider.createUnexpectedEmitterDiagnostic(fromEmitter, toEle, stack));
            return null;
        }
        List<ISynState> path = pathAndElement.subList(0, pathAndElement.size() - 1);
        accept(fromNode, path, stack);
        return pathAndElement.get(pathAndElement.size() - 1);
    }
    throw new IllegalStateException();
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ISynNavigable(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynNavigable) ISynState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynState)

Example 14 with ISynAbsorberState

use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.

the class AbstractSyntacticSequencer method init.

@Override
public void init(ISerializationContext context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
    INode node = NodeModelUtils.findActualNodeFor(semanticObject);
    syntacticSequencerPDAs = pdaProvider.getSyntacticSequencerPDAs(grammar.getGrammar());
    ISynAbsorberState state = syntacticSequencerPDAs.get(context);
    Preconditions.checkNotNull(state, "Invalid context: " + context);
    SyntacticalContext acceptor = new SyntacticalContext(context, semanticObject, state, node);
    contexts.push(acceptor);
    delegate = sequenceAcceptor;
    this.errorAcceptor = errorAcceptor;
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) INode(org.eclipse.xtext.nodemodel.INode)

Example 15 with ISynAbsorberState

use of org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState in project xtext-core by eclipse.

the class AbstractSyntacticSequencer method enterAssignedParserRuleCall.

@Override
public boolean enterAssignedParserRuleCall(RuleCall rc, EObject semanticChild, ICompositeNode node) {
    navigateToAbsorber(rc, node);
    boolean shouldEnter = delegate.enterAssignedParserRuleCall(rc, semanticChild, node);
    if (shouldEnter) {
        ISerializationContext child = SerializationContext.forChild(contexts.peek().context, rc, semanticChild);
        ISynAbsorberState pda = syntacticSequencerPDAs.get(child);
        if (pda == null)
            throw new IllegalStateException();
        SyntacticalContext j = new SyntacticalContext(child, semanticChild, pda, node);
        contexts.push(j);
    }
    return shouldEnter;
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext)

Aggregations

ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)19 ISynTransition (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition)10 Test (org.junit.Test)8 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)3 EClass (org.eclipse.emf.ecore.EClass)2 Grammar (org.eclipse.xtext.Grammar)2 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)2 ISynNavigable (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynNavigable)2 ISynState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynState)2 ParserRule (org.eclipse.xtext.ParserRule)1 INode (org.eclipse.xtext.nodemodel.INode)1 SynAbsorberNfaAdapter (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.SynAbsorberNfaAdapter)1 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)1 RuleCallStack (org.eclipse.xtext.serializer.sequencer.RuleCallStack)1 Nfa (org.eclipse.xtext.util.formallang.Nfa)1