瀏覽代碼

Fixed Trac #558: properly parse strings containing hexadecimal sequences (i.e. 'QWERTY0xCUIOP').
Note that for now hexadecimal numbers are parsed but not interpreted properly...

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2103 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 13 年之前
父節點
當前提交
ab955c87c5
共有 2 個文件被更改,包括 18 次插入2 次删除
  1. 1 1
      core/oql/oql-lexer.php
  2. 17 1
      core/oql/oql-lexer.plex

+ 1 - 1
core/oql/oql-lexer.php

@@ -168,7 +168,7 @@ class OQLLexerRaw
                 '/\GABOVE STRICT/ ',
                 '/\GNOT ABOVE/ ',
                 '/\GNOT ABOVE STRICT/ ',
-                '/\G[0-9]+|0x[0-9a-fA-F]+/ ',
+                '/\G(0x[0-9a-fA-F]+|[0-9]+)/ ',
                 '/\G\"([^\\\\\"]|\\\\\"|\\\\\\\\)*\"|'.chr(94).chr(39).'([^\\\\'.chr(39).']|\\\\'.chr(39).'|\\\\\\\\)*'.chr(39).'/ ',
                 '/\G([_a-zA-Z][_a-zA-Z0-9]*|`[^`]+`)/ ',
                 '/\G:([_a-zA-Z][_a-zA-Z0-9]*->[_a-zA-Z][_a-zA-Z0-9]*|[_a-zA-Z][_a-zA-Z0-9]*)/ ',

+ 17 - 1
core/oql/oql-lexer.plex

@@ -140,7 +140,23 @@ above            = "ABOVE"
 above_strict     = "ABOVE STRICT"
 not_above        = "NOT ABOVE"
 not_above_strict = "NOT ABOVE STRICT"
-numval     = /[0-9]+|0x[0-9a-fA-F]+/
+//
+// WARNING: there seems to be a bug in the Lexer about matching the longest pattern
+//          when there are alternates in the regexp.
+//
+// For instance:
+// numval     = /[0-9]+|0x[0-9a-fA-F]+/
+// Does not work: SELECT Toto WHERE name = 'Text0xCTest' => Fails because 0xC is recongnized as a numval (inside the string) instead of a strval !!
+//
+// Inserting a ^ after the alternate (see comment at the top of this file) does not work either
+// numval     = /[0-9]+|'.chr(94).'0x[0-9a-fA-F]+/
+// SELECT Toto WHERE name = 'Text0xCTest' => works but
+// SELECT Toto WHERE id = 0xC => does not work, 'xC' is found as a name (apparently 0 is recognized as a numval and the remaining is a name !)
+//
+// numval     = /([0-9]+|0x[0-9a-fA-F]+)/
+// Does not work either, the hexadecimal numbers are not matched properly
+// The following seems to work...
+numval     = /(0x[0-9a-fA-F]+|[0-9]+)/
 strval     = /"([^\\"]|\\"|\\\\)*"|'.chr(94).chr(39).'([^\\'.chr(39).']|\\'.chr(39).'|\\\\)*'.chr(39).'/
 name       = /([_a-zA-Z][_a-zA-Z0-9]*|`[^`]+`)/
 varname    = /:([_a-zA-Z][_a-zA-Z0-9]*->[_a-zA-Z][_a-zA-Z0-9]*|[_a-zA-Z][_a-zA-Z0-9]*)/