Commit e5ca9abb authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

435: Support addidional files with grammars (OPENED)

Task-Url: #435
parent 0ca2377c
Pipeline #25206 passed with stage
in 51 seconds
......@@ -9,7 +9,7 @@ allprojects {
apply plugin: 'eclipse'
group = 'eu.dariah.de.minfba'
version = '4.1.2-SNAPSHOT'
version = '4.2-SNAPSHOT'
repositories {
mavenLocal()
......@@ -18,9 +18,9 @@ allprojects {
}
}
ext {
coreVersion = "6.4-SNAPSHOT"
gtfVersion = "2.2.1-SNAPSHOT"
processingVersion = "4.3-SNAPSHOT"
coreVersion = "6.5-SNAPSHOT"
gtfVersion = "2.3-SNAPSHOT"
processingVersion = "4.3.1-SNAPSHOT"
colregModelVersion = "4.3.4-RELEASE"
dariahSpVersion = "2.1.7-RELEASE"
......
......@@ -4,12 +4,17 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.EnumMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import de.unibamberg.minf.dme.model.base.Grammar;
import de.unibamberg.minf.dme.model.grammar.AuxiliaryFile;
import de.unibamberg.minf.dme.model.grammar.GrammarContainer;
import de.unibamberg.minf.dme.model.grammar.AuxiliaryFile.FileTypes;
import de.unibamberg.minf.gtf.compilation.GrammarCompiler;
import de.unibamberg.minf.gtf.exceptions.GrammarProcessingException;
import lombok.extern.slf4j.Slf4j;
......@@ -32,6 +37,9 @@ public class GrammarDaoImpl extends BaseFsDao implements GrammarDao, Initializin
FileUtils.deleteDirectory(new File(this.getGrammarDirectory(grammarId)));
}
/*
* TODO: refactor to a common method somewhere in gtf (@see de.unibamberg.minf.dme.service.GrammarServiceImpl)
*/
@Override
public boolean saveGrammar(GrammarContainer gc) throws IOException {
if (gc.getParserGrammar()==null || gc.getParserGrammar().trim().isEmpty()) {
......@@ -51,20 +59,38 @@ public class GrammarDaoImpl extends BaseFsDao implements GrammarDao, Initializin
}
Files.createDirectories(Paths.get(dirPath));
if (gc.getLexerGrammar()!=null && !gc.getLexerGrammar().trim().isEmpty()) {
gc.setLexerGrammar("lexer grammar " + gc.getId() + "Lexer;\n\n" + gc.getLexerGrammar());
Files.write(Paths.get(filePathPrefix + "Lexer.g4"), gc.getLexerGrammar().getBytes());
String lexerGrammar = gc.getLexerGrammar();
String parserGrammar = gc.getParserGrammar();
Map<FileTypes, String> fileTypeNameMap = new EnumMap<>(FileTypes.class);
if (gc.getAuxiliaryFiles()!=null) {
String content;
for (AuxiliaryFile f : gc.getAuxiliaryFiles()) {
content = f.getContent().replace("{LEXER}", gc.getId() + "Lexer").replace("{PARSER}", gc.getId() + "Parser");
Files.write(Paths.get(dirPath + f.getFileType().getFileName()), content.getBytes());
fileTypeNameMap.put(f.getFileType(), f.getFileType().getFileName().substring(0, f.getFileType().getFileName().indexOf('.')));
}
}
if (lexerGrammar!=null && !lexerGrammar.trim().isEmpty()) {
if (fileTypeNameMap.containsKey(FileTypes.LEXER_SUPERCLASS)) {
lexerGrammar = "options { superClass= " + fileTypeNameMap.get(FileTypes.LEXER_SUPERCLASS) + "; }\n\n" + lexerGrammar;
}
lexerGrammar = "lexer grammar " + gc.getId() + "Lexer;\n\n" + lexerGrammar;
Files.write(Paths.get(filePathPrefix + "Lexer.g4"), lexerGrammar.getBytes());
gc.setParserGrammar("parser grammar " + gc.getId() + "Parser;\n\n" +
parserGrammar = "parser grammar " + gc.getId() + "Parser; " +
"options { tokenVocab= " + gc.getId() + "Lexer; }\n\n" +
gc.getParserGrammar());
Files.write(Paths.get(filePathPrefix + "Parser.g4"), gc.getParserGrammar().getBytes());
parserGrammar;
Files.write(Paths.get(filePathPrefix + "Parser.g4"), parserGrammar.getBytes());
} else {
gc.setParserGrammar("grammar " + gc.getId() + ";\n\n" + gc.getParserGrammar());
Files.write(Paths.get(filePathPrefix + ".g4"), gc.getParserGrammar().getBytes());
parserGrammar = "grammar " + gc.getId() + ";\n\n" + parserGrammar;
Files.write(Paths.get(filePathPrefix + ".g4"), parserGrammar.getBytes());
}
return true;
}
}
@Override
public void compileGrammar(GrammarContainer gc) throws GrammarProcessingException, IOException {
......
Subproject commit ca479bb95e8f7dac66ac4718192f1374710bb06e
Subproject commit 11e3a70be8ceffdcf95b0e6429f3cee814349daa
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment