use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_08.
@Test
public void testEnum_08() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8'\n" + "Model: enumValue=MyEnum;\n" + "enum MyEnum: Value | Value = 'foo';";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
assertNotNull(eEnum);
assertEquals(1, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals("Value", value.getName());
assertEquals(0, value.getValue());
assertEquals("Value", value.getLiteral());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class ElementFinderTest method grammarFinder.
private AbstractGrammarElementFinder grammarFinder() {
final String file = "classpath:/org/eclipse/xtext/generator/grammarAccess/ElementFinderTestLanguage.xtext";
XtextResourceSet rs = get(XtextResourceSet.class);
rs.setClasspathURIContext(getClass());
final Resource r = rs.getResource(URI.createURI(file), true);
return new AbstractGrammarElementFinder() {
@Override
public Grammar getGrammar() {
return (Grammar) r.getContents().get(0);
}
};
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class Bug265111Test method testParseGrammar.
@Test
public void testParseGrammar() throws Exception {
String grammar = "grammar test with org.eclipse.xtext.grammarinheritance.BaseInheritanceTestLanguage\n" + "generate test 'http://test'\n" + "Root: A | Model;" + "A: 'A' name=ID;";
Resource r = getResourceFromStringAndExpect(grammar, 1);
Grammar g = (Grammar) r.getContents().get(0);
assertEquals("test", g.getName());
assertEquals(r.getErrors().toString(), 1, r.getErrors().size());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class ToEcoreTrafoTest method testConcreteLanguageToMetamodel1.
@Test
public void testConcreteLanguageToMetamodel1() throws Exception {
XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.', '/') + ".xtext");
EObject element = r.getContents().get(0);
Grammar g = (Grammar) element;
List<AbstractMetamodelDeclaration> mms = Lists.<AbstractMetamodelDeclaration>newArrayList(Iterables.filter(g.getMetamodelDeclarations(), GeneratedMetamodel.class));
assertNotNull(mms);
assertEquals(1, mms.size());
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class ToEcoreTrafoTest method testAbstractLanguageToMetamodel.
@Test
public void testAbstractLanguageToMetamodel() throws Exception {
XtextResource r = getResource("classpath:/" + AbstractTestLanguage.class.getName().replace('.', '/') + ".xtext");
Grammar element = (Grammar) r.getParseResult().getRootASTElement();
if (!r.getErrors().isEmpty()) {
EList<Diagnostic> errors = r.getErrors();
for (Diagnostic syntaxError : errors) {
logger.debug(syntaxError.getMessage() + " - " + syntaxError.getLine());
}
fail(errors.toString());
}
List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
assertEquals(8, lexerRules.size());
List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
assertNotNull(list);
assertEquals(0, list.size());
}
Aggregations