Refactor code
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
This commit is contained in:
0
tools/__init__.py
Normal file
0
tools/__init__.py
Normal file
39
tools/genANTLR4.py
Normal file
39
tools/genANTLR4.py
Normal file
@ -0,0 +1,39 @@
|
||||
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()
|
Reference in New Issue
Block a user