Java Code Examples for org.eclipse.xtext.GrammarUtil#allTerminalRules()

The following examples show how to use org.eclipse.xtext.GrammarUtil#allTerminalRules() . 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: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence compileTerminalRules(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    boolean _isBacktrackLexer = options.isBacktrackLexer();
    if (_isBacktrackLexer) {
      _builder.newLine();
      _builder.append("// Rules duplicated to allow inter-rule references");
      _builder.newLine();
    }
  }
  {
    List<TerminalRule> _allTerminalRules = GrammarUtil.allTerminalRules(it);
    for(final TerminalRule rule : _allTerminalRules) {
      _builder.newLine();
      CharSequence _compileRule = this.compileRule(rule, it, options);
      _builder.append(_compileRule);
      _builder.newLineIfNotEmpty();
    }
  }
  return _builder;
}
 
Example 2
Source File: ToEcoreTrafoTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: ToEcoreTrafoTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testConcreteLanguageToMetamodel() throws Exception {
	XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.', '/') + ".xtext");
	Grammar element = (Grammar) r.getContents().get(0);
	List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
	assertEquals("Number of lexer-rules in Grammar", 9, lexerRules.size());
	List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
	EPackage metaModel = list.get(0);
	assertNotNull(metaModel);
	assertNotNull(metaModel.getNsPrefix());
	assertNotNull(metaModel.getNsURI());
	assertNotNull(metaModel.getName());
	EList<EClassifier> types = metaModel.getEClassifiers();
	EClass type = (EClass) types.get(1);
	EStructuralFeature feature = type.getEStructuralFeature("elements");
	assertNotNull(feature.getEType());
}
 
Example 4
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileTokens(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    boolean _isBacktrackLexer = options.isBacktrackLexer();
    if (_isBacktrackLexer) {
      _builder.append("tokens {");
      _builder.newLine();
      {
        Set<String> _allKeywords = this.keywordHelper.getAllKeywords();
        for(final String kw : _allKeywords) {
          _builder.append("\t");
          String _ruleName = this.keywordHelper.getRuleName(kw);
          _builder.append(_ruleName, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      {
        List<TerminalRule> _allTerminalRules = GrammarUtil.allTerminalRules(it);
        for(final TerminalRule rule : _allTerminalRules) {
          _builder.append("\t");
          String _ruleName_1 = this._grammarAccessExtensions.ruleName(rule);
          _builder.append(_ruleName_1, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("}");
      _builder.newLine();
    }
  }
  return _builder;
}