mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[generator2] remove idea specific code from generic antlr generator
This commit is contained in:
parent
3883c3bf86
commit
da891708b0
6 changed files with 48 additions and 18 deletions
|
@ -33,9 +33,11 @@ class PsiAntlrGrammarGenerator extends AbstractAntlrGrammarWithActionsGenerator
|
|||
|
||||
@Inject
|
||||
extension IdeaPluginClassNames
|
||||
@Inject
|
||||
extension PsiGrammarNaming naming
|
||||
|
||||
override protected getGrammarClass(Grammar it) {
|
||||
getGrammarClass('Psi')
|
||||
override protected getGrammarNaming() {
|
||||
naming
|
||||
}
|
||||
|
||||
override protected compileOptions(Grammar it, AntlrOptions options) '''
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea.parser.antlr
|
||||
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
|
||||
@Singleton
|
||||
class PsiGrammarNaming extends GrammarNaming {
|
||||
@Inject
|
||||
extension XtextGeneratorNaming
|
||||
|
||||
override String getParserPackage(Grammar it) '''«ideaBasePackage».parser.antlr.internal'''
|
||||
|
||||
override getGrammarClass(Grammar it) {
|
||||
new TypeReference(parserPackage, '''PsiInternal«simpleName»''')
|
||||
}
|
||||
}
|
|
@ -15,15 +15,17 @@ import org.eclipse.xtext.xtext.generator.parser.antlr.AbstractAntlrGeneratorFrag
|
|||
class XtextAntlrIDEAGeneratorFragment extends AbstractAntlrGeneratorFragment2 {
|
||||
|
||||
@Inject
|
||||
extension PsiAntlrGrammarGenerator
|
||||
PsiAntlrGrammarGenerator generator
|
||||
|
||||
@Inject CodeConfig codeConfig
|
||||
|
||||
@Inject IXtextProjectConfig projectConfig
|
||||
|
||||
@Inject extension PsiGrammarNaming
|
||||
|
||||
override protected doGenerate() {
|
||||
val fsa = projectConfig.ideaPluginSrcGen
|
||||
grammar.generate(options, fsa)
|
||||
generator.generate(grammar, options, fsa)
|
||||
|
||||
val encoding = codeConfig.encoding
|
||||
val grammarFileName = '''«grammar.grammarClass.path».g'''
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.eclipse.xtext.xtext.generator.CodeConfig
|
|||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
|
||||
import org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions
|
||||
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.*
|
||||
|
@ -44,9 +43,6 @@ abstract class AbstractAntlrGrammarGenerator {
|
|||
@Inject
|
||||
protected extension GrammarAccessExtensions
|
||||
|
||||
@Inject
|
||||
protected extension GrammarNaming
|
||||
|
||||
@Inject CodeConfig codeConfig
|
||||
|
||||
def generate(Grammar it, AntlrOptions options, IXtextGeneratorFileSystemAccess fsa) {
|
||||
|
@ -54,14 +50,14 @@ abstract class AbstractAntlrGrammarGenerator {
|
|||
filter.discardUnreachableRules = options.skipUnusedRules
|
||||
val RuleNames ruleNames = RuleNames.getRuleNames(grammar, true);
|
||||
val Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
|
||||
fsa.generateFile(grammarClass.path + '.g', flattened.compile(options))
|
||||
fsa.generateFile(grammarNaming.getGrammarClass(it).path + '.g', flattened.compile(options))
|
||||
}
|
||||
|
||||
protected abstract def TypeReference getGrammarClass(Grammar it)
|
||||
protected abstract def GrammarNaming getGrammarNaming()
|
||||
|
||||
protected def compile(Grammar it, AntlrOptions options) '''
|
||||
«codeConfig.fileHeader»
|
||||
grammar «grammarClass.simpleName»;
|
||||
grammar «grammarNaming.getGrammarClass(it).simpleName»;
|
||||
«compileOptions(options)»
|
||||
«compileTokens(options)»
|
||||
«compileLexerHeader(options)»
|
||||
|
@ -82,7 +78,7 @@ abstract class AbstractAntlrGrammarGenerator {
|
|||
protected def compileLexerHeader(Grammar it, AntlrOptions options) '''
|
||||
|
||||
@lexer::header {
|
||||
package «grammarClass.packageName»;
|
||||
package «grammarNaming.getGrammarClass(it).packageName»;
|
||||
«compileLexerImports(options)»
|
||||
}
|
||||
'''
|
||||
|
@ -97,7 +93,7 @@ abstract class AbstractAntlrGrammarGenerator {
|
|||
protected def compileParserHeader(Grammar it, AntlrOptions options) '''
|
||||
|
||||
@parser::header {
|
||||
package «grammarClass.packageName»;
|
||||
package «grammarNaming.getGrammarClass(it).packageName»;
|
||||
«compileParserImports(options)»
|
||||
}
|
||||
'''
|
||||
|
|
|
@ -27,12 +27,14 @@ import org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions
|
|||
import static extension org.eclipse.xtext.EcoreUtil2.*
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.*
|
||||
import com.google.inject.Inject
|
||||
|
||||
@Singleton
|
||||
class AntlrGrammarGenerator extends AbstractAntlrGrammarWithActionsGenerator {
|
||||
@Inject extension GrammarNaming naming
|
||||
|
||||
protected override getGrammarClass(Grammar it) {
|
||||
getGrammarClass('')
|
||||
protected override getGrammarNaming() {
|
||||
naming
|
||||
}
|
||||
|
||||
protected override compileOptions(Grammar it, AntlrOptions options) '''
|
||||
|
|
|
@ -21,10 +21,10 @@ class GrammarNaming {
|
|||
@Inject
|
||||
extension XtextGeneratorNaming
|
||||
|
||||
def String getParserPackage(Grammar it) '''«runtimeBasePackage».idea.parser.antlr.internal'''
|
||||
def String getParserPackage(Grammar it) '''«runtimeBasePackage».parser.antlr.internal'''
|
||||
|
||||
def TypeReference getGrammarClass(Grammar it, String prefix) {
|
||||
new TypeReference(parserPackage, '''«prefix»Internal«simpleName»''')
|
||||
def TypeReference getGrammarClass(Grammar it) {
|
||||
new TypeReference(parserPackage, '''Internal«simpleName»''')
|
||||
}
|
||||
|
||||
def TypeReference getInternalParserClass(Grammar it) {
|
||||
|
|
Loading…
Reference in a new issue