|
@@ -23,7 +23,8 @@ def do_parse(inputfile, grammarfile):
|
|
|
try:
|
|
|
if os.path.getmtime(picklefile) > os.path.getmtime(grammarfile):
|
|
|
# Pickle is more recent than grammarfile, so use it
|
|
|
- grammar = pickle.load(open(picklefile, 'rb'))
|
|
|
+ with open(picklefile, 'rb') as f:
|
|
|
+ grammar = pickle.load(f)
|
|
|
new_grammar = False
|
|
|
else:
|
|
|
# Will be catched immediately
|
|
@@ -40,7 +41,8 @@ def do_parse(inputfile, grammarfile):
|
|
|
grammar = Grammar()
|
|
|
grammar.rules = structure['rules']
|
|
|
grammar.tokens = structure['tokens']
|
|
|
- pickle.dump(grammar, open(picklefile, 'wb'), pickle.HIGHEST_PROTOCOL)
|
|
|
+ with open(picklefile, 'wb') as f:
|
|
|
+ pickle.dump(grammar, f, pickle.HIGHEST_PROTOCOL)
|
|
|
parsers[grammarfile] = grammar
|
|
|
else:
|
|
|
new_grammar = False
|
|
@@ -50,7 +52,8 @@ def do_parse(inputfile, grammarfile):
|
|
|
try:
|
|
|
if os.path.getmtime(picklefile) > os.path.getmtime(inputfile):
|
|
|
# Pickle is more recent than inputfile, so use it
|
|
|
- result = pickle.load(open(picklefile, 'rb'))
|
|
|
+ with open(picklefile, 'rb') as f:
|
|
|
+ result = pickle.load(f)
|
|
|
else:
|
|
|
# Inputfile has changed
|
|
|
raise Exception()
|
|
@@ -59,7 +62,8 @@ def do_parse(inputfile, grammarfile):
|
|
|
if result['status'] != Parser.Constants.Success:
|
|
|
msg = "%s:%s:%s: %s" % (inputfile, result["line"], result["column"], result["text"])
|
|
|
raise Exception(msg)
|
|
|
- pickle.dump(result, open(picklefile, 'wb'), pickle.HIGHEST_PROTOCOL)
|
|
|
+ with open(picklefile, 'wb') as f:
|
|
|
+ pickle.dump(result, f, pickle.HIGHEST_PROTOCOL)
|
|
|
|
|
|
return result
|
|
|
|