Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dariah
search
Commits
e5ca9abb
Commit
e5ca9abb
authored
Jul 07, 2021
by
Gradl, Tobias
Browse files
435: Support addidional files with grammars (OPENED)
Task-Url:
#435
parent
0ca2377c
Pipeline
#25206
passed with stage
in 51 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
build.gradle
View file @
e5ca9abb
...
...
@@ -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"
...
...
search-core/src/main/java/eu/dariah/de/search/dao/fs/GrammarDaoImpl.java
View file @
e5ca9abb
...
...
@@ -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
.
setP
arserGrammar
(
"parser grammar "
+
gc
.
getId
()
+
"Parser;
\n\n
"
+
p
arserGrammar
=
"parser grammar "
+
gc
.
getId
()
+
"Parser;
"
+
"options { tokenVocab= "
+
gc
.
getId
()
+
"Lexer; }\n\n"
+
gc
.
getP
arserGrammar
())
;
Files
.
write
(
Paths
.
get
(
filePathPrefix
+
"Parser.g4"
),
gc
.
getP
arserGrammar
()
.
getBytes
());
p
arserGrammar
;
Files
.
write
(
Paths
.
get
(
filePathPrefix
+
"Parser.g4"
),
p
arserGrammar
.
getBytes
());
}
else
{
gc
.
setP
arserGrammar
(
"grammar "
+
gc
.
getId
()
+
";\n\n"
+
gc
.
getP
arserGrammar
())
;
Files
.
write
(
Paths
.
get
(
filePathPrefix
+
".g4"
),
gc
.
getP
arserGrammar
()
.
getBytes
());
p
arserGrammar
=
"grammar "
+
gc
.
getId
()
+
";\n\n"
+
p
arserGrammar
;
Files
.
write
(
Paths
.
get
(
filePathPrefix
+
".g4"
),
p
arserGrammar
.
getBytes
());
}
return
true
;
}
}
@Override
public
void
compileGrammar
(
GrammarContainer
gc
)
throws
GrammarProcessingException
,
IOException
{
...
...
_search-commons
@
11e3a70b
Compare
ca479bb9
...
11e3a70b
Subproject commit
ca479bb95e8f7dac66ac4718192f1374710bb06e
Subproject commit
11e3a70be8ceffdcf95b0e6429f3cee814349daa
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment