org.eclipse.xtext.Grammar Java Examples

The following examples show how to use org.eclipse.xtext.Grammar. 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: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCycleInTypeHierarchy() throws Exception {
	String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals" +
			" generate test 'http://test'";
	grammarAsText += " RuleA: RuleB;";
	grammarAsText += " RuleB: RuleC;";
	grammarAsText += " RuleC: RuleA;";
	grammarAsText += " RuleD: RuleA;";

	Grammar grammar = (Grammar) getModel(grammarAsText);
	AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
	
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(grammar.getRules().get(0).getType(), true, false);
	messageAcceptor.expectedContext(
			grammar.getRules().get(1).getType(),
			grammar.getRules().get(2).getType()
	);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
	messageAcceptor.validate();
}
 
Example #2
Source File: OverriddenValueInspectorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testOptionalAction_04() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second (isSecond=\'keyword\' | {First.second=current} id=INT) name=ID;");
  _builder.newLine();
  _builder.append("Second: \'keyword\' name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
 
Example #3
Source File: EnumTemplateVariableResolver.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<String> resolveValues(TemplateVariable variable,
		XtextTemplateContext castedContext) {
	String enumerationName = variable.getVariableType()
			.getParams().iterator().next();
	Grammar grammar = getGrammar(castedContext);
	if (grammar == null)
		return Collections.emptyList();
	EEnum enumeration = (EEnum) getEClassifierForGrammar(enumerationName, grammar);
	if (enumeration == null) {
		return Collections.emptyList();
	}
	return Lists.transform(enumeration.getELiterals(), new Function<EEnumLiteral, String>() {
		@Override
		public String apply(EEnumLiteral enumLiteral) {
			return enumLiteral.getLiteral();
		}
	});
}
 
Example #4
Source File: XtextRenameStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IRenameStrategy createRenameStrategy(final EObject targetElement, final IRenameElementContext context) {
	return new XtextSwitch<IRenameStrategy>() {

		@Override
		public IRenameStrategy caseAbstractMetamodelDeclaration(AbstractMetamodelDeclaration metamodelDeclaration) {
			return metamodelDeclarationProvider.get();
		}

		@Override
		public IRenameStrategy caseAbstractRule(AbstractRule rule) {
			return ruleProvider.get();
		}

		@Override
		public IRenameStrategy caseGrammar(Grammar grammar) {
			return XtextRenameStrategyProvider.super.createRenameStrategy(targetElement, context);
		}
	}.doSwitch(targetElement);
}
 
Example #5
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public List<String> initialHiddenTokens(final Grammar it) {
  List<String> _xblockexpression = null;
  {
    boolean _isDefinesHiddenTokens = it.isDefinesHiddenTokens();
    if (_isDefinesHiddenTokens) {
      final Function1<AbstractRule, String> _function = (AbstractRule it_1) -> {
        return this.ruleName(it_1);
      };
      return IterableExtensions.<String>toList(ListExtensions.<AbstractRule, String>map(it.getHiddenTokens(), _function));
    }
    int _size = it.getUsedGrammars().size();
    boolean _equals = (_size == 1);
    if (_equals) {
      return this.initialHiddenTokens(IterableExtensions.<Grammar>head(it.getUsedGrammars()));
    }
    _xblockexpression = CollectionLiterals.<String>emptyList();
  }
  return _xblockexpression;
}
 
Example #6
Source File: N4JSRenameStrategy.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the TypeExpressions grammar
 */
protected Grammar getTypeExpressionsGrammar() {
	Grammar grammar = grammarProvider.getGrammar(this);
	while (grammar != null) {
		if ("org.eclipse.n4js.ts.TypeExpressions".equals(grammar.getName())) {
			return grammar;
		}
		List<Grammar> grammars = grammar.getUsedGrammars();
		if (!grammars.isEmpty()) {
			grammar = grammars.iterator().next();
		} else {
			return null;
		}
	}
	return grammar;
}
 
Example #7
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testPredicatedUnorderedGroup_04() throws Exception {
	String grammarAsText =
			"grammar test with org.eclipse.xtext.common.Terminals\n" +
			"generate test 'http://test'\n" +
			"A: =>(name=ID value=B);\n" +
			"B: name=ID & value=STRING;";
	
	Grammar grammar = (Grammar) getModel(grammarAsText);
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
	Group predicatedGroup = (Group) grammar.getRules().get(0).getAlternatives();
	Group groupContent = (Group) predicatedGroup.getElements().get(0);
	Assignment valueAssignment = (Assignment) groupContent.getElements().get(1);
	messageAcceptor.expectedContext(
			grammar.getRules().get(0).getAlternatives(),
			valueAssignment.getTerminal(),
			grammar.getRules().get(1).getAlternatives()
	);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkUnorderedGroupIsNotPredicated(grammar);
	messageAcceptor.validate();
}
 
Example #8
Source File: GrammarParserTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #9
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkGrammarName(Grammar g) {
	String name = g.getName();
	if (name == null) {
		return;
	}
	String[] split = name.split("\\.");
	if (split.length == 1)
		error("You must use a namespace.", XtextPackage.Literals.GRAMMAR__NAME);
	for (int i = 0; i < split.length - 1; i++) {
		String nsEle = split[i];
		if (Character.isUpperCase(nsEle.charAt(0)))
			warning("Namespace elements should start with a lower case letter.", XtextPackage.Literals.GRAMMAR__NAME);
	}
	String ele = split[split.length - 1];
	if (!Character.isUpperCase(ele.charAt(0)))
		error("The last element should start with an upper case letter.", XtextPackage.Literals.GRAMMAR__NAME);
}
 
Example #10
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug_282852_08() throws Exception {
	Grammar base = XtextFactory.eINSTANCE.createGrammar();
	AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule();
	ruleFoo.setName("Foo");
	base.getRules().add(ruleFoo);
	AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule();
	subRuleFoo.setName("foo");
	AbstractRule subRuleFoo2 = XtextFactory.eINSTANCE.createParserRule();
	subRuleFoo2.setName("fOO");
	AbstractRule subRuleFoo3 = XtextFactory.eINSTANCE.createParserRule();
	subRuleFoo3.setName("FOO");
	base.getRules().add(subRuleFoo);
	base.getRules().add(subRuleFoo2);
	base.getRules().add(subRuleFoo3);

	XtextValidator validator = get(XtextValidator.class);
	configureValidator(validator, this, subRuleFoo);
	validator.checkRuleName(subRuleFoo);
	assertEquals("A rule's name has to be unique even case insensitive. The conflicting rules are 'FOO', 'Foo' and 'fOO'.", lastMessage);
}
 
Example #11
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testPredicatedUnorderedGroup_01() throws Exception {
	String grammarAsText =
			"grammar test with org.eclipse.xtext.common.Terminals\n" +
			"generate test 'http://test'\n" +
			"Model: =>(name=ID & value=STRING);\n";
	
	Grammar grammar = (Grammar) getModel(grammarAsText);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
	messageAcceptor.expectedContext(
			grammar.getRules().get(0).getAlternatives(),
			((CompoundElement) grammar.getRules().get(0).getAlternatives()).getElements().get(0)
	);
	PredicateUsesUnorderedGroupInspector inspector = new PredicateUsesUnorderedGroupInspector(messageAcceptor);
	inspector.inspect(grammar);
	messageAcceptor.validate();
}
 
Example #12
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug_282852_03() throws Exception {
	Grammar base = XtextFactory.eINSTANCE.createGrammar();
	Grammar child = XtextFactory.eINSTANCE.createGrammar();
	child.getUsedGrammars().add(base);
	AbstractRule ruleFoo = XtextFactory.eINSTANCE.createParserRule();
	ruleFoo.setName("Foo");
	base.getRules().add(ruleFoo);
	AbstractRule subRuleFoo = XtextFactory.eINSTANCE.createParserRule();
	subRuleFoo.setName("Foo");
	child.getRules().add(subRuleFoo);

	XtextValidator validator = get(XtextValidator.class);
	validator.setMessageAcceptor(this);
	validator.checkRuleName(subRuleFoo);
	assertNull(lastMessage);
}
 
Example #13
Source File: SemanticSequencerNfaProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: SyntacticSequencerPDAProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Extracts the grammar from this transition or the NFA if this transition does not point to an
 * {@link AbstractElement}.
 */
private Grammar getGrammar(Nfa<ISynState> nfa) {
	AbstractElement grammarElement = getGrammarElement();
	if (grammarElement == null) {
		grammarElement = nfa.getStart().getGrammarElement();
		if (grammarElement == null) {
			grammarElement = nfa.getStop().getGrammarElement();
			if (grammarElement == null) {
				Iterator<ISynState> iter = nfa.getStart().getFollowers().iterator();
				while (grammarElement == null && iter.hasNext()) {
					grammarElement = iter.next().getGrammarElement();
				}
			}
		}
	}
	Grammar grammar = GrammarUtil.getGrammar(grammarElement);
	return grammar;
}
 
Example #15
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getEcoreFilePath(final Grammar grammar) {
  String _xblockexpression = null;
  {
    final String ecoreModelFolder = this.getProjectConfig().getRuntime().getEcoreModelFolder();
    String _modelPluginID = this.getModelPluginID();
    String _plus = ("/" + _modelPluginID);
    String _plus_1 = (_plus + "/");
    String _plus_2 = (_plus_1 + ecoreModelFolder);
    String _plus_3 = (_plus_2 + "/");
    String _modelName = this.getModelName(grammar);
    String _plus_4 = (_plus_3 + _modelName);
    _xblockexpression = (_plus_4 + ".ecore");
  }
  return _xblockexpression;
}
 
Example #16
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence _compileRule(final Group it, final Grammar grammar, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  CharSequence _ruleImpl = this.ruleImpl(it, grammar, options, 0);
  _builder.append(_ruleImpl);
  _builder.newLineIfNotEmpty();
  return _builder;
}
 
Example #17
Source File: XtendAntlrGrammarGeneratorHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public LinkedHashSet<String> getTokens(final Grammar it) {
  final LinkedHashSet<String> tokens = CollectionLiterals.<String>newLinkedHashSet();
  List<ParserRule> _allParserRules = GrammarUtil.allParserRules(it);
  List<EnumRule> _allEnumRules = GrammarUtil.allEnumRules(it);
  Iterable<AbstractRule> _plus = Iterables.<AbstractRule>concat(_allParserRules, _allEnumRules);
  for (final AbstractRule rule : _plus) {
    this.collectTokens(rule, tokens);
  }
  return tokens;
}
 
Example #18
Source File: TestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected Grammar internalFindGrammar(GrammarProvider grammarProvider) {
	Grammar grammar = grammarProvider.getGrammar(this);
	while (grammar != null) {
		if ("org.eclipse.xtext.ide.tests.testlanguage.TestLanguage".equals(grammar.getName())) {
			return grammar;
		}
		List<Grammar> grammars = grammar.getUsedGrammars();
		if (!grammars.isEmpty()) {
			grammar = grammars.iterator().next();
		} else {
			return null;
		}
	}
	return grammar;
}
 
Example #19
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Resource createResourceForEPackages(Grammar grammar, XpandExecutionContext ctx, List<EPackage> packs,
		ResourceSet rs) {
	URI ecoreFileUri = getEcoreFileUri(grammar, ctx);
	ecoreFileUri = toPlatformResourceURI(ecoreFileUri);
	Resource existing = rs.getResource(ecoreFileUri, false);
	if (existing != null) {
		existing.unload();
		rs.getResources().remove(existing);
	}
	Resource ecoreFile = rs.createResource(ecoreFileUri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	ecoreFile.getContents().addAll(packs);
	return ecoreFile;
}
 
Example #20
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testHiddenTokenIsATerminal_01() throws Exception {
	String grammarAsText =
		"grammar test with org.eclipse.xtext.common.Terminals hidden(Model)\n" +
		"generate test 'http://test'\n" +
		"Model: name=ID;\n";

	Grammar grammar = (Grammar) getModel(grammarAsText);
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(grammar, true, false);
	configureValidator(validator, messageAcceptor, grammar);
	validator.checkHiddenTokenIsNotAFragment(grammar);
	messageAcceptor.validate();
}
 
Example #21
Source File: RefactorElementNameFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isUseJdtRefactoring(final Grammar grammar) {
  boolean _xifexpression = false;
  boolean _isSet = this.useJdtRefactoring.isSet();
  if (_isSet) {
    _xifexpression = this.useJdtRefactoring.get();
  } else {
    _xifexpression = this._xbaseUsageDetector.inheritsXbase(grammar);
  }
  return _xifexpression;
}
 
Example #22
Source File: TemplateValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkParameters(Variable variable) {
	Codetemplate template = EcoreUtil2.getContainerOfType(variable, Codetemplate.class);
	Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class);
	if (templates != null && template != null) {
		Grammar language = templates.getLanguage();
		AbstractRule rule = template.getContext();
		ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(language);
		if (helper != null && rule != null && !rule.eIsProxy() && rule instanceof ParserRule) {
			String contextTypeId = helper.getId(rule);
			ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(language);
			TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
			if (contextType != null) {
				Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(),
						TemplateVariableResolver.class);
				String type = variable.getType();
				if (type == null)
					type = variable.getName();
				while (resolvers.hasNext()) {
					final TemplateVariableResolver resolver = resolvers.next();
					if (resolver.getType().equals(type)) {
						IInspectableTemplateVariableResolver inspectableResolver = registry
								.toInspectableResolver(resolver);
						if (inspectableResolver != null) {
							inspectableResolver.validateParameters(variable, this);
						}
					}
				}
			}
		}
	}
}
 
Example #23
Source File: LanguageConfig.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	if (LOG.isInfoEnabled()) {
		LOG.info("generating infrastructure for " + grammar.getName() + " with fragments : "
				+ Strings.toString(this.fragments, new ToStringFunction(", "), ", "));
	}
	super.generate(grammar, ctx);
}
 
Example #24
Source File: GrammarUtilTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAllRules() throws Exception {
  this.with(XtextStandaloneSetup.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate g \'http://1\'");
  _builder.newLine();
  _builder.append("Rule:");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("name=super::STRING;");
  _builder.newLine();
  _builder.append("terminal STRING: \'\"\';");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
  final Function1<AbstractRule, String> _function = (AbstractRule it) -> {
    return it.getName();
  };
  Assert.assertEquals(
    Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Rule", "STRING", "ID", "INT", "STRING", "ML_COMMENT", "SL_COMMENT", "WS", "ANY_OTHER")).toString(), 
    ListExtensions.<AbstractRule, String>map(allRules, _function).toString());
}
 
Example #25
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) {
  if (it instanceof EnumRule) {
    return _compileRule((EnumRule)it, grammar, options);
  } else if (it instanceof ParserRule) {
    return _compileRule((ParserRule)it, grammar, options);
  } else if (it instanceof TerminalRule) {
    return _compileRule((TerminalRule)it, grammar, options);
  } else if (it instanceof String) {
    return _compileRule((String)it, grammar, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, grammar, options).toString());
  }
}
 
Example #26
Source File: ValidEntryRuleInspectorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAction_01() throws Exception {
	String grammarAsString = "grammar org.foo with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'foo.sample'\n" +
			"X : {X} ID?;";
	Grammar grammar = getGrammar(grammarAsString);
	ParserRule rule = (ParserRule) GrammarUtil.findRuleForName(grammar, "X");
	validateRule(rule);
	assertTrue(warnings.toString(), warnings.isEmpty());
}
 
Example #27
Source File: AbstractAntlrXtendGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected com.google.inject.Module createModule(Grammar grammar) {
	return new com.google.inject.Module() {
		@Override
		public void configure(Binder binder) {
			binder.bind(Grammar.class).toInstance(grammar);
			binder.bind(Naming.class).toInstance(getNaming());
			binder.bind(IGrammarAccess.class).toInstance(new Xtend2GeneratorFragment.GenericGrammarAccess(grammar));
			addLocalBindings(binder);
		}
	};
}
 
Example #28
Source File: ActionTestLanguage2GrammarAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected Grammar internalFindGrammar(GrammarProvider grammarProvider) {
	Grammar grammar = grammarProvider.getGrammar(this);
	while (grammar != null) {
		if ("org.eclipse.xtext.testlanguages.ActionTestLanguage2".equals(grammar.getName())) {
			return grammar;
		}
		List<Grammar> grammars = grammar.getUsedGrammars();
		if (!grammars.isEmpty()) {
			grammar = grammars.iterator().next();
		} else {
			return null;
		}
	}
	return grammar;
}
 
Example #29
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected Xtext2EcoreTransformer createTransformer(Grammar grammar, IDiagnosticConsumer consumer) {
	final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
	transformer.setErrorAcceptor(new TransformationDiagnosticsProducer(consumer));
	transformer.setPostProcessor(postProcessor);
	return transformer;
}
 
Example #30
Source File: GrammarConstraintProviderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private String getParserRule(String body) throws Exception {
	Grammar grammar = (Grammar) getModel(HEADER + body);
	IGrammarConstraintProvider gcp = get(IGrammarConstraintProvider.class);

	SerializationContextMap<IConstraint> constraints = gcp.getConstraints(grammar);
	List<String> result = Lists.newArrayList();
	for (Entry<IConstraint> r : constraints.sortedCopy().values()) {
		result.add(Joiner.on(", ").join(r.getContexts()) + ":");
		result.add("  " + r.getValue());
	}
	return Joiner.on("\n").join(result);
}