summaryrefslogtreecommitdiff
path: root/examples/SimpleCalc.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2018-10-30 17:13:40 -0500
committerptmcg <ptmcg@austin.rr.com>2018-10-30 17:13:40 -0500
commite308005e9645303487451909d00079187edf09e6 (patch)
tree34cebb32ebac8eebe6b5655f0a3d5ef2eb551e99 /examples/SimpleCalc.py
parent41bb3b91e2f1e552fc1afa2373e21028035471aa (diff)
downloadpyparsing-git-e308005e9645303487451909d00079187edf09e6.tar.gz
Fix Issue #40 - Py3 enforces tighter exception scoping, plus other exception typo
Diffstat (limited to 'examples/SimpleCalc.py')
-rw-r--r--examples/SimpleCalc.py17
1 files changed, 9 insertions, 8 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("> ")