diff options
author | ptmcg <ptmcg@austin.rr.com> | 2018-10-30 17:13:40 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2018-10-30 17:13:40 -0500 |
commit | e308005e9645303487451909d00079187edf09e6 (patch) | |
tree | 34cebb32ebac8eebe6b5655f0a3d5ef2eb551e99 | |
parent | 41bb3b91e2f1e552fc1afa2373e21028035471aa (diff) | |
download | pyparsing-git-e308005e9645303487451909d00079187edf09e6.tar.gz |
Fix Issue #40 - Py3 enforces tighter exception scoping, plus other exception typo
-rw-r--r-- | examples/SimpleCalc.py | 17 | ||||
-rw-r--r-- | examples/fourFn.py | 2 |
2 files changed, 10 insertions, 9 deletions
diff --git a/examples/SimpleCalc.py b/examples/SimpleCalc.py index 46a5dff..0bf62e4 100644 --- a/examples/SimpleCalc.py +++ b/examples/SimpleCalc.py @@ -69,8 +69,8 @@ if __name__ == '__main__': print("Type in the string to be parsed or 'quit' to exit the program")
input_string = input("> ")
- while input_string != 'quit':
- if input_string.lower() == 'debug':
+ while input_string.strip().lower() != 'quit':
+ if input_string.strip().lower() == 'debug':
debug_flag=True
input_string = input("> ")
continue
@@ -81,9 +81,9 @@ if __name__ == '__main__': if input_string != '':
# try parsing the input string
try:
- L=pattern.parseString( input_string, parseAll=True )
+ L=pattern.parseString(input_string, parseAll=True)
except ParseException as err:
- L=['Parse Failure',input_string]
+ L=['Parse Failure', input_string, (str(err), err.line, err.column)]
# show result of parsing the input string
if debug_flag: print(input_string, "->", L)
@@ -102,12 +102,13 @@ if __name__ == '__main__': # Assign result to a variable if required
if L.varname:
variables[L.varname] = result
- if debug_flag: print("variables=",variables)
+ if debug_flag: print("variables=", variables)
else:
print('Parse Failure')
- print(err.line)
- print(" "*(err.column-1) + "^")
- print(err)
+ err_str, err_line, err_col = L[-1]
+ print(err_line)
+ print(" "*(err_col-1) + "^")
+ print(err_str)
# obtain new input string
input_string = input("> ")
diff --git a/examples/fourFn.py b/examples/fourFn.py index 75f3909..f485f53 100644 --- a/examples/fourFn.py +++ b/examples/fourFn.py @@ -116,7 +116,7 @@ if __name__ == "__main__": try:
results = BNF().parseString( s, parseAll=True )
val = evaluateStack( exprStack[:] )
- except ParseException as e:
+ except ParseException as pe:
print(s, "failed parse:", str(pe))
except Exception as e:
print(s, "failed eval:", str(e))
|