Commits

Olemis Lang committed 2a7eab0

GViz QL: Greedy production matching approach. GViz QL grammar precedence + lookup

Comments (0)

Files changed (3)

trac-dev/gviz/tracgviz/grammar.py

 """
 __author__ = 'Olemis Lang'
 
-__all__ = '', ''
+__all__ = 'GVIZ_GRAMMAR_PRECEDENCE', 'GVIZ_GRAMMAR_PRODUCTIONS'
 
 from pygments.token import *
 
-from tracgviz.util.parsing import Any, EndMarker, gen_precedence, NonTerminal, \
+from tracgviz.util.parsing import Any, EndMarker, NonTerminal, \
     OperatorPrecedenceParser as Parser
 
 # Grammar
 
 GVIZ_QL_START_STATE = 'GVIZ_SQL'
 
-def gen_gvizql_grammar():
-  GVIZ_QL_SYMBOLS = [ 
+def gvizql_grammar():
+  GVIZ_QL_TERMINALS = [ 
       (Operator.Word.Boolean, 'and'), 
       (Operator.Word.Boolean, 'or'), 
       (Operator.Word.Boolean, 'not'), 
     'LABEL_EXPR', 'VALUE', 'ARITHMETIC_EXPR', 'TERM', 'FACTOR', 'SIMPLE_EXPR', \
     'BOOL_VALUE', 'BOOL_EXPR', 'OR_EXPR' )]
 
-  GVIZ_PRODUCTIONS = [
+  GVIZ_QL_PRODUCTIONS = [
       # SQL clauses
       ('gvizql',  GVIZQL,     [ GVIZQL, (Whitespace, Any), CLAUSE ] ),
       ('',        GVIZQL,     [ CLAUSE ] ),
       ('',        BOOL_EXPR,  [ OR_EXPR ] ),
       ('orexp',   OR_EXPR,    [ OR_EXPR, _Or, BOOL_VALUE ] ),
       ('',        OR_EXPR,    [ BOOL_VALUE ] ),
-      ('not',     BOOL_VALUE, [ _Not BOOL_VALUE ] ),
+      ('not',     BOOL_VALUE, [ _Not, BOOL_VALUE ] ),
       ('cmp',     BOOL_VALUE, [ ARITHMETIC_EXPR, _BoolOp, ARITHMETIC_EXPR ] ),
       ('strcmp',  BOOL_VALUE, [ ARITHMETIC_EXPR, _BoolWordOp, ARITHMETIC_EXPR ] ),
 
       ('',        SIMPLE_EXPR,      [ VALUE ] ),
 
       # Function calls
-      ('bfunc',     VALUE, [ _Builtin, OpenP, CloseP ] ),
-      ('func',      VALUE, [ _Function, OpenP, CloseP ] ),
-      ('bfuncargs', VALUE, [ _Builtin, OpenP, SEQ, CloseP ] ),
-      ('funcargs',  VALUE, [ _Function, OpenP, SEQ, CloseP ] ),
+      ('bfunc',     VALUE, [ _Builtin, _OpenP, _CloseP ] ),
+      ('func',      VALUE, [ _Function, _OpenP, _CloseP ] ),
+      ('bfuncargs', VALUE, [ _Builtin, _OpenP, SEQ, _CloseP ] ),
+      ('funcargs',  VALUE, [ _Function, _OpenP, SEQ, _CloseP ] ),
       ('seq',       SEQ, [ SEQ, _Comma, ARITHMETIC_EXPR ] ),
       ('',          SEQ, [ ARITHMETIC_EXPR ] ),
 
       ('str',       VALUE, [ _Str ] ),
       ('date',      VALUE, [ _Date ] ),
       ('const',     VALUE, [ _Const ] ),
-    ],
+    ]
+  return GVIZ_QL_PRODUCTIONS
 
-  #  1.   VALUE -> Number
-  #  2.   VALUE -> Variable
-  #  3.   VALUE -> String
-  #  4.   VALUE -> Date
-  #  5.   VALUE -> Constant
-  #  6.   VALUE -> Builtin ( )
-  #  7.   VALUE -> Builtin ( SUITE )
-  #  8.   VALUE -> Function ( )
-  #  9.   VALUE -> Function ( SUITE )
-  #  10.  SUITE -> SUITE , ARITMETIC_EXPR
-  #  10a. SUITE -> ARITMETIC_EXPR
-  #  13.  ARITMETIC_EXPR -> ARITMETIC_EXPR + TERM
-  #  14.  ARITMETIC_EXPR -> ARITMETIC_EXPR - TERM
-  #  14a. ARITMETIC_EXPR -> TERM
-  #  15.  TERM -> TERM * FACTOR
-  #  15.a TERM -> FACTOR
-  #  16.  FACTOR -> FACTOR / SIMPLE_EXPR
-  #  16a. FACTOR -> SIMPLE_EXPR
-  #  17.  SIMPLE_EXPR -> ( ARITHMETIC_EXPR )
-  #  17a. SIMPLE_EXPR -> VALUE
-  #  18.  BOOL_VALUE -> ARITHMETIC_EXPR Operator.Comparison ARITHMETIC_EXPR
-  #  19.  BOOL_VALUE -> ARITHMETIC_EXPR Operator.Word.Comparison ARITHMETIC_EXPR
-  #  20.  BOOL_VALUE -> not BOOL_VALUE
-  #  21.  BOOL_EXPR -> BOOL_EXPR and OR_EXPR
-  #  21a. BOOL_EXPR -> OR_EXPR
-  #  22.  OR_EXPR -> OR_EXPR or BOOL_VALUE
-  #  22a. OR_EXPR -> BOOL_VALUE
+# Generated precedence and productions lookup tree
+# These are made available to improve performance because of the fact that
+# no production processing is needed , they are ready to use 
 
 GVIZ_GRAMMAR_PRECEDENCE = {
-    CloseP : {
-        Parser.MorePrecedence : [Multiply, Add, CloseP, EndE],
-      },
-    Var : {
-        Parser.MorePrecedence : [Multiply, Add, CloseP, EndE],
-      },
-    Multiply : {
-        Parser.MorePrecedence : [Multiply, Add, CloseP, EndE],
-        Parser.LessPrecedence : [OpenP, Var],
-      },
-    Add : {
-        Parser.MorePrecedence : [Add, CloseP, EndE],
-        Parser.LessPrecedence : [Multiply, OpenP, Var],
-      },
-    OpenP : {
-        Parser.LessPrecedence : [OpenP, Var, Multiply, Add,],
-        Parser.SamePrecedence : [CloseP, ],
-      },
-    EndE : {
-        Parser.LessPrecedence : [OpenP, Var, Multiply, Add,],
-      },
-  }
-
-GVIZ_GRAMMAR_PRECEDENCE = gen_precedence(GVIZ_GRAMMAR_PRECEDENCE) 
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Date): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Number): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Str): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Builtin): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Const): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Function): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Var): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Mult): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Plus): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Minus): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _Div): LessPrecedence,
+ ((EndMarker, 'ARITHMETIC_EXPR'), _OpenP): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Date): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Number): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Str): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Builtin): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Const): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Function): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Var): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Mult): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Plus): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Minus): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Div): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _BoolOp): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _And): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Not): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _Or): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _BoolWordOp): LessPrecedence,
+ ((EndMarker, 'BOOL_EXPR'), _OpenP): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Date): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Number): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Str): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Builtin): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Const): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Function): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Var): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Mult): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Plus): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Minus): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Div): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _BoolOp): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _Not): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _BoolWordOp): LessPrecedence,
+ ((EndMarker, 'BOOL_VALUE'), _OpenP): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Format): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _GroupBy): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Label): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Limit): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Offset): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Options): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _OrderBy): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Pivot): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Select): LessPrecedence,
+ ((EndMarker, 'CLAUSE'), _Where): LessPrecedence,
+ ((EndMarker, 'COLSEQ'), _Var): LessPrecedence,
+ ((EndMarker, 'COLSEQ'), _Comma): LessPrecedence,
+ ((EndMarker, 'COLUMN'), _Var): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Date): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Number): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Str): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Builtin): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Const): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Function): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Var): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _Div): LessPrecedence,
+ ((EndMarker, 'FACTOR'), _OpenP): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Format): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _GroupBy): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Label): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Limit): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Offset): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Options): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _OrderBy): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Pivot): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Select): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), _Where): LessPrecedence,
+ ((EndMarker, 'GVIZQL'), (Token.Text.Whitespace, Any)): LessPrecedence,
+ ((EndMarker, 'LABELSEQ'), _Var): LessPrecedence,
+ ((EndMarker, 'LABELSEQ'), _Comma): LessPrecedence,
+ ((EndMarker, 'LABEL_EXPR'), _Var): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Date): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Number): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Str): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Builtin): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Const): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Function): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Var): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Mult): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Plus): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Minus): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Div): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _BoolOp): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Not): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _Or): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _BoolWordOp): LessPrecedence,
+ ((EndMarker, 'OR_EXPR'), _OpenP): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Date): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Number): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Str): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Builtin): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Const): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Function): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Var): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Mult): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Plus): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Minus): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Div): LessPrecedence,
+ ((EndMarker, 'SEQ'), _OpenP): LessPrecedence,
+ ((EndMarker, 'SEQ'), _Comma): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Date): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Number): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Str): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Builtin): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Const): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Function): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _Var): LessPrecedence,
+ ((EndMarker, 'SIMPLE_EXPR'), _OpenP): LessPrecedence,
+ ((EndMarker, 'TERM'), _Date): LessPrecedence,
+ ((EndMarker, 'TERM'), _Number): LessPrecedence,
+ ((EndMarker, 'TERM'), _Str): LessPrecedence,
+ ((EndMarker, 'TERM'), _Builtin): LessPrecedence,
+ ((EndMarker, 'TERM'), _Const): LessPrecedence,
+ ((EndMarker, 'TERM'), _Function): LessPrecedence,
+ ((EndMarker, 'TERM'), _Var): LessPrecedence,
+ ((EndMarker, 'TERM'), _Mult): LessPrecedence,
+ ((EndMarker, 'TERM'), _Div): LessPrecedence,
+ ((EndMarker, 'TERM'), _OpenP): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Date): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Number): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Str): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Builtin): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Const): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Function): LessPrecedence,
+ ((EndMarker, 'VALUE'), _Var): LessPrecedence,
+ (_Format, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Format, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Format, _Var): LessPrecedence,
+ (_Format, _Comma): LessPrecedence,
+ (_Format, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_GroupBy, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_GroupBy, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_GroupBy, _Var): LessPrecedence,
+ (_GroupBy, _Comma): LessPrecedence,
+ (_GroupBy, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Label, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Label, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Label, _Var): LessPrecedence,
+ (_Label, _Comma): LessPrecedence,
+ (_Label, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Limit, _Number): SamePrecedence,
+ (_Offset, _Number): SamePrecedence,
+ (_Options, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Options, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Options, _Var): LessPrecedence,
+ (_Options, _Comma): LessPrecedence,
+ (_Options, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_OrderBy, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_OrderBy, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_OrderBy, _Date): LessPrecedence,
+ (_OrderBy, _Number): LessPrecedence,
+ (_OrderBy, _Str): LessPrecedence,
+ (_OrderBy, _Builtin): LessPrecedence,
+ (_OrderBy, _Const): LessPrecedence,
+ (_OrderBy, _Function): LessPrecedence,
+ (_OrderBy, _Var): LessPrecedence,
+ (_OrderBy, _Mult): LessPrecedence,
+ (_OrderBy, _Plus): LessPrecedence,
+ (_OrderBy, _Minus): LessPrecedence,
+ (_OrderBy, _Div): LessPrecedence,
+ (_OrderBy, _OpenP): LessPrecedence,
+ (_OrderBy, _Comma): LessPrecedence,
+ (_OrderBy, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Pivot, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Pivot, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Pivot, _Var): LessPrecedence,
+ (_Pivot, _Comma): LessPrecedence,
+ (_Pivot, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Select, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Select, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Select, _Date): LessPrecedence,
+ (_Select, _Number): LessPrecedence,
+ (_Select, _Str): LessPrecedence,
+ (_Select, _Builtin): LessPrecedence,
+ (_Select, _Const): LessPrecedence,
+ (_Select, _Function): LessPrecedence,
+ (_Select, _Var): LessPrecedence,
+ (_Select, _Mult): LessPrecedence,
+ (_Select, _Plus): LessPrecedence,
+ (_Select, _Minus): LessPrecedence,
+ (_Select, _Div): LessPrecedence,
+ (_Select, _OpenP): LessPrecedence,
+ (_Select, _Comma): LessPrecedence,
+ (_Select, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Where, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Where, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Where, _Date): LessPrecedence,
+ (_Where, _Number): LessPrecedence,
+ (_Where, _Str): LessPrecedence,
+ (_Where, _Builtin): LessPrecedence,
+ (_Where, _Const): LessPrecedence,
+ (_Where, _Function): LessPrecedence,
+ (_Where, _Var): LessPrecedence,
+ (_Where, _Mult): LessPrecedence,
+ (_Where, _Plus): LessPrecedence,
+ (_Where, _Minus): LessPrecedence,
+ (_Where, _Div): LessPrecedence,
+ (_Where, _BoolOp): LessPrecedence,
+ (_Where, _And): LessPrecedence,
+ (_Where, _Not): LessPrecedence,
+ (_Where, _Or): LessPrecedence,
+ (_Where, _BoolWordOp): LessPrecedence,
+ (_Where, _OpenP): LessPrecedence,
+ (_Where, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Date, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Date, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Date, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Date, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Date, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_Date, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Date, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Date, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Date, (EndMarker, 'SIMPLE_EXPR')): MorePrecedence,
+ (_Date, (EndMarker, 'TERM')): MorePrecedence,
+ (_Date, (EndMarker, 'VALUE')): MorePrecedence,
+ (_Date, _Mult): MorePrecedence,
+ (_Date, _Plus): MorePrecedence,
+ (_Date, _Minus): MorePrecedence,
+ (_Date, _Div): MorePrecedence,
+ (_Date, _BoolOp): MorePrecedence,
+ (_Date, _And): MorePrecedence,
+ (_Date, _Or): MorePrecedence,
+ (_Date, _BoolWordOp): MorePrecedence,
+ (_Date, _CloseP): MorePrecedence,
+ (_Date, _Comma): MorePrecedence,
+ (_Date, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Number, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Number, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Number, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Number, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Number, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_Number, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Number, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Number, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Number, (EndMarker, 'SIMPLE_EXPR')): MorePrecedence,
+ (_Number, (EndMarker, 'TERM')): MorePrecedence,
+ (_Number, (EndMarker, 'VALUE')): MorePrecedence,
+ (_Number, _Mult): MorePrecedence,
+ (_Number, _Plus): MorePrecedence,
+ (_Number, _Minus): MorePrecedence,
+ (_Number, _Div): MorePrecedence,
+ (_Number, _BoolOp): MorePrecedence,
+ (_Number, _And): MorePrecedence,
+ (_Number, _Or): MorePrecedence,
+ (_Number, _BoolWordOp): MorePrecedence,
+ (_Number, _CloseP): MorePrecedence,
+ (_Number, _Comma): MorePrecedence,
+ (_Number, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Str, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Str, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Str, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Str, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Str, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_Str, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Str, (EndMarker, 'LABELSEQ')): MorePrecedence,
+ (_Str, (EndMarker, 'LABEL_EXPR')): MorePrecedence,
+ (_Str, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Str, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Str, (EndMarker, 'SIMPLE_EXPR')): MorePrecedence,
+ (_Str, (EndMarker, 'TERM')): MorePrecedence,
+ (_Str, (EndMarker, 'VALUE')): MorePrecedence,
+ (_Str, _Mult): MorePrecedence,
+ (_Str, _Plus): MorePrecedence,
+ (_Str, _Minus): MorePrecedence,
+ (_Str, _Div): MorePrecedence,
+ (_Str, _BoolOp): MorePrecedence,
+ (_Str, _And): MorePrecedence,
+ (_Str, _Or): MorePrecedence,
+ (_Str, _BoolWordOp): MorePrecedence,
+ (_Str, _CloseP): MorePrecedence,
+ (_Str, _Comma): MorePrecedence,
+ (_Str, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Builtin, _OpenP): SamePrecedence,
+ (_Const, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Const, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Const, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Const, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Const, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_Const, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Const, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Const, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Const, (EndMarker, 'SIMPLE_EXPR')): MorePrecedence,
+ (_Const, (EndMarker, 'TERM')): MorePrecedence,
+ (_Const, (EndMarker, 'VALUE')): MorePrecedence,
+ (_Const, _Mult): MorePrecedence,
+ (_Const, _Plus): MorePrecedence,
+ (_Const, _Minus): MorePrecedence,
+ (_Const, _Div): MorePrecedence,
+ (_Const, _BoolOp): MorePrecedence,
+ (_Const, _And): MorePrecedence,
+ (_Const, _Or): MorePrecedence,
+ (_Const, _BoolWordOp): MorePrecedence,
+ (_Const, _CloseP): MorePrecedence,
+ (_Const, _Comma): MorePrecedence,
+ (_Const, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Function, _OpenP): SamePrecedence,
+ (_Var, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Var, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Var, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Var, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Var, (EndMarker, 'COLSEQ')): MorePrecedence,
+ (_Var, (EndMarker, 'COLUMN')): MorePrecedence,
+ (_Var, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_Var, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Var, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Var, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Var, (EndMarker, 'SIMPLE_EXPR')): MorePrecedence,
+ (_Var, (EndMarker, 'TERM')): MorePrecedence,
+ (_Var, (EndMarker, 'VALUE')): MorePrecedence,
+ (_Var, _Str): SamePrecedence,
+ (_Var, _Mult): MorePrecedence,
+ (_Var, _Plus): MorePrecedence,
+ (_Var, _Minus): MorePrecedence,
+ (_Var, _Div): MorePrecedence,
+ (_Var, _BoolOp): MorePrecedence,
+ (_Var, _And): MorePrecedence,
+ (_Var, _Or): MorePrecedence,
+ (_Var, _BoolWordOp): MorePrecedence,
+ (_Var, _CloseP): MorePrecedence,
+ (_Var, _Comma): MorePrecedence,
+ (_Var, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Mult, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Mult, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Mult, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Mult, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Mult, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Mult, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Mult, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Mult, (EndMarker, 'TERM')): MorePrecedence,
+ (_Mult, _Date): LessPrecedence,
+ (_Mult, _Number): LessPrecedence,
+ (_Mult, _Str): LessPrecedence,
+ (_Mult, _Builtin): LessPrecedence,
+ (_Mult, _Const): LessPrecedence,
+ (_Mult, _Function): LessPrecedence,
+ (_Mult, _Var): LessPrecedence,
+ (_Mult, _Mult): MorePrecedence,
+ (_Mult, _Plus): MorePrecedence,
+ (_Mult, _Minus): MorePrecedence,
+ (_Mult, _Div): LessPrecedence,
+ (_Mult, _BoolOp): MorePrecedence,
+ (_Mult, _And): MorePrecedence,
+ (_Mult, _Or): MorePrecedence,
+ (_Mult, _BoolWordOp): MorePrecedence,
+ (_Mult, _OpenP): LessPrecedence,
+ (_Mult, _CloseP): MorePrecedence,
+ (_Mult, _Comma): MorePrecedence,
+ (_Mult, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Plus, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Plus, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Plus, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Plus, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Plus, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Plus, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Plus, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Plus, _Date): LessPrecedence,
+ (_Plus, _Number): LessPrecedence,
+ (_Plus, _Str): LessPrecedence,
+ (_Plus, _Builtin): LessPrecedence,
+ (_Plus, _Const): LessPrecedence,
+ (_Plus, _Function): LessPrecedence,
+ (_Plus, _Var): LessPrecedence,
+ (_Plus, _Mult): LessPrecedence,
+ (_Plus, _Plus): MorePrecedence,
+ (_Plus, _Minus): MorePrecedence,
+ (_Plus, _Div): LessPrecedence,
+ (_Plus, _BoolOp): MorePrecedence,
+ (_Plus, _And): MorePrecedence,
+ (_Plus, _Or): MorePrecedence,
+ (_Plus, _BoolWordOp): MorePrecedence,
+ (_Plus, _OpenP): LessPrecedence,
+ (_Plus, _CloseP): MorePrecedence,
+ (_Plus, _Comma): MorePrecedence,
+ (_Plus, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Minus, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Minus, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Minus, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Minus, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Minus, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Minus, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Minus, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Minus, _Date): LessPrecedence,
+ (_Minus, _Number): LessPrecedence,
+ (_Minus, _Str): LessPrecedence,
+ (_Minus, _Builtin): LessPrecedence,
+ (_Minus, _Const): LessPrecedence,
+ (_Minus, _Function): LessPrecedence,
+ (_Minus, _Var): LessPrecedence,
+ (_Minus, _Mult): LessPrecedence,
+ (_Minus, _Plus): MorePrecedence,
+ (_Minus, _Minus): MorePrecedence,
+ (_Minus, _Div): LessPrecedence,
+ (_Minus, _BoolOp): MorePrecedence,
+ (_Minus, _And): MorePrecedence,
+ (_Minus, _Or): MorePrecedence,
+ (_Minus, _BoolWordOp): MorePrecedence,
+ (_Minus, _OpenP): LessPrecedence,
+ (_Minus, _CloseP): MorePrecedence,
+ (_Minus, _Comma): MorePrecedence,
+ (_Minus, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Div, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_Div, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Div, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Div, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Div, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_Div, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Div, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Div, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Div, (EndMarker, 'TERM')): MorePrecedence,
+ (_Div, _Date): LessPrecedence,
+ (_Div, _Number): LessPrecedence,
+ (_Div, _Str): LessPrecedence,
+ (_Div, _Builtin): LessPrecedence,
+ (_Div, _Const): LessPrecedence,
+ (_Div, _Function): LessPrecedence,
+ (_Div, _Var): LessPrecedence,
+ (_Div, _Mult): MorePrecedence,
+ (_Div, _Plus): MorePrecedence,
+ (_Div, _Minus): MorePrecedence,
+ (_Div, _Div): MorePrecedence,
+ (_Div, _BoolOp): MorePrecedence,
+ (_Div, _And): MorePrecedence,
+ (_Div, _Or): MorePrecedence,
+ (_Div, _BoolWordOp): MorePrecedence,
+ (_Div, _OpenP): LessPrecedence,
+ (_Div, _CloseP): MorePrecedence,
+ (_Div, _Comma): MorePrecedence,
+ (_Div, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_BoolOp, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_BoolOp, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_BoolOp, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_BoolOp, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_BoolOp, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_BoolOp, _Date): LessPrecedence,
+ (_BoolOp, _Number): LessPrecedence,
+ (_BoolOp, _Str): LessPrecedence,
+ (_BoolOp, _Builtin): LessPrecedence,
+ (_BoolOp, _Const): LessPrecedence,
+ (_BoolOp, _Function): LessPrecedence,
+ (_BoolOp, _Var): LessPrecedence,
+ (_BoolOp, _Mult): LessPrecedence,
+ (_BoolOp, _Plus): LessPrecedence,
+ (_BoolOp, _Minus): LessPrecedence,
+ (_BoolOp, _Div): LessPrecedence,
+ (_BoolOp, _And): MorePrecedence,
+ (_BoolOp, _Or): MorePrecedence,
+ (_BoolOp, _OpenP): LessPrecedence,
+ (_BoolOp, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_And, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_And, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_And, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_And, _Date): LessPrecedence,
+ (_And, _Number): LessPrecedence,
+ (_And, _Str): LessPrecedence,
+ (_And, _Builtin): LessPrecedence,
+ (_And, _Const): LessPrecedence,
+ (_And, _Function): LessPrecedence,
+ (_And, _Var): LessPrecedence,
+ (_And, _Mult): LessPrecedence,
+ (_And, _Plus): LessPrecedence,
+ (_And, _Minus): LessPrecedence,
+ (_And, _Div): LessPrecedence,
+ (_And, _BoolOp): LessPrecedence,
+ (_And, _And): MorePrecedence,
+ (_And, _Not): LessPrecedence,
+ (_And, _Or): LessPrecedence,
+ (_And, _BoolWordOp): LessPrecedence,
+ (_And, _OpenP): LessPrecedence,
+ (_And, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Not, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Not, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_Not, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Not, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Not, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Not, _Date): LessPrecedence,
+ (_Not, _Number): LessPrecedence,
+ (_Not, _Str): LessPrecedence,
+ (_Not, _Builtin): LessPrecedence,
+ (_Not, _Const): LessPrecedence,
+ (_Not, _Function): LessPrecedence,
+ (_Not, _Var): LessPrecedence,
+ (_Not, _Mult): LessPrecedence,
+ (_Not, _Plus): LessPrecedence,
+ (_Not, _Minus): LessPrecedence,
+ (_Not, _Div): LessPrecedence,
+ (_Not, _BoolOp): LessPrecedence,
+ (_Not, _And): MorePrecedence,
+ (_Not, _Not): LessPrecedence,
+ (_Not, _Or): MorePrecedence,
+ (_Not, _BoolWordOp): LessPrecedence,
+ (_Not, _OpenP): LessPrecedence,
+ (_Not, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Or, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_Or, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Or, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Or, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_Or, _Date): LessPrecedence,
+ (_Or, _Number): LessPrecedence,
+ (_Or, _Str): LessPrecedence,
+ (_Or, _Builtin): LessPrecedence,
+ (_Or, _Const): LessPrecedence,
+ (_Or, _Function): LessPrecedence,
+ (_Or, _Var): LessPrecedence,
+ (_Or, _Mult): LessPrecedence,
+ (_Or, _Plus): LessPrecedence,
+ (_Or, _Minus): LessPrecedence,
+ (_Or, _Div): LessPrecedence,
+ (_Or, _BoolOp): LessPrecedence,
+ (_Or, _And): MorePrecedence,
+ (_Or, _Not): LessPrecedence,
+ (_Or, _Or): MorePrecedence,
+ (_Or, _BoolWordOp): LessPrecedence,
+ (_Or, _OpenP): LessPrecedence,
+ (_Or, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_BoolWordOp, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_BoolWordOp, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_BoolWordOp, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_BoolWordOp, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_BoolWordOp, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_BoolWordOp, _Date): LessPrecedence,
+ (_BoolWordOp, _Number): LessPrecedence,
+ (_BoolWordOp, _Str): LessPrecedence,
+ (_BoolWordOp, _Builtin): LessPrecedence,
+ (_BoolWordOp, _Const): LessPrecedence,
+ (_BoolWordOp, _Function): LessPrecedence,
+ (_BoolWordOp, _Var): LessPrecedence,
+ (_BoolWordOp, _Mult): LessPrecedence,
+ (_BoolWordOp, _Plus): LessPrecedence,
+ (_BoolWordOp, _Minus): LessPrecedence,
+ (_BoolWordOp, _Div): LessPrecedence,
+ (_BoolWordOp, _And): MorePrecedence,
+ (_BoolWordOp, _Or): MorePrecedence,
+ (_BoolWordOp, _OpenP): LessPrecedence,
+ (_BoolWordOp, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_OpenP, _Date): LessPrecedence,
+ (_OpenP, _Number): LessPrecedence,
+ (_OpenP, _Str): LessPrecedence,
+ (_OpenP, _Builtin): LessPrecedence,
+ (_OpenP, _Const): LessPrecedence,
+ (_OpenP, _Function): LessPrecedence,
+ (_OpenP, _Var): LessPrecedence,
+ (_OpenP, _Mult): LessPrecedence,
+ (_OpenP, _Plus): LessPrecedence,
+ (_OpenP, _Minus): LessPrecedence,
+ (_OpenP, _Div): LessPrecedence,
+ (_OpenP, _OpenP): LessPrecedence,
+ (_OpenP, _CloseP): SamePrecedence,
+ (_OpenP, _Comma): LessPrecedence,
+ (_CloseP, (EndMarker, 'ARITHMETIC_EXPR')): MorePrecedence,
+ (_CloseP, (EndMarker, 'BOOL_EXPR')): MorePrecedence,
+ (_CloseP, (EndMarker, 'BOOL_VALUE')): MorePrecedence,
+ (_CloseP, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_CloseP, (EndMarker, 'FACTOR')): MorePrecedence,
+ (_CloseP, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_CloseP, (EndMarker, 'OR_EXPR')): MorePrecedence,
+ (_CloseP, (EndMarker, 'SEQ')): MorePrecedence,
+ (_CloseP, (EndMarker, 'SIMPLE_EXPR')): MorePrecedence,
+ (_CloseP, (EndMarker, 'TERM')): MorePrecedence,
+ (_CloseP, (EndMarker, 'VALUE')): MorePrecedence,
+ (_CloseP, _Mult): MorePrecedence,
+ (_CloseP, _Plus): MorePrecedence,
+ (_CloseP, _Minus): MorePrecedence,
+ (_CloseP, _Div): MorePrecedence,
+ (_CloseP, _BoolOp): MorePrecedence,
+ (_CloseP, _And): MorePrecedence,
+ (_CloseP, _Or): MorePrecedence,
+ (_CloseP, _BoolWordOp): MorePrecedence,
+ (_CloseP, _CloseP): MorePrecedence,
+ (_CloseP, _Comma): MorePrecedence,
+ (_CloseP, (Token.Text.Whitespace, Any)): MorePrecedence,
+ (_Comma, (EndMarker, 'CLAUSE')): MorePrecedence,
+ (_Comma, (EndMarker, 'COLSEQ')): MorePrecedence,
+ (_Comma, (EndMarker, 'GVIZQL')): MorePrecedence,
+ (_Comma, (EndMarker, 'LABELSEQ')): MorePrecedence,
+ (_Comma, (EndMarker, 'SEQ')): MorePrecedence,
+ (_Comma, _Date): LessPrecedence,
+ (_Comma, _Number): LessPrecedence,
+ (_Comma, _Str): LessPrecedence,
+ (_Comma, _Builtin): LessPrecedence,
+ (_Comma, _Const): LessPrecedence,
+ (_Comma, _Function): LessPrecedence,
+ (_Comma, _Var): LessPrecedence,
+ (_Comma, _Mult): LessPrecedence,
+ (_Comma, _Plus): LessPrecedence,
+ (_Comma, _Minus): LessPrecedence,
+ (_Comma, _Div): LessPrecedence,
+ (_Comma, _OpenP): LessPrecedence,
+ (_Comma, _CloseP): MorePrecedence,
+ (_Comma, _Comma): MorePrecedence,
+ (_Comma, (Token.Text.Whitespace, Any)): MorePrecedence,
+ ((Token.Text.Whitespace, Any), (EndMarker, 'GVIZQL')): MorePrecedence,
+ ((Token.Text.Whitespace, Any), _Format): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _GroupBy): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Label): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Limit): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Offset): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Options): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _OrderBy): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Pivot): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Select): LessPrecedence,
+ ((Token.Text.Whitespace, Any), _Where): LessPrecedence,
+ ((Token.Text.Whitespace, Any), (Token.Text.Whitespace, Any)): MorePrecedence}
 
 GVIZ_GRAMMAR_PRODUCTIONS = {
-    (Name, Any) : {
-        EndMarker : '6',
-      },
-    (Punctuation, ')') : {
-        (NonTerminal, Any) : {
-            (Punctuation, '(') : {
-                EndMarker: '5',
-              }
-          }
-      },
-    (NonTerminal, Any) : {
-        (Operator, '*') :{
-            (NonTerminal, Any) : {
-                EndMarker: '3',
-              }
-          },
-        (Operator, '+') :{
-            (NonTerminal, Any) : {
-                EndMarker: '1',
-              }
-          },
-      },
-  }
+ (NonTerminal, Any): {
+        _Format: {EndMarker: 'format'},
+        _GroupBy: {EndMarker: 'groupby'},
+        _Label: {EndMarker: 'label'},
+        _Options: {EndMarker: 'options'},
+        _OrderBy: {EndMarker: 'orderby'},
+        _Pivot: {EndMarker: 'pivot'},
+        _Select: {EndMarker: 'select'},
+        _Where: {EndMarker: 'where'},
+        _Mult: {(NonTerminal, Any): {EndMarker: 'mult'}},
+        _Plus: {(NonTerminal, Any): {EndMarker: 'sum'}},
+        _Minus: {(NonTerminal, Any): {EndMarker: 'sub'}},
+        _Div: {(NonTerminal, Any): {EndMarker: 'div'}},
+        _BoolOp: {(NonTerminal, Any): {EndMarker: 'cmp'}},
+        _And: {(NonTerminal, Any): {EndMarker: 'boolexp'}},
+        _Not: {EndMarker: 'not'},
+        _Or: {(NonTerminal, Any): {EndMarker: 'orexp'}},
+        _BoolWordOp: {(NonTerminal, Any): {EndMarker: 'strcmp'}},
+        _Comma: {(NonTerminal, Any): {EndMarker: 'seq'}},
+        (Token.Text.Whitespace, Any): {(NonTerminal, Any): {EndMarker: 'gvizql'}}},
+ _Date: {EndMarker: 'date'},
+ _Number: {_Limit: {EndMarker: 'limit'},
+        _Offset: {EndMarker: 'offset'},
+        EndMarker: 'number'},
+ _Str: {_Var: {EndMarker: 'lblexpr'},
+        EndMarker: 'str'},
+ _Const: {EndMarker: 'const'},
+ _Var: {EndMarker: 'var'},
+ _CloseP: {
+        (NonTerminal, Any): {
+            _OpenP: {
+                _Builtin: {EndMarker: 'bfuncargs'},
+                _Function: {EndMarker: 'funcargs'},
+                EndMarker: 'par'}},
+        _OpenP: {
+            _Builtin: {EndMarker: 'bfunc'},
+            _Function: {EndMarker: 'func'}}}}
 
+

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

 
 from pygments.token import *
 
-from tracgviz.util.parsing import Any, EndMarker, gen_precedence, NonTerminal, \
+from tracgviz.util.parsing import Any, EndMarker, NonTerminal, \
     OperatorPrecedenceParser as Parser
 
 # Modified version of sample operator precedence grammar in
       },
   }
 
-SAMPLE_GRAMMAR_PRECEDENCE = gen_precedence(SAMPLE_GRAMMAR_PRECEDENCE) 
+SAMPLE_GRAMMAR_PRECEDENCE = Parser.gen_precedence(SAMPLE_GRAMMAR_PRECEDENCE) 
 
 SAMPLE_GRAMMAR_PRODUCTIONS = {
     (Name, Any) : {

trac-dev/gviz/tracgviz/util/parsing.py

 """
 __author__ = 'Olemis Lang'
 
