2018-12-04 02:05:06 +07:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
ANTLR_JAR = os.environ.get('ANTLR_LIB')
|
|
|
|
|
|
|
|
if ANTLR_JAR is None:
|
|
|
|
# fall back, not recommended
|
2018-12-18 01:06:36 +07:00
|
|
|
ANTLR_JAR = '../external/antrl4.jar'
|
|
|
|
|
|
|
|
files_from_antlr4 = [
|
|
|
|
'parser/MP.interp',
|
|
|
|
'parser/MPLexer.interp',
|
|
|
|
'parser/MPLexer.py',
|
|
|
|
'parser/MPLexer.tokens',
|
|
|
|
'parser/MPParser.py',
|
|
|
|
'parser/MP.tokens',
|
|
|
|
'parser/MPVisitor.py'
|
|
|
|
]
|
2018-12-04 02:05:06 +07:00
|
|
|
|
|
|
|
|
|
|
|
def generate():
|
|
|
|
if all(list(map(os.path.isfile, files_from_antlr4))):
|
|
|
|
return
|
|
|
|
gen_antlr_class_cmd = [
|
|
|
|
"java",
|
|
|
|
"-jar",
|
|
|
|
ANTLR_JAR,
|
|
|
|
"-no-listener",
|
|
|
|
"-visitor",
|
|
|
|
"parser/MP.g4"
|
|
|
|
]
|
|
|
|
subprocess.run(gen_antlr_class_cmd)
|
|
|
|
|
|
|
|
|
2018-12-18 01:06:36 +07:00
|
|
|
def regenerate():
|
|
|
|
for f in files_from_antlr4:
|
|
|
|
os.remove(f)
|
2018-12-04 02:05:06 +07:00
|
|
|
generate()
|