Revamp file reading and error messages
This commit is contained in:
@ -33,14 +33,6 @@ import os
|
|||||||
import ply.lex as lex
|
import ply.lex as lex
|
||||||
import ply.yacc as yacc
|
import ply.yacc as yacc
|
||||||
|
|
||||||
global Verbose
|
|
||||||
global DriverDump
|
|
||||||
global CodeDump
|
|
||||||
global FunctionTypes
|
|
||||||
global DriveableFunctionTypes
|
|
||||||
global NumberOfLinesIn
|
|
||||||
global NumberOfLinesOut
|
|
||||||
|
|
||||||
states = (
|
states = (
|
||||||
('tcl', 'exclusive'),
|
('tcl', 'exclusive'),
|
||||||
)
|
)
|
||||||
@ -63,11 +55,33 @@ DriveableFunctionTypes = [
|
|||||||
Verbose = False
|
Verbose = False
|
||||||
DriverDump = False
|
DriverDump = False
|
||||||
CodeDump = False
|
CodeDump = False
|
||||||
|
PrintedFileName = -1
|
||||||
|
NumberOfLinesIn = 0
|
||||||
|
NumberOfLinesOut = 0
|
||||||
|
SourceFileList = []
|
||||||
|
SourceLineList = []
|
||||||
|
|
||||||
def PrintParseError(message):
|
def PrintParseError(message):
|
||||||
|
global PrintedFileName
|
||||||
|
global lexer
|
||||||
|
global SourceData
|
||||||
|
curr_line = lexer.lineno
|
||||||
|
curr_file = SourceLineList[curr_line - 1][0]
|
||||||
|
if curr_file != PrintedFileName:
|
||||||
|
PrintedFileName = curr_file
|
||||||
|
SourceFile = SourceFileList[curr_file]
|
||||||
|
print "in", SourceFile
|
||||||
print message
|
print message
|
||||||
|
print "%4d:" % SourceLineList[curr_line - 1][1], SourceData[curr_line - 1]
|
||||||
|
|
||||||
def PrintPostError(message):
|
def PrintPostError(message):
|
||||||
|
global PrintedFileName
|
||||||
|
global SourceLineList
|
||||||
|
curr_file = 0
|
||||||
|
if curr_file != PrintedFileName:
|
||||||
|
PrintedFileName = curr_file
|
||||||
|
SourceFile = SourceFileList[curr_file]
|
||||||
|
print "in", SourceFile
|
||||||
print message
|
print message
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1783,11 +1797,46 @@ def process_drivers(TheDrivers):
|
|||||||
dump_driver(MyDriver)
|
dump_driver(MyDriver)
|
||||||
generate_driver(MyDriver)
|
generate_driver(MyDriver)
|
||||||
|
|
||||||
|
def load_file(source_file, depth_list):
|
||||||
|
global SourceFileList, SourceLineList
|
||||||
|
# find the file and set the name
|
||||||
|
SourceFile = os.path.realpath(os.path.abspath(source_file))
|
||||||
|
if not os.path.isfile(SourceFile):
|
||||||
|
#print source_file, SourceFile, SourceFileList
|
||||||
|
if len(SourceFileList) > 0:
|
||||||
|
trial_name = os.path.join(os.path.dirname(SourceFileList[0]), source_file)
|
||||||
|
#print trial_name
|
||||||
|
if os.path.isfile(trial_name):
|
||||||
|
SourceFile = os.path.realpath(os.path.abspath(trial_name))
|
||||||
|
SourceFileList.append(SourceFile)
|
||||||
|
curr_file = len(SourceFileList) - 1
|
||||||
|
fd = open(SourceFile, 'r')
|
||||||
|
LocalData = []
|
||||||
|
line_no = 0
|
||||||
|
for line in fd:
|
||||||
|
line_no += 1
|
||||||
|
line = line.rstrip('\n')
|
||||||
|
LocalData.append(line)
|
||||||
|
SourceLineList.append((curr_file, line_no))
|
||||||
|
fd.close()
|
||||||
|
return LocalData
|
||||||
|
|
||||||
|
def dump_source_files(data):
|
||||||
|
print "SourceFileList:", SourceFileList
|
||||||
|
print "SourceLineList:", SourceLineList
|
||||||
|
curr_file = -1
|
||||||
|
for line_no, line in enumerate(data):
|
||||||
|
if SourceLineList[line_no][0] != curr_file:
|
||||||
|
curr_file = SourceLineList[line_no][0]
|
||||||
|
print "File:", SourceFileList[curr_file]
|
||||||
|
print "%4d:" % SourceLineList[line_no][1], line
|
||||||
|
|
||||||
def process_source(source_files):
|
def process_source(source_files):
|
||||||
global lexer, yaccer
|
global lexer, yaccer
|
||||||
global PathName
|
global PathName, SourceFile
|
||||||
global TheDrivers
|
global TheDrivers
|
||||||
global NumberOfLinesIn
|
global NumberOfLinesIn
|
||||||
|
global SourceData
|
||||||
|
|
||||||
TheDrivers = {}
|
TheDrivers = {}
|
||||||
|
|
||||||
@ -1805,12 +1854,10 @@ def process_source(source_files):
|
|||||||
|
|
||||||
for source_file in source_files:
|
for source_file in source_files:
|
||||||
PathName = os.path.realpath(os.path.abspath(os.path.dirname(source_file)))
|
PathName = os.path.realpath(os.path.abspath(os.path.dirname(source_file)))
|
||||||
fd = open(source_file, 'r')
|
SourceData = load_file(source_file, [])
|
||||||
data = fd.read()
|
NumberOfLinesIn = len(SourceData)
|
||||||
fd.close()
|
|
||||||
NumberOfLinesIn = data.count('\n')
|
|
||||||
start_line = lexer.lineno
|
start_line = lexer.lineno
|
||||||
yaccer.parse(data)
|
yaccer.parse('\n'.join(SourceData))
|
||||||
stop_line = lexer.lineno
|
stop_line = lexer.lineno
|
||||||
if Verbose:
|
if Verbose:
|
||||||
print 'Consumed file %s with %d lines (%d, %d)' % \
|
print 'Consumed file %s with %d lines (%d, %d)' % \
|
||||||
@ -1818,6 +1865,8 @@ def process_source(source_files):
|
|||||||
lexer.lineno = 1
|
lexer.lineno = 1
|
||||||
|
|
||||||
process_drivers(TheDrivers)
|
process_drivers(TheDrivers)
|
||||||
|
if args.list:
|
||||||
|
dump_source_files(SourceData)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global Verbose
|
global Verbose
|
||||||
@ -1832,6 +1881,8 @@ def main():
|
|||||||
action="store_true")
|
action="store_true")
|
||||||
parser.add_argument("-d", "--driver", help="dump driver",
|
parser.add_argument("-d", "--driver", help="dump driver",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
parser.add_argument("-l", "--list", help="list output",
|
||||||
|
action="store_true")
|
||||||
parser.add_argument("-m", "--move", help="generate move commands",
|
parser.add_argument("-m", "--move", help="generate move commands",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
parser.add_argument("-v", "--verbose", help="verbose output",
|
parser.add_argument("-v", "--verbose", help="verbose output",
|
||||||
|
Reference in New Issue
Block a user