-__all__ = 'OperatorPrecedenceParser', 'Any', 'EndMarker', 'gen_precedence', \
-    'NonTerminal'
+__all__ = 'OperatorPrecedenceParser', 'Any', 'EndMarker', 'NonTerminal'
+
 __metaclass__ = type
 
-from itertools import chain, ifilter
+from itertools import dropwhile, ifilter
 import logging
 from pygments.token import *
 
     self.start_state = start_state
 
   @classmethod
+  def gen_precedence(cls, pseudo_precedence):
+    r"""Generates a precedence table from a more readable representation 
+    of the form 
+
+    {
+        SrcToken : {
+            Token.Grammar.Relationship.MorePrecedence : { DstToken1, ... }
+            Token.Grammar.Relationship.SamePrecedence : { DstToken2, ... }
+            Token.Grammar.Relationship.LessPrecedence : { DstToken3, ... }
+          },
+        ...
+    }
+    """
+    return dict(
+      [ (tkn1, tkn2), prec] \
+          for tkn1, v1 in pseudo_precedence.iteritems() \
+          for prec, v2 in v1.iteritems() \
+          for tkn2 in v2
+    )
+
+  @classmethod
   def process_productions(cls, *productions):
     r"""Generate precedence and production look up tree according to 
     a set of grammar productions.
         last_tkn, last_val = tkn, val
         tkn = None        # Force reading next char from stream
       elif precedence in REDUCE_PREC:
+        # Reduce
         try:
           prod_id, args = self._match_production(pushdown_list)
         except LookupError:
     """
     if reftkn is Any:
       return True
