trac-gviz / trac-dev / gviz / tracgviz / grammar.py

Olemis Lang 2f29abc 
































Olemis Lang e1cdac3 







































































Olemis Lang 2f29abc 













































































#!/usr/bin/env python

# Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

r"""Internal representation of operator precedence grammar used to parse
Google Visualization API Query Language expressions.

Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
Licensed under the Apache License, Version 2.0 
"""
__author__ = 'Olemis Lang'

__all__ = '', ''

from pygments.token import *

from tracgviz.util.parsing import Any, EndMarker, gen_precedence, NonTerminal, \
    OperatorPrecedenceParser as Parser

# Grammar
# =======

GVIZ_START_STATE = 'GVIZ_SQL'

_And        = (Operator.Word.Boolean, 'and')
_Or         = (Operator.Word.Boolean, 'or')
_Not        = (Operator.Word.Boolean, 'not')
_Number     = (Number, Any)
_Var        = (Name.Variable, Any)
_Str        = (String, Any)
_Date       = (Literal.Date, Any)
_Const      = (Name.Constant, Any)
_Builtin    = (Name.Builtin, Any)
_Function   = (Name.Function, Any)
_Comma      = (Punctuation, ',')
_OpenP      = (Punctuation, '(')
_CloseP     = (Punctuation, ')')
_Sum        = (Operator.Arithmetic, '+')
_Multiply   = (Operator.Arithmetic, '*')
_Subtract   = (Operator.Arithmetic, '-')
_Divide     = (Operator.Arithmetic, '/')
_BoolOp     = (Operator.Comparison, Any)
_BoolWordOp = (Operator.Word.Comparison, Any)
_EndAE      = (EndMarker, 'ARITHMETIC_EXPR')
_EndBE      = (EndMarker, 'BOOL_EXPR')
_EndSuite   = (EndMarker, 'SUITE')

GVIZ_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

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) 

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',
              }
          },
      },
  }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.