fix parsing of negative float (closes #63421)
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 18 May 2011 15:27:47 +0200
changeset 626 56dbd4ec5137
parent 625 a57413372525
child 627 baf0543aa7d3
fix parsing of negative float (closes #63421)
ChangeLog
parser.g
parser.py
test/unittest_parser.py
--- a/ChangeLog	Wed May 18 15:20:48 2011 +0200
+++ b/ChangeLog	Wed May 18 15:27:47 2011 +0200
@@ -6,6 +6,7 @@
 * support for CAST function
 * support for regexp-based pattern matching using a REGEXP operator
 * may now GROUPBY functions / column number
+* fix parsing of negative float
 
 2011-01-12  --  0.28.0
     * enhance rewrite_shared_optional so one can specify where the new identity
--- a/parser.g	Wed May 18 15:20:48 2011 +0200
+++ b/parser.g	Wed May 18 15:27:47 2011 +0200
@@ -99,7 +99,7 @@
     token QMARK:       r'\?'
 
     token STRING:      r"'([^\'\\]|\\.)*'|\"([^\\\"\\]|\\.)*\""
-    token FLOAT:       r'\d+\.\d*'
+    token FLOAT:       r'-?\d+\.\d*'
     token INT:         r'-?\d+'
     token SUBSTITUTE:  r'%\([A-Za-z_0-9]+\)s'
 
--- a/parser.py	Wed May 18 15:20:48 2011 +0200
+++ b/parser.py	Wed May 18 15:27:47 2011 +0200
@@ -105,7 +105,7 @@
         ('COLALIAS', re.compile('[A-Z][A-Z0-9_]*\\.\\d+')),
         ('QMARK', re.compile('\\?')),
         ('STRING', re.compile('\'([^\\\'\\\\]|\\\\.)*\'|\\"([^\\\\\\"\\\\]|\\\\.)*\\"')),
-        ('FLOAT', re.compile('\\d+\\.\\d*')),
+        ('FLOAT', re.compile('-?\\d+\\.\\d*')),
         ('INT', re.compile('-?\\d+')),
         ('SUBSTITUTE', re.compile('%\\([A-Za-z_0-9]+\\)s')),
     ]
@@ -701,7 +701,7 @@
     P = Hercule(HerculeScanner(text))
     return runtime.wrap_error_reporter(P, rule)
 
-if __name__ == '__main__':
+if __name__ == 'old__main__':
     from sys import argv, stdin
     if len(argv) >= 2:
         if len(argv) >= 3:
@@ -710,3 +710,4 @@
             f = stdin
         print parse(argv[1], f.read())
     else: print >>sys.stderr, 'Args:  <rule> [<filename>]'
+# End -- grammar generated by Yapps
--- a/test/unittest_parser.py	Wed May 18 15:20:48 2011 +0200
+++ b/test/unittest_parser.py	Wed May 18 15:27:47 2011 +0200
@@ -157,6 +157,7 @@
     'Any YEAR(XD),COUNT(X) GROUPBY YEAR(XD) ORDERBY YEAR(XD) WHERE X date XD;',
     'Any YEAR(XD),COUNT(X) GROUPBY 1 ORDERBY 1 WHERE X date XD;',
 
+    'Any -1.0;',
     )
 
 class ParserHercule(TestCase):