+    elif reftkn is EndMarker:
+      return False
     else:
       _reftype, _refval = reftkn
       _type, _val = tkn
-      return (_reftype is Any or _reftype is _type) and \
+      return (_reftype is Any or _type in _reftype) and \
           (_refval is Any or _refval == _val)
 
+  def _match_any(self, tkn, choices):
+    r"""Find the first match for token `tkn` against a sequence of `choices`.
+    """
+    try:
+      _, newchoices = dropwhile(lambda (t, _): not self._match_token(t, tkn), 
+          choices).next()
+    except StopIteration:
+      return None
+    else:
+      return newchoices
+
   def _match_production(self, pushdown_list):
     r"""Match production on reduce
     """
     idx = 0
+    last_match = None
     choices = self.productions_tree
-    while EndMarker not in choices:
+    while choices:
+      last_match = choices
       idx -= 1
-      last_tkn, last_val = pushdown_list[idx]
-      logging.debug('Last token %s : %s', last_tkn, last_val)
-      choices = choices.get((last_tkn, last_val)) or choices.get((last_tkn, Any))
-      if choices is None:
-        raise LookupError("Could not match grammar against pushdown list")
-    if EndMarker in choices:
+      tkn = pushdown_list[idx]
+      logging.debug('Last token %s', tkn)
+      choices = self._match_any(tkn, choices.iteritems())
+      logging.debug('Match %s, pushdown list %s, idx %s',
+          bool(choices), pushdown_list, idx)
+    if last_match and EndMarker in last_match:
+      idx += 1
       args = pushdown_list[idx:]
       for _ in xrange(idx, 0):
         pushdown_list.pop()
-      return choices[EndMarker], args
+      logging.debug('Prod id %s with args %s', last_match[EndMarker], args)
+      return last_match[EndMarker], args
     else:
-      raise InvalidParserConfiguration(self, "Expected production ID. Not found.")
+      raise LookupError("Could not match grammar against pushdown list")
 
 #------------------------------------------------------
 #   Helper functions and objects
 # Token used to delimit segments in a token stream
 EndMarker   = Token.Grammar.EndMarker
 
-def gen_precedence(pseudo_precedence):
-  r"""Generates a precedence table from a more readable representation 
-  of the form 
-
-  {
-      SrcToken : {
-          Token.Grammar.Relationship.MorePrecedence : { DstToken1, ... }
-          Token.Grammar.Relationship.SamePrecedence : { DstToken2, ... }
-          Token.Grammar.Relationship.LessPrecedence : { DstToken3, ... }
-        },
-      ...
-  }
-  """
-  return dict(
-    [ (tkn1, tkn2), prec] \
-        for tkn1, v1 in pseudo_precedence.iteritems() \
-        for prec, v2 in v1.iteritems() \
-        for tkn2 in v2
-  )
-
 #------------------------------------------------------
 #   Exception classes
 #------------------------------------------------------