diff options
-rw-r--r-- | src/CHANGES | 5 | ||||
-rw-r--r-- | src/pyparsing.py | 6 | ||||
-rw-r--r-- | src/unitTests.py | 12 |
3 files changed, 20 insertions, 3 deletions
diff --git a/src/CHANGES b/src/CHANGES index 799cdf8..9ab77a2 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -2,6 +2,11 @@ Change Log
==========
+Version 2.1.6 -
+------------------------------
+- Fixed bug in pyparsing_common.numeric, integers were parsed as floats.
+
+
Verison 2.1.5 - June, 2016
------------------------------
- Added ParserElement.split() generator method, similar to re.split().
diff --git a/src/pyparsing.py b/src/pyparsing.py index ec678d0..163dc8b 100644 --- a/src/pyparsing.py +++ b/src/pyparsing.py @@ -57,8 +57,8 @@ The pyparsing module handles some of the problems that are typically vexing when - embedded comments
"""
-__version__ = "2.1.5"
-__versionTime__ = "13 Jun 2016 19:59 UTC"
+__version__ = "2.1.6"
+__versionTime__ = "18 Jun 2016 12:49 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -3988,7 +3988,7 @@ class pyparsing_common: signedInteger = Regex(r'[+-]?\d+').setName("signed integer").setParseAction(convertToInteger)
"""expression that parses an integer with optional leading sign, returns an int"""
- fraction = (signedInteger.addParseAction(convertToFloat) + '/' + signedInteger.addParseAction(convertToFloat)).setName("fraction")
+ fraction = (signedInteger().setParseAction(convertToFloat) + '/' + signedInteger().setParseAction(convertToFloat)).setName("fraction")
"""fractional expression of an integer divided by an integer, returns a float"""
fraction.addParseAction(lambda t: t[0]/t[-1])
diff --git a/src/unitTests.py b/src/unitTests.py index 90cbc2a..0de3b97 100644 --- a/src/unitTests.py +++ b/src/unitTests.py @@ -2777,6 +2777,18 @@ class CommonExpressionsTest(ParseTestCase): """)[0]
assert success, "failed to parse valid mixed integer"
+ success, results = pyparsing_common.numeric.runTests("""
+ 100
+ -3
+ 1.732
+ -3.14159
+ 6.02e23""")
+ assert success, "failed to parse numerics"
+ for test,result in results:
+ expected = eval(test)
+ assert result[0] == expected, "numeric parse failed (wrong value) (%s should be %s)" % (result[0], expected)
+ assert type(result[0]) == type(expected), "numeric parse failed (wrong type) (%s should be %s)" % (type(result[0]), type(expected))
+
class TokenMapTest(ParseTestCase):
def runTest(self):
|