org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming Java Examples

The following examples show how to use org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming. 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: JFlexGeneratorFragment2.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
	Grammar grammar = getGrammar();
	String macros = read(patternPath);
	String rules = read(additionalRulePath);
	final String encoding = codeConfig.getEncoding();
	String fileName = "Internal" + GrammarUtil.getSimpleName(grammar) + "Flexer.flex";
	
	final IXtextGeneratorFileSystemAccess fsa;
	final GrammarNaming grammarNaming;
	
	if (ui) {
		grammarNaming = contentAssistNaming;
		fsa = this.getProjectConfig().getGenericIde().getSrcGen();
		
	} else {
		grammarNaming = productionNaming;
		fsa = this.getProjectConfig().getRuntime().getSrcGen();
	}
	
	String srcGenPath = fsa.getPath();
	String parserName = grammarNaming.getInternalParserClass(grammar).getName();
	String baseName = grammarNaming.getParserGrammar(grammar).getGrammarFileName();
	baseName = baseName.substring(0, baseName.lastIndexOf('/'));
	String directory = srcGenPath + "/" + baseName;
	String contents = templatex.generateFlexer(grammar, parserName, macros, rules, codeConfig);
	fsa.generateFile(baseName + "/" + fileName, contents);
	String javaFileName = directory + "/" + "Internal" + GrammarUtil.getSimpleName(grammar) + "Flexer.java";
	String[] args = new String[] { "-d", directory, directory + "/" + fileName };
	main.runJFlex(args);
	Charset charset = Charset.forName(encoding);
	String javaCode = readFileIntoString(javaFileName, charset);
	javaCode = new NewlineNormalizer(codeConfig.getLineDelimiter()).normalizeLineDelimiters(javaCode);
	javaCode = removeTimestamps(javaCode);
	writeStringIntoFile(javaFileName, javaCode, charset);
}
 
Example #2
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateProductionGrammar() {
  @Extension
  final GrammarNaming naming = this.productionNaming;
  final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getRuntime().getSrcGen();
  this.productionGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
  this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
  this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
  this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
  this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeLineDelimiters(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
}
 
Example #3
Source File: XtextAntlrGeneratorComparisonFragment.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public AntlrFragmentHelperEx(final Naming oldNaming, final GrammarNaming prodNaming, final ContentAssistGrammarNaming caNaming) {
  super(oldNaming);
  this.prodNaming = prodNaming;
  this.caNaming = caNaming;
}
 
Example #4
Source File: XtextAntlrGeneratorComparisonFragment.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
protected GrammarNaming getProductionNaming() {
  return this.productionNaming;
}
 
Example #5
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected GrammarNaming getGrammarNaming() {
  return this.naming;
}
 
Example #6
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected GrammarNaming getGrammarNaming() {
  return this.naming;
}
 
Example #7
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public JavaFileAccess generateAntlrTokenFileProvider() {
  GeneratedJavaFileAccess _xblockexpression = null;
  {
    @Extension
    final GrammarNaming naming = this.productionNaming;
    final GeneratedJavaFileAccess file = this.fileFactory.createGeneratedJavaFile(naming.getAntlrTokenFileProviderClass(this.getGrammar()));
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("public class ");
        String _simpleName = naming.getAntlrTokenFileProviderClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
        _builder.append(_simpleName);
        _builder.append(" implements ");
        _builder.append(IAntlrTokenFileProvider.class);
        _builder.append(" {");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("@Override");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public ");
        _builder.append(InputStream.class, "\t");
        _builder.append(" getAntlrTokenFile() {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append(ClassLoader.class, "\t\t");
        _builder.append(" classLoader = getClass().getClassLoader();");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("return classLoader.getResourceAsStream(\"");
        String _tokensFileName = naming.getParserGrammar(XtextAntlrGeneratorFragment2.this.getGrammar()).getTokensFileName();
        _builder.append(_tokensFileName, "\t\t");
        _builder.append("\");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
      }
    };
    file.setContent(_client);
    _xblockexpression = file;
  }
  return _xblockexpression;
}
 
Example #8
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
protected abstract GrammarNaming getGrammarNaming();