d6be336a0c
Change mpc.py to auto generate antlr4 files without having to run manualy. Also add a small command line ultility. Remove commented import in others files, and update README
40 lines
746 B
Python
40 lines
746 B
Python
import os
|
|
import subprocess
|
|
|
|
|
|
ANTLR_JAR = os.environ.get('ANTLR_LIB')
|
|
|
|
if ANTLR_JAR is None:
|
|
# fall back, not recommended
|
|
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'
|
|
]
|
|
|
|
|
|
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)
|
|
|
|
|
|
def regenerate():
|
|
for f in files_from_antlr4:
|
|
os.remove(f)
|
|
generate()
|