Search in sources :

Example 86 with ParserRule

use of org.eclipse.xtext.ParserRule 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();
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) Grammar(org.eclipse.xtext.Grammar)

Example 87 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_11.

@Test
public void testFindActualSemanticObjectFor_11() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model<Param>:name=ID;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode lessThan = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf("<"));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(lessThan);
    assertTrue(object instanceof ParserRule);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 88 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindActualNode_02.

@Test
public void testFindActualNode_02() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model<Param>:name=ID;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ParserRule rule = (ParserRule) grammar.getRules().get(0);
    ICompositeNode node = NodeModelUtils.findActualNodeFor(rule);
    assertEquals(" Model<Param>:name=ID;", node.getText());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 89 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class PartialParserTest method preserveEntryParserRuleOnFullyReparse1.

@Test
public void preserveEntryParserRuleOnFullyReparse1() throws Exception {
    with(ReferenceGrammarTestLanguageStandaloneSetupGenerated.class);
    ParserRule rule = get(ReferenceGrammarTestLanguageGrammarAccess.class).getKindRule();
    String model = "kind (Fritz 12)";
    checkFullReparse(rule, model);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) ReferenceGrammarTestLanguageGrammarAccess(org.eclipse.xtext.testlanguages.services.ReferenceGrammarTestLanguageGrammarAccess) Test(org.junit.Test)

Example 90 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class ComplexReconstrTest method testPrintGrammar.

@Test
public void testPrintGrammar() {
    XtextResourceSet rs = get(XtextResourceSet.class);
    rs.setClasspathURIContext(getClass());
    URI u = URI.createURI("classpath:/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTestLanguage.xtextbin");
    EObject o = rs.getResource(u, true).getContents().get(0);
    for (Object x : o.eContents()) if (x instanceof ParserRule) {
        ParserRule pr = (ParserRule) x;
        if (pr.getName().toLowerCase().contains("tricky")) {
            if (logger.isTraceEnabled())
                logger.trace(EmfFormatter.objToStr(pr));
        }
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Aggregations

ParserRule (org.eclipse.xtext.ParserRule)380 Test (org.junit.Test)172 Grammar (org.eclipse.xtext.Grammar)151 Action (org.eclipse.xtext.Action)144 Parameter (org.eclipse.xtext.Parameter)137 EPackage (org.eclipse.emf.ecore.EPackage)126 AbstractRule (org.eclipse.xtext.AbstractRule)94 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)74 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 RuleCall (org.eclipse.xtext.RuleCall)41 EObject (org.eclipse.emf.ecore.EObject)27 EnumRule (org.eclipse.xtext.EnumRule)21 TerminalRule (org.eclipse.xtext.TerminalRule)21 AbstractElement (org.eclipse.xtext.AbstractElement)18 Assignment (org.eclipse.xtext.Assignment)15 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)12 EClass (org.eclipse.emf.ecore.EClass)11 Group (org.eclipse.xtext.Group)11 NamedArgument (org.eclipse.xtext.NamedArgument)11 TypeRef (org.eclipse.xtext.TypeRef)11