How to use the pyparsing.CaselessLiteral function in pyparsing

To help you get started, we’ve selected a few pyparsing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pld / bamboo / bamboo / core / parser.py View on Github external
trans       trans ( case )
        agg         agg ( trans[, trans]* )
        =========   ==========

        """
        if self.bnf:
            return self.bnf

        # literal operators
        exp_op = Literal('^')
        sign_op = oneOf('+ -')
        mult_op = oneOf('* /')
        plus_op = oneOf('+ -')
        not_op = CaselessLiteral('not')
        and_op = CaselessLiteral('and')
        or_op = CaselessLiteral('or')
        in_op = CaselessLiteral('in').suppress()
        comparison_op = oneOf('< <= > >= != ==')
        case_op = CaselessLiteral('case').suppress()

        # aggregation functions
        aggregations = build_caseless_or_expression(self.aggregation_names)

        # literal syntactic
        open_bracket = Literal('[').suppress()
        close_bracket = Literal(']').suppress()
        open_paren = Literal('(').suppress()
        close_paren = Literal(')').suppress()
        comma = Literal(',').suppress()
        dquote = Literal('"').suppress()
        colon = Literal(':').suppress()
github meahmadi / nsun / ir / ac / iust / me_ahmadi / multiProcessMind / language.py View on Github external
ss.timeValue       = (pp.CaselessLiteral("Jalali") | pp.CaselessLiteral("J") |\
                                   pp.CaselessLiteral("Hijri") | pp.CaselessLiteral("H") |\
                                   pp.CaselessLiteral("Gregorian") | pp.CaselessLiteral("g") )\
                                   +(ss.timeint + pp.Suppress(ss.dash) + ss.timeint + pp.Suppress(ss.dash) + ss.timeint  \
                                      + ss.timeint + pp.Suppress(ss.dpoint) + ss.timeint + pp.Suppress(ss.dpoint) + ss.timeint + pp.Suppress(ss.dpoint) + ss.timeint ) 
        ss.properties      = pp.Group( pp.Suppress(pp.Literal("{")) + ss.nameValue + pp.ZeroOrMore(pp.Suppress(ss.comma) + ss.nameValue) + pp.Suppress(pp.Literal("}"))).setParseAction(self.parseDict)
        
        
        ss.nameSelectorBase= pp.Group(pp.Combine(pp.Optional(ss.tajob) + (ss.question |  pp.Optional(ss.var))) + pp.Optional(ss.properties))
        ss.nameSelector    = ss.nameSelectorBase + pp.ZeroOrMore(pp.Group((ss.dash|ss.lt|ss.bg) + pp.Optional(ss.nameSelectorBase) + (ss.dash|ss.lt|ss.bg)) + ss.nameSelectorBase)
        
        ss.operator        = pp.Word(pp.alphas) + pp.Optional(ss.properties)
        
        ss.findCondition = pp.Group(pp.Suppress("(") + ss.nameSelector + pp.Suppress(")")) + pp.Optional(pp.CaselessLiteral("as") + ss.var)
        ss.findExpression = pp.CaselessLiteral("find") + \
                    ( pp.CaselessLiteral("when") | pp.CaselessLiteral("where") | pp.CaselessLiteral("who") | pp.CaselessLiteral("the") | pp.CaselessLiteral("only") | pp.CaselessLiteral("someof") | pp.CaselessLiteral("all") | pp.CaselessLiteral("a") | pp.CaselessLiteral("some") )("findType") +\
                    ss.var +\
                    ss.findCondition #+ pp.ZeroOrMore( ss.comma  + ss.findCondition )
                    
        ss.searchExpression = pp.CaselessLiteral("search") + \
                                ss.var + \
                                ss.var + \
                                pp.Group(pp.OneOrMore(ss.var)) + \
                                ss.properties
        
        ss.placeExpression = pp.CaselessLiteral("place") + (ss.var | ss.stringPhrase)
        
        ss.spatialOperation = pp.Forward()
        ss.spatialOperation <<  pp.Suppress("(") + pp.Group(ss.var |  ss.spatialOperation ) + ss.operator + pp.Group(ss.var |  ss.spatialOperation ) + pp.Suppress(")") 
        ss.seeExpression =  pp.CaselessLiteral("see") + ( pp.OneOrMore(ss.var | ss.spatialOperation.setParseAction(self.parseSpatialExpression)))
        
        ss.eventExpression = pp.CaselessLiteral("event") +  (ss.var | ss.stringPhrase)
github pld / bamboo / bamboo / core / parser.py View on Github external
case_op = CaselessLiteral('case').suppress()

        # aggregation functions
        aggregations = build_caseless_or_expression(self.aggregation_names)

        # literal syntactic
        open_bracket = Literal('[').suppress()
        close_bracket = Literal(']').suppress()
        open_paren = Literal('(').suppress()
        close_paren = Literal(')').suppress()
        comma = Literal(',').suppress()
        dquote = Literal('"').suppress()
        colon = Literal(':').suppress()

        # functions
        date_func = CaselessLiteral('date')
        percentile_func = CaselessLiteral('percentile')
        today_func = CaselessLiteral('today()').setParseAction(EvalToday)

        # case statment
        default = CaselessLiteral('default')

        reserved_words = MatchFirst(
            [Keyword(word) for word in self.reserved_words])

        # atoms
        integer = Word(nums)
        real = Combine(Word(nums) + '.' + Word(nums))
        variable = ~reserved_words + Word(alphanums + '_')
        atom = real | integer | variable
        atom.setParseAction(EvalConstant)
github google / encrypted-bigquery-client / src / query_parser.py View on Github external
for i in reversed(range(0, len(tokens))):
      if tokens[i] == '-':
        math_stack.append(int('-1'))
        math_stack.append(util.OperatorToken('*', 2))
      elif tokens[i] == '~':
        math_stack.append(util.OperatorToken('~', 1))
      elif tokens[i].lower() == 'not':
        math_stack.append(util.OperatorToken('not', 1))

  def PushBinaryOperator(tokens):
    math_stack.append(util.OperatorToken(tokens[0], 2))

  # Miscellaneous symbols and keywords.
  comma = pp.Literal(',')
  decimal = pp.Literal('.')
  exponent_literal = pp.CaselessLiteral('E')
  lp = pp.Literal('(')
  rp = pp.Literal(')')
  count_star = pp.Literal('*')
  distinct_keyword = pp.CaselessKeyword('DISTINCT')

  # Any non-space containing sequence of characters that must begin with
  # an alphabetical character and contain alphanumeric characters
  # and underscores (i.e. function or variable names).
  label = pp.Word(pp.alphas, pp.alphas + pp.nums + '_' + '.')

  # A single/double quote surrounded string.
  string = pp.quotedString

  # Various number representations.
  integer = pp.Word(pp.nums)
  decimal_type1 = pp.Combine(integer + decimal + pp.Optional(integer))
github kjellmf / dot2tex / dot2tex / dotparsing.py View on Github external
rparen = Literal(")")
        equals = Suppress("=")
        comma = Literal(",")
        dot = Literal(".")
        slash = Literal("/")
        bslash = Literal("\\")
        star = Literal("*")
        semi = Suppress(";")
        at = Literal("@")
        minus = Literal("-")
        pluss = Suppress("+")

        # keywords
        strict_ = CaselessLiteral("strict")
        graph_ = CaselessLiteral("graph")
        digraph_ = CaselessLiteral("digraph")
        subgraph_ = CaselessLiteral("subgraph")
        node_ = CaselessLiteral("node")
        edge_ = CaselessLiteral("edge")

        punctuation_ = "".join([c for c in string.punctuation if c not in '_']) + string.whitespace
        # token definitions

        identifier = Word(alphanums + "_").setName("identifier")

        # double_quoted_string = QuotedString('"', multiline=True,escChar='\\',
        #    unquoteResults=True) # dblQuotedString
        double_quoted_string = Regex(r'\"(?:\\\"|\\\\|[^"])*\"', re.MULTILINE)
        double_quoted_string.setParseAction(removeQuotes)
        quoted_string = Combine(double_quoted_string +
                                Optional(OneOrMore(pluss + double_quoted_string)), adjacent=False)
        alphastring_ = OneOrMore(CharsNotIn(punctuation_))
github nil0x42 / phpsploit / deps / pyparsing-2.1.1 / examples / urlExtractor.py View on Github external
# Copyright 2004, Paul McGuire
from pyparsing import Literal,Suppress,CharsNotIn,CaselessLiteral,\
        Word,dblQuotedString,alphanums,SkipTo
import urllib.request, urllib.parse, urllib.error
import pprint

# Define the pyparsing grammar for a URL, that is:
#    URLlink ::= <a href="URL">linkText</a>
#    URL ::= doubleQuotedString | alphanumericWordPath
# Note that whitespace may appear just about anywhere in the link.  Note also
# that it is not necessary to explicitly show this in the pyparsing grammar; by default,
# pyparsing skips over whitespace between tokens.
linkOpenTag = (Literal("&lt;") + "a" + "href" + "=").suppress() + \
                ( dblQuotedString | Word(alphanums+"/") ) + \
                Suppress("&gt;") 
linkCloseTag = Literal("&lt;") + "/" + CaselessLiteral("a") + "&gt;"
link = linkOpenTag + SkipTo(linkCloseTag) + linkCloseTag.suppress()

# Go get some HTML with some links in it.
serverListPage = urllib.request.urlopen( "http://www.yahoo.com" )
htmlText = serverListPage.read()
serverListPage.close()

# scanString is a generator that loops through the input htmlText, and for each
# match yields the tokens and start and end locations (for this application, we are
# not interested in the start and end values).
for toks,strt,end in link.scanString(htmlText):
    print(toks.asList())

# Rerun scanString, but this time create a dict of text:URL key-value pairs.
# Need to reverse the tokens returned by link, using a parse action.
link.setParseAction( lambda st,loc,toks: [ toks[1], toks[0] ] )
github meahmadi / nsun / ir / ac / iust / me_ahmadi / multiProcessMind / language.py View on Github external
ss.typeName        = pp.Combine(pp.Word(ss.caps,exact=1) + pp.Word(pp.alphas))#("TypeName")#TODO action
        ss.objectName      = pp.Combine(pp.Word(ss.lowers,exact=1) + pp.Optional(pp.Word(pp.alphas)))#("ObjectName")#TODO action
        ss.objectid        = pp.Combine(pp.Literal("`")+ ss.integer + pp.Literal("`"))#.setParseAction(self.parseObjectId)#("ObjectId")
        ss.var             = pp.Combine(pp.Optional(ss.dollar)+pp.Word(pp.alphas+ "_",exact=1) + pp.Optional(pp.Word(pp.alphas + pp.nums + "_"))) | ss.objectid#("VariableName")#TODO action
        
        
        ss.constValue      =  ss.number | ss.stringPhrase | ss.NONE | pp.Group(pp.Suppress(ss.dollar) + ss.var + pp.Suppress(ss.dot) + ss.var).setParseAction(self.parseVarProp) | pp.Group(ss.var).setParseAction(self.parseVarToId) #pp.Word(pp.alphas) |
        ss.nameValue       = pp.Group(pp.Word(pp.alphas) + pp.Suppress(pp.Literal(":")) + ss.constValue)
        ss.dTimeValue      = ss.number +\
                                (pp.CaselessLiteral("millisecond") | pp.CaselessLiteral("ms") |\
                                 pp.CaselessLiteral("second") | pp.CaselessLiteral("s") |\
                                 pp.CaselessLiteral("minute") | pp.Literal("m") |\
                                 pp.CaselessLiteral("hour")   | pp.CaselessLiteral("h") |\
                                 pp.CaselessLiteral("day")    | pp.CaselessLiteral("d") |\
                                 pp.CaselessLiteral("week")   | pp.CaselessLiteral("w") |\
                                 pp.CaselessLiteral("month")  | pp.Literal("M") |\
                                 pp.CaselessLiteral("year")   | pp.CaselessLiteral("y"))
        ss.timeValue       = (pp.CaselessLiteral("Jalali") | pp.CaselessLiteral("J") |\
                                   pp.CaselessLiteral("Hijri") | pp.CaselessLiteral("H") |\
                                   pp.CaselessLiteral("Gregorian") | pp.CaselessLiteral("g") )\
                                   +(ss.timeint + pp.Suppress(ss.dash) + ss.timeint + pp.Suppress(ss.dash) + ss.timeint  \
                                      + ss.timeint + pp.Suppress(ss.dpoint) + ss.timeint + pp.Suppress(ss.dpoint) + ss.timeint + pp.Suppress(ss.dpoint) + ss.timeint ) 
        ss.properties      = pp.Group( pp.Suppress(pp.Literal("{")) + ss.nameValue + pp.ZeroOrMore(pp.Suppress(ss.comma) + ss.nameValue) + pp.Suppress(pp.Literal("}"))).setParseAction(self.parseDict)
        
        
        ss.nameSelectorBase= pp.Group(pp.Combine(pp.Optional(ss.tajob) + (ss.question |  pp.Optional(ss.var))) + pp.Optional(ss.properties))
        ss.nameSelector    = ss.nameSelectorBase + pp.ZeroOrMore(pp.Group((ss.dash|ss.lt|ss.bg) + pp.Optional(ss.nameSelectorBase) + (ss.dash|ss.lt|ss.bg)) + ss.nameSelectorBase)
        
        ss.operator        = pp.Word(pp.alphas) + pp.Optional(ss.properties)
        
        ss.findCondition = pp.Group(pp.Suppress("(") + ss.nameSelector + pp.Suppress(")")) + pp.Optional(pp.CaselessLiteral("as") + ss.var)
github facebookincubator / OnlineSchemaChange / core / lib / sqlparse / create.py View on Github external
Optional(COMMA + LENGTH) + RIGHT_PARENTHESES,
        adjacent=False,
        joinString=', '
    )('length')
    FLOAT_DEF = (
        FLOAT_TYPE('column_type') + Optional(FLOAT_LEN) + UNSIGNED +
        ZEROFILL
    )
    # time type definition. They contain type_name and an optional FSP section
    # Sample: DATETIME[(fsp)]
    FSP = COL_LEN
    DT_DEF = (
        Combine(
            CaselessLiteral("TIME") + Optional(CaselessLiteral("STAMP"))
        ) |
        CaselessLiteral("DATETIME")
    )('column_type') + Optional(FSP)
    SIMPLE_DEF = (
        CaselessLiteral("DATE") | CaselessLiteral("YEAR") |
        CaselessLiteral("TINYBLOB") | CaselessLiteral("BLOB") |
        CaselessLiteral("MEDIUMBLOB") | CaselessLiteral("LONGBLOB") |
        CaselessLiteral("BOOL") | CaselessLiteral("BOOLEAN")
    )('column_type')
    OPTIONAL_COL_LEN = Optional(COL_LEN)
    BINARY = Optional(CaselessLiteral("BINARY"))('binary')
    CHARSET_NAME = (
        Optional(QUOTE).suppress() +
        Word(alphanums + '_')('charset') +
        Optional(QUOTE).suppress()
    )
    COLLATION_NAME = (
        Optional(QUOTE).suppress() +
github Orange-OpenSource / diafuzzer / collect-ccf.py View on Github external
digits = '0123456789'
mul = Group(O(W(digits)) + '*' + O(W(digits)))

fixed_avp = '&lt;' + W(alphanums + '_-') + '&gt;'
mandatory_avp = '{' + W(alphanums + '_-') + '}'
optional_avp = '[' + W(alphanums + '_-') + ']'

avp = Group(O(mul) + (fixed_avp | mandatory_avp | optional_avp))

avps = Group(OneOrMore(avp))

flags = Group(delimitedList(Literal('REQ')|Literal('PXY')|Literal('ERR'), delim=','))

msg_decl = O(S('&lt;')) + W(alphas + '_-') + O(S('&gt;'))
msg_hdr = S('&lt;') + S(CL('Diameter')) + S(O('-')) + S(CL('Header')) + S(':') + W(alphanums) + O(S(',')) + flags + O(S(',') + W(alphanums)) + S('&gt;')
equals = S(':') + S(':') + S('=')
msg_ccf = msg_decl + equals + msg_hdr + avps

avp_decl = O(S('&lt;')) + W(alphas + '_-') + O(S('&gt;'))
avp_hdr = S('&lt;') + S(CL('AVP')) + S(O('-')) + S(CL('Header')) + S(':') + W(alphanums) + S(O(',')) + O(W(alphanums)) + S('&gt;')
avp_ccf = avp_decl + equals + avp_hdr + avps





'''
Ensure canonical form:
- force sort of Camel-Case used in IETF and 3gpp specs
- sort AVPs: first fixed, then mandatory, then optional. Mandatory and optional AVPs are sorted
'''
github pydot / pydot-ng / pydot_ng / _dotparser.py View on Github external
# punctuation
        colon = pyparsing.Literal(":")
        lbrace = pyparsing.Literal("{")
        rbrace = pyparsing.Literal("}")
        lbrack = pyparsing.Literal("[")
        rbrack = pyparsing.Literal("]")
        lparen = pyparsing.Literal("(")
        rparen = pyparsing.Literal(")")
        equals = pyparsing.Literal("=")
        comma = pyparsing.Literal(",")
        semi = pyparsing.Literal(";")
        at = pyparsing.Literal("@")
        minus = pyparsing.Literal("-")

        # keypyparsing.Words
        strict_ = pyparsing.CaselessLiteral("strict")
        graph_ = pyparsing.CaselessLiteral("graph")
        digraph_ = pyparsing.CaselessLiteral("digraph")
        subgraph_ = pyparsing.CaselessLiteral("subgraph")
        node_ = pyparsing.CaselessLiteral("node")
        edge_ = pyparsing.CaselessLiteral("edge")

        # token definitions
        identifier = pyparsing.Word(pyparsing.alphanums + "_.").\
            setName("identifier")

        # dblpyparsing.QuotedString
        double_quoted_string = pyparsing.QuotedString('"', multiline=True,
                                                      unquoteResults=False)

        noncomma_ = "".join([c for c in pyparsing.printables if c != ","])
        alphastring_ = pyparsing.OneOrMore(pyparsing.CharsNotIn(noncomma_ +