summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-06-18 13:04:27 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-06-18 13:04:27 +0000
commit4894cef022ca888d5b7962fcc99f996bdd0e6224 (patch)
tree5704e9532759531cffce7c26b7a85469027423c7
parent191c56031a16a6a7910613fa2be77a670d225996 (diff)
downloadpyparsing-4894cef022ca888d5b7962fcc99f996bdd0e6224.tar.gz
Fixed bug in pyparsing_common.numeric, integers were parsed as floats
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@371 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES5
-rw-r--r--src/pyparsing.py6
-rw-r--r--src/unitTests.py12
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):