Commits

Olemis Lang committed 5130d9e

GViz QL : Labels for computed columns. Tests rewritten ... [ok]

Comments (0)

Files changed (2)

trac-dev/gviz/tracgviz/gvizql.py

             (r'(?=date\s)', Whitespace, 'date'),
             (r'(?=timeofday\s)', Whitespace, 'tod'),
             (r'(?=(?:datetime|timestamp)\s)', Whitespace, 'dt'),
-            (r'`(?:\w|\s)+`', Name.Variable),
+            (r'`(?:[^`])+`', Name.Variable),
             (r'`.*`', Generic.Error),
             (r'`[^`]*(?=$)', Generic.Error),
             (r'\d*\.\d+(?=[^a-zA-Z_])', Number),
     return orderdef
 
   def handle_lblexpr(self, colnm, label):
-    return (str(colnm[1]), literal_eval(label[1]))
+    colnm = colnm[1]
+    if colnm.startswith('`'):
+      colnm = colnm[1:-1]
+    return (str(colnm), literal_eval(label[1]))
 
   def handle_lblseq(self, labels, _, label_expr):
     labels = labels[1]

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

          seniorityStartTime = 2007-12-30 14:40:00
       """,
   'Parsing LABEL (complex)' : r"""
-      >>> parse("select    max(salary) label max(salary) 'Better paid'", 
+      >>> parse("select    max(salary) label `max(salary)` 'Better paid'",
       ...       'cols', 'labels')
       ...
       *****
       Token.Name.Variable salary
       Token.Punctuation )
       Token.Keyword.Reserved label
-      Token.Name.Builtin max
-      Token.Punctuation (
-      Token.Name.Variable salary
-      Token.Punctuation )
+      Token.Name.Variable `max(salary)`
       Token.Literal.String.Single 'Better paid'
       *****
       * Parsing
       * Result
       *****
       = Columns =
-      max(salary) number
+      max(salary) number Better paid
       <BLANKLINE>
       NotImplementedError  :  Feature not supported ... yet
 
       >>> parse(r'''select lower(name) + '@example.com', upper(dept) 
-      ...       label lower(name) + '@example.com' 'E-mail', 
-      ...       upper(dept) "DEPT" ''',
+      ...       label `lower(name) + '@example.com'` 'E-mail', 
+      ...       `upper(dept)` "DEPT" ''',
       ...       'cols', 'labels')
       ...
       *****
       Token.Name.Variable dept
       Token.Punctuation )
       Token.Keyword.Reserved label
-      Token.Name.Function lower
-      Token.Punctuation (
-      Token.Name.Variable name
-      Token.Punctuation )
-      Token.Operator.Arithmetic +
-      Token.Literal.String.Single '@example.com'
+      Token.Name.Variable `lower(name) + '@example.com'`
       Token.Literal.String.Single 'E-mail'
       Token.Punctuation ,
-      Token.Name.Function upper
-      Token.Punctuation (
-      Token.Name.Variable dept
-      Token.Punctuation )
+      Token.Name.Variable `upper(dept)`
       Token.Literal.String.Double "DEPT"
       *****
       * Parsing
       * Result
       *****
       = Columns =
-      lower(name) + '@example.com' number
-      upper(dept) string
+      lower(name) + '@example.com' number E-mail
+      upper(dept) string DEPT
       = Row =
          lower(name) + '@example.com' = john@example.com
          upper(dept) = ENG