Commits

Olemis Lang committed 08f72c7

GViz QL [ refs dataviz-302 ] : Multiple columns and whitespaces in OPTION format_syntax ... ok

Comments (0)

Files changed (2)

trac-dev/gviz/tracgviz/gvizql.py

     self.no_values = self.no_format = False
     self.format_syntax = {}
 
-  RE_OPTION_FORMAT_SYNTAX = compile('(?:([^`,][^:`,]*?)|(?:`([^`]+)`))'
-                                    ':([^,]+?)(?:,|$)')
+  RE_OPTION_FORMAT_SYNTAX = compile(r'(?:([^`,][^:`,]*)|(?:`([^`]+)`\s*))'
+                                    ':([^,]+)(?:,|$)')
 
   def configure(self, options):
     r"""Store formatting options

trac-dev/gviz/tracgviz/testing/test_gvizql.py

          dayOfWeek(hireDate) = (2, 'Mon')
 
 
+      >>> parse("select name, age, isSenior, dayOfWeek(hireDate) "
+      ...       "format age 'SPELLOUT',"
+      ...       "`dayOfWeek(hireDate)` 'Error;Sun;Mon;Tue;Wed;Thu;Fri;Sat;Error'"
+      ...       " options format_syntax:'`dayOfWeek(hireDate)` : NumberRule , age : PredefinedNumberRule'",
+      ...       'opts', 'cols', 'fmt')
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved select
+      Token.Name.Variable name
+      Token.Punctuation ,
+      Token.Name.Variable age
+      Token.Punctuation ,
+      Token.Name.Variable isSenior
+      Token.Punctuation ,
+      Token.Name.Function dayOfWeek
+      Token.Punctuation (
+      Token.Name.Variable hireDate
+      Token.Punctuation )
+      Token.Keyword.Reserved format
+      Token.Name.Variable age
+      Token.Literal.String.Single 'SPELLOUT'
+      Token.Punctuation ,
+      Token.Name.Variable `dayOfWeek(hireDate)`
+      Token.Literal.String.Single 'Error;Sun;Mon;Tue;Wed;Thu;Fri;Sat;Error'
+      Token.Keyword.Reserved options
+      Token.Name.Variable format_syntax
+      Token.Punctuation :
+      Token.Literal.String.Single '`dayOfWeek(hireDate)` : NumberRule , age : PredefinedNumberRule'
+      *****
+      * Parsing
+      *****
+      [(u'format_syntax', '`dayOfWeek(hireDate)` : NumberRule , age : PredefinedNumberRule')]
+      ['name', 'age', 'isSenior', 'dayOfWeek(hireDate)']
+      [('age', 'SPELLOUT'), ('dayOfWeek(hireDate)', 'Error;Sun;Mon;Tue;Wed;Thu;Fri;Sat;Error')]
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      age number
+      isSenior boolean
+      dayOfWeek(hireDate) number
+      = Row =
+         name = John
+         age = (35, 'thirty-five')
+         isSenior = True
+         dayOfWeek(hireDate) = (7, 'Sat')
+      = Row =
+         name = Dave
+         age = (27, 'twenty-seven')
+         isSenior = False
+         dayOfWeek(hireDate) = (4, 'Wed')
+      = Row =
+         name = Sally
+         age = (30, 'thirty')
+         isSenior = False
+         dayOfWeek(hireDate) = (2, 'Mon')
+      = Row =
+         name = Ben
+         age = (32, 'thirty-two')
+         isSenior = True
+         dayOfWeek(hireDate) = (5, 'Thu')
+      = Row =
+         name = Dana
+         age = (25, 'twenty-five')
+         isSenior = False
+         dayOfWeek(hireDate) = (4, 'Wed')
+      = Row =
+         name = Mike
+         age = (24, 'twenty-four')
+         isSenior = True
+         dayOfWeek(hireDate) = (2, 'Mon')
+
       """,
   'Parsing OPTIONS errors' : r"""
       >>> parse("select * options no_values, format_syntax:'salary:PredefinedNumberRule,:,' "