We encountered a problem with the parser where a description contained a range value and the parse thought it was the beginning of a new field definition. We should be able to exclude the incorrect range values by looking at our last good range, and if the range does not continue the previous range, then it is probably incorrect and can be discarded. These changes can probably be performed in the tokenize section of the parser.
44 lines
1 KiB
Python
Executable file
44 lines
1 KiB
Python
Executable file
#!/usr/bin/python
|
|
from pyaccuwage.parser import PastedDefParser
|
|
import argparse
|
|
import sys
|
|
|
|
parser = argparse.ArgumentParser(description="Parse and convert contents of IRS files into pyaccuwage e-file classes.")
|
|
parser.add_argument("-f", "--full", help="Generate full python file, including related imports.", action="store_true")
|
|
parser.add_argument("-c", "--classname", help="Name to use for generated class.", type=str)
|
|
|
|
args = parser.parse_args()
|
|
|
|
lines = []
|
|
for x in sys.stdin.readlines():
|
|
lines.append(x)
|
|
|
|
pdp = PastedDefParser()
|
|
tokens = pdp.load("".join(lines))
|
|
|
|
def generate_imports():
|
|
return "\n".join([
|
|
"from pyaccuwage import model",
|
|
"from pyaccuwage.fields import *",
|
|
"",
|
|
"",
|
|
])
|
|
|
|
def generate_class_begin(name):
|
|
return "class %s(mode.Model):\n" % name
|
|
|
|
if args.full:
|
|
sys.stdout.write(generate_imports())
|
|
|
|
if args.classname:
|
|
classname = args.classname
|
|
else:
|
|
classname = "GeneratedRecord"
|
|
|
|
sys.stdout.write(generate_class_begin(classname))
|
|
|
|
|
|
for x in tokens:
|
|
sys.stdout.write('\t' + x + '\n')
|
|
|
|
|