• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyparsing.oneOf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyparsing.oneOf函数的典型用法代码示例。如果您正苦于以下问题:Python oneOf函数的具体用法?Python oneOf怎么用?Python oneOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了oneOf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_idl_line_parser

def get_idl_line_parser():
    """
    Based on http://pyparsing.wikispaces.com/file/view/parsePythonValue.py
    """
    from pyparsing import \
    Word, ZeroOrMore, OneOrMore, Optional, oneOf, StringEnd, Suppress, Group, Combine, \
    nums, dblQuotedString, removeQuotes
    
    s = Suppress
    int_number = Combine(Optional(oneOf("+ -")) + Word(nums)).setParseAction(lambda tokens: int(tokens[0])).setName("integer")
    float_number = \
        Combine(Optional(oneOf("+ -")) + Word(nums) + Optional("." +
                   Optional(Word(nums)) +
                   Optional(oneOf("e E")+Optional(oneOf("+ -")) +Word(nums)))) \
        .setName("float") \
        .setParseAction( lambda tokens: float(tokens[0]) )
               
    bounding_box = s('(') + OneOrMore( int_number | s(',') ) + s(')')
    bounding_box_with_score = Group(bounding_box + Optional( ( s(":") | s("~") ) +  float_number ))
    #filename =  s('"') + Word(alphanums + "/_.~") +  s('"')
    quoted = dblQuotedString.setParseAction(removeQuotes)
    filename = quoted
    idl_line = filename + Optional(s(':') +  ZeroOrMore(bounding_box_with_score | s(','))) + ( s(";") | s(".") ) + StringEnd() 

    #print( filename.parseString("\"left/image_00000004_0.png\"") )
    #print( bounding_box.parseString("(221, 183, 261, 289)") )
    
    return idl_line.parseString
开发者ID:Belial2010,项目名称:Pedestrian-Detection-Project,代码行数:28,代码来源:idl_parsing.py


示例2: check_in_parsing

def check_in_parsing(s):
    update =    (Literal('@') + 
                Group(OneOrMore(Word(alphas))) +  
                StringEnd()) | (Literal('@') + 
                SkipTo(oneOf("4 for For FOR")) + 
                oneOf('4 for For FOR') + 
                Word(nums))
    
    #for s in smstestlist:
    #    print s
    try:
        u = update.parseString(s)
        print u
        if len(u) == 2:
            u[1] = ' '.join(u[1])
            if u[1] in safezones:
                print "user in safezone " + u[1]
                combo = {'location':u[1],'hours':'24'}
                return combo
            else:
                print "Error: " + u[1] + " is not a safezone!"
                return "Error: " + u[1] + " is not a safezone! Syntax for checking in: @ location 4 numberofhours"
        else:
            print "user at " + u[1] + " for " + u[3] + " hours."
            combo = {'location':u[1],'hours':str(u[3])}
            return combo
    except:
        print "Error: Unable to understand!"
开发者ID:elizabethmgin,项目名称:panoptincon,代码行数:28,代码来源:utilities.py


示例3: _parse_expr

def _parse_expr(text, ldelim="(", rdelim=")"):
    """Parse mathematical expression using PyParsing."""
    var = pyparsing.Word(pyparsing.alphas + "_", pyparsing.alphanums + "_")
    point = pyparsing.Literal(".")
    exp = pyparsing.CaselessLiteral("E")
    number = pyparsing.Combine(
        pyparsing.Word("+-" + pyparsing.nums, pyparsing.nums)
        + pyparsing.Optional(point + pyparsing.Optional(pyparsing.Word(pyparsing.nums)))
        + pyparsing.Optional(
            exp + pyparsing.Word("+-" + pyparsing.nums, pyparsing.nums)
        )
    )
    atom = var | number
    oplist = [
        (pyparsing.Literal("**"), 2, pyparsing.opAssoc.RIGHT),
        (pyparsing.oneOf("+ - ~"), 1, pyparsing.opAssoc.RIGHT),
        (pyparsing.oneOf("* / // %"), 2, pyparsing.opAssoc.LEFT),
        (pyparsing.oneOf("+ -"), 2, pyparsing.opAssoc.LEFT),
        (pyparsing.oneOf("<< >>"), 2, pyparsing.opAssoc.LEFT),
        (pyparsing.Literal("&"), 2, pyparsing.opAssoc.LEFT),
        (pyparsing.Literal("^"), 2, pyparsing.opAssoc.LEFT),
        (pyparsing.Literal("|"), 2, pyparsing.opAssoc.LEFT),
    ]
    # Get functions
    expr = pyparsing.infixNotation(
        atom, oplist, lpar=pyparsing.Suppress(ldelim), rpar=pyparsing.Suppress(rdelim)
    )
    return expr.parseString(text)[0]
开发者ID:pmacosta,项目名称:peng,代码行数:28,代码来源:functions.py


示例4: _parseFeatureSignature

def _parseFeatureSignature(sig):
    """This function parses a given feature-signature."""
    mal = set()

    def _rewriteOne(p):
        return ""

    def _rewriteTwo(p):
        return ""

    def _addIdentifier2Mal(p):
        mal.add(p[0])

    operand = __string | __hexadec | __function | __integer | __identifier.setParseAction(_addIdentifier2Mal)
    compoperator = pypa.oneOf("< > <= >= == !=")
    calcoperator = pypa.oneOf("+ - * / % & | << >>")
    expr = pypa.operatorPrecedence(
        operand,
        [
            ("defined", 1, pypa.opAssoc.RIGHT, _rewriteOne),
            ("!", 1, pypa.opAssoc.RIGHT, _rewriteOne),
            (calcoperator, 2, pypa.opAssoc.LEFT, _rewriteTwo),
            (compoperator, 2, pypa.opAssoc.LEFT, _rewriteTwo),
            ("&&", 2, pypa.opAssoc.LEFT, _rewriteTwo),
            ("||", 2, pypa.opAssoc.LEFT, _rewriteTwo),
        ],
    )

    try:
        rsig = expr.parseString(sig)[0]
    except pypa.ParseException, e:
        print("ERROR (parse): cannot parse sig (%s) -- (%s)" % (sig, e.col))
        return sig
开发者ID:pombredanne,项目名称:cppstats,代码行数:33,代码来源:derivative.py


示例5: parse

def parse(formula):
    """Parse formula string and create abstract syntax tree (AST).
    """
    # LTL expression
    _ltl_expr = pp.operatorPrecedence(
        _proposition,
        [
            ("'", 1, pp.opAssoc.LEFT, ASTUnTempOp),
            ("!", 1, pp.opAssoc.RIGHT, ASTNot),
            (_UnaryTempOps, 1, pp.opAssoc.RIGHT, ASTUnTempOp),
            (pp.oneOf("& &&"), 2, pp.opAssoc.LEFT, ASTAnd),
            (pp.oneOf("| ||"), 2, pp.opAssoc.LEFT, ASTOr),
            (pp.oneOf("xor ^"), 2, pp.opAssoc.LEFT, ASTXor),
            ("->", 2, pp.opAssoc.RIGHT, ASTImp),
            ("<->", 2, pp.opAssoc.RIGHT, ASTBiImp),
            (pp.oneOf("= == !="), 2, pp.opAssoc.RIGHT, ASTComparator),
            (pp.oneOf("U V R"), 2, pp.opAssoc.RIGHT, ASTBiTempOp),
        ],
    )
    _ltl_expr.ignore(pp.LineStart() + "--" + pp.restOfLine)

    # Increase recursion limit for complex formulae
    sys.setrecursionlimit(2000)
    try:
        return _ltl_expr.parseString(formula, parseAll=True)[0]
    except RuntimeError:
        raise pp.ParseException("Maximum recursion depth exceeded," "could not parse")
开发者ID:rmattila,项目名称:tulip-control,代码行数:27,代码来源:pyparser.py


示例6: __init__

    def __init__(self):
        from pyparsing import (ParserElement, StringEnd, LineEnd, Literal,
                               pythonStyleComment, ZeroOrMore, Suppress,
                               Optional, Combine, OneOrMore, Regex, oneOf,
                               QuotedString, Group, ParseException)

        ParserElement.setDefaultWhitespaceChars("\t ")

        EOF = StringEnd()
        EOL = ~EOF + LineEnd() # EOL must not match on EOF

        escape = Literal("\\")
        comment = pythonStyleComment
        junk = ZeroOrMore(comment | EOL).suppress()

        ## word (i.e: single argument string)
        word = Suppress(escape + EOL + Optional(comment)) \
        | Combine(OneOrMore( escape.suppress() + Regex(".") |
                             QuotedString("'", escChar='\\', multiline=True) |
                             QuotedString('"', escChar='\\', multiline=True) |
                             Regex("[^ \t\r\n\f\v\\\\$&<>();\|\'\"`]+") |
                             Suppress(escape + EOL) ))

        ## redirector (aka bash file redirectors, such as "2>&1" sequences)
        fd_src = Regex("[0-2]").setParseAction(lambda t: int(t[0]))
        fd_dst = Suppress("&") + fd_src
        # "[n]<word" || "[n]<&word" || "[n]<&digit-"
        fd_redir = (Optional(fd_src, 0) + Literal("<")
                    |Optional(fd_src, 1) + Literal(">"))\
                   +(word | (fd_dst + Optional("-")))
        # "&>word" || ">&word"
        full_redir = (oneOf("&> >&") + word)\
                     .setParseAction(lambda t:("&" ,">", t[-1]))
        # "<<<word" || "<<[-]word"
        here_doc = Regex("<<(<|-?)") + word
        # "[n]>>word"
        add_to_file = Optional(fd_src | Literal("&"), 1) + \
                      Literal(">>") + word
        # "[n]<>word"
        fd_bind = Optional(fd_src, 0) + Literal("<>") + word

        redirector = (fd_redir | full_redir | here_doc
                      | add_to_file | fd_bind)\
                     .setParseAction(lambda token: tuple(token))

        ## single command (args/redir list)
        command = Group(OneOrMore(redirector | word))

        ## logical operators (section splits)
        semicolon = Suppress(";") + junk
        connector = (oneOf("&& || |") + junk) | semicolon

        ## pipeline, aka logical block of interconnected commands
        pipeline = junk + Group(command +
                                ZeroOrMore(connector + command) +
                                Optional(semicolon))

        # define object attributes
        self.LEXER = pipeline.ignore(comment) + EOF
        self.parseException = ParseException
开发者ID:0x0mar,项目名称:phpsploit,代码行数:60,代码来源:lexer.py


示例7: __init__

 def __init__(self):
     """
     expop   :: '^'
     multop  :: '*' | '/'
     addop   :: '+' | '-'
     integer :: ['+' | '-'] '0'..'9'+
     atom    :: PI | E | real | fn '(' expr ')' | '(' expr ')'
     factor  :: atom [ expop factor ]*
     term    :: factor [ multop factor ]*
     expr    :: term [ addop term ]*
     """
     point = Literal( "." )
     e     = CaselessLiteral( "E" )
     fnumber = Combine( Word( "+-"+alphanums+"_", alphanums+"_" ) + 
                        Optional( point + Optional( Word( alphanums+"_" ) ) ) +
                        Optional( e + Word( "+-"+alphanums+"_", alphanums+"_" ) ) )
     
     ident = Word(alphas,alphanums + "_")       
     plus  = Literal( "+" )
     minus = Literal( "-" )
     mult  = Literal( "*" )
     div   = Literal( "/" )
     lpar  = Literal( "(" ).suppress()
     rpar  = Literal( ")" ).suppress()
     
     addop  = plus | minus
     multop = mult | div
     expop = Literal( "^" )
     pi    = CaselessLiteral( "PI" )
     expr = Forward()
     function = ident + lpar + expr + ZeroOrMore("," + expr) + rpar
     atom = ((Optional(oneOf("- +")) +
              (pi|e|function|fnumber).setParseAction(self.pushFirst))
             | Optional(oneOf("- +")) + Group(lpar+expr+rpar)
             ).setParseAction(self.pushUMinus)       
     # by defining exponentiation as "atom [ ^ factor ]..." instead of 
     # "atom [ ^ atom ]...", we get right-to-left exponents, instead of left-to-right
     # that is, 2^3^2 = 2^(3^2), not (2^3)^2.
     factor = Forward()
     factor << atom + ZeroOrMore( ( expop + factor ).setParseAction( self.pushFirst ) )
     term = factor + ZeroOrMore( ( multop + factor ).setParseAction( self.pushFirst ) )
     expr << term + ZeroOrMore( ( addop + term ).setParseAction( self.pushFirst ) )
     # addop_term = ( addop + term ).setParseAction( self.pushFirst )
     # general_term = term + ZeroOrMore( addop_term ) | OneOrMore( addop_term)
     # expr <<  general_term       
     self.bnf = expr
     # map operator symbols to corresponding arithmetic operations
     epsilon = 1e-12
     self.opn = { "+" : operator.add,
             "-" : operator.sub,
             "*" : operator.mul,
             "/" : operator.truediv,
             "^" : operator.pow }
     self.fn  = { "sin" : math.sin,
             "cos" : math.cos,
             "tan" : math.tan,
             "abs" : abs,
             "trunc" : lambda a: int(a),
             "round" : round,
             "sgn" : lambda a: abs(a)>epsilon and cmp(a,0) or 0}
开发者ID:Alwnikrotikz,项目名称:bionetgen,代码行数:60,代码来源:util.py


示例8: _parse_line

def _parse_line():
    """Parse a single data line that may contain string or numerical data.
    Float and Int 'words' are converted to their appropriate type. 
    Exponentiation is supported, as are NaN and Inf."""
        
    digits = Word(nums)
    dot = "."
    sign = oneOf("+ -")
    ee = CaselessLiteral('E') | CaselessLiteral('D')

    num_int = ToInteger(Combine( Optional(sign) + digits ))
    
    num_float = ToFloat(Combine( Optional(sign) + 
                        ((digits + dot + Optional(digits)) |
                         (dot + digits)) +
                         Optional(ee + Optional(sign) + digits)
                        ))
    
    # special case for a float written like "3e5"
    mixed_exp = ToFloat(Combine( digits + ee + Optional(sign) + digits ))
    
    nan = ToInf(oneOf("Inf -Inf")) | \
          ToNan(oneOf("NaN nan NaN%  NaNQ NaNS qNaN sNaN " + \
                        "1.#SNAN 1.#QNAN -1.#IND"))
    
    # sep = Literal(" ") | Literal("\n")
    
    data = ( OneOrMore( (nan | num_float | mixed_exp | num_int |
                         Word(printables)) ) )
    
    return data
开发者ID:OzanCKN,项目名称:OpenMDAO-Framework,代码行数:31,代码来源:filewrap.py


示例9: __init__

    def __init__(self, ffilter, queue_out):
	FuzzQueue.__init__(self, queue_out)
	Thread.__init__(self)
	self.setName('filter_thread')

	self.queue_out = queue_out

	if PYPARSING:
	    element = oneOf("c l w h")
	    digits = "XB0123456789"
	    integer = Word( digits )#.setParseAction( self.__convertIntegers )
	    elementRef = Group(element + oneOf("= != < > >= <=") + integer)
	    operator = oneOf("and or")
	    definition = elementRef + ZeroOrMore( operator + elementRef)
	    nestedformula = Group(Suppress(Optional(Literal("("))) + definition + Suppress(Optional(Literal(")"))))
	    self.finalformula = nestedformula + ZeroOrMore( operator + nestedformula)

	    elementRef.setParseAction(self.__compute_element)
	    nestedformula.setParseAction(self.__compute_formula)
	    self.finalformula.setParseAction(self.__myreduce)

	self.res = None
	self.hideparams = ffilter

	if "XXX" in self.hideparams['codes']:
	    self.hideparams['codes'].append("0")

	self.baseline = None
开发者ID:601040605,项目名称:wfuzz,代码行数:28,代码来源:filter.py


示例10: _parse_template

    def _parse_template(self, options, template):
        """Parse a template string."""
        variable_name = Word(alphas + " ")
        variable_prefix = Optional(Word(alphas) + ":")
        variable = "{" + variable_prefix + variable_name + "}"
        variable.setParseAction(self._replace_variable(options))

        block_name = oneOf("Title Description PreviousPage NextPage")
        block_start = "{block:" + block_name + "}"
        block_end = "{/block:" + block_name + "}"
        block = block_start + SkipTo(block_end) + block_end
        block.setParseAction(self._replace_block(options))

        block_type_name = oneOf("Text Photo Panorama Photoset Quote Link Chat Video Audio")
        block_type_start = "{block:" + block_type_name + "}"
        block_type_end = "{/block:" + block_type_name + "}"
        block_type = block_type_start + SkipTo(block_type_end) + block_type_end
        block_type.setParseAction(self._replace_block_type(options))

        block_cond_name = Word(alphas)
        block_cond_start = "{block:If" + Optional("Not") + block_cond_name + "}"
        block_cond_end = "{/block:If" + Optional("Not") + block_cond_name + "}"
        block_cond = block_cond_start + SkipTo(block_cond_end) + block_cond_end
        block_cond.setParseAction(self._replace_block_cond(options))

        block_iter_name = oneOf("Posts")
        block_iter_start = "{block:" + block_iter_name + "}"
        block_iter_end = "{/block:" + block_iter_name + "}"
        block_iter = block_iter_start + SkipTo(block_iter_end) + block_iter_end
        block_iter.setParseAction(self._replace_block_iter(options))

        parser = (block | block_type | block_cond | block_iter | variable)
        return parser.transformString(template)
开发者ID:pabluk,项目名称:tumblr-theme-parser,代码行数:33,代码来源:__init__.py


示例11: interpretLine

	def interpretLine(self,l):
		#Construct parsing rules
		natural=pyparsing.Word(pyparsing.nums)
		natural_n=pyparsing.Word(pyparsing.nums)
		natural_n.setParseAction(lambda t: int(t[0]))
		integer=pyparsing.Optional(pyparsing.oneOf(['-', '+']))+natural
		decimal=pyparsing.Word('.',pyparsing.nums)
		exponent=pyparsing.Literal('e')+integer
		number=pyparsing.Combine(integer+pyparsing.Optional(decimal)+pyparsing.Optional(exponent))
		number.setParseAction(lambda t: float(t[0]))
		cmd=pyparsing.Group(pyparsing.oneOf(CMDS)+natural_n)
		coord=pyparsing.Group(pyparsing.oneOf(AXES)+number)
		line=cmd+pyparsing.Group(pyparsing.ZeroOrMore(coord))

		if len(l.strip())==0: return False

		res=line.parseString(l).asList()
		letter=res[0][0]
		num=res[0][1]
		if letter=='G':
			return self.interpretG(num,res[1])
		if letter=='M':
			return self.interpretM(num)
		if letter=='T':
			return self.interpretT(num)
开发者ID:pathim,项目名称:xxl-cnc-heissdraht,代码行数:25,代码来源:gcode.py


示例12: parser

def parser():
    global _parser
    if _parser is None:
        ParserElement.setDefaultWhitespaceChars("")
        lbrack, rbrack, lbrace, rbrace, lparen, rparen = map(Literal, "[]{}()")

        reMacro = Combine("\\" + oneOf(list("dws")))
        escapedChar = ~ reMacro + Combine("\\" + oneOf(list(printables)))
        reLiteralChar = "".join(c for c in printables if c not in r"\[]{}().*?+|") + " \t"

        reRange = Combine(lbrack + SkipTo(rbrack, ignore=escapedChar) + rbrack)
        reLiteral = (escapedChar | oneOf(list(reLiteralChar)))
        reDot = Literal(".")
        repetition = (
                      (lbrace + Word(nums).setResultsName("count") + rbrace) |
                      (lbrace + Word(nums).setResultsName("minCount") + "," + Word(nums).setResultsName("maxCount") + rbrace) |
                      oneOf(list("*+?"))
                      )

        reRange.setParseAction(handle_range)
        reLiteral.setParseAction(handle_literal)
        reMacro.setParseAction(handle_macro)
        reDot.setParseAction(handle_dot)

        reTerm = (reLiteral | reRange | reMacro | reDot)
        reExpr = operatorPrecedence(reTerm, [
                (repetition, 1, opAssoc.LEFT, handle_repetition),
                (None, 2, opAssoc.LEFT, handle_sequence),
                (Suppress('|'), 2, opAssoc.LEFT, handle_alternative),
            ])

        _parser = reExpr

    return _parser
开发者ID:Bernie,项目名称:spyne,代码行数:34,代码来源:invregexp.py


示例13: defineConditionSyntax

	def defineConditionSyntax(self):
		num = Combine(Optional(oneOf("+ -")) + Word(nums) + "." +
               Optional(Word(nums)) +
               Optional(oneOf("e E")+Optional(oneOf("+ -")) +Word(nums)))
		op = oneOf("< == > >= <= !=")
		expr = Word(alphanums) + op + num

		return expr
开发者ID:icanos,项目名称:lightswitch,代码行数:8,代码来源:Schema.py


示例14: __init__

    def __init__(self):
        """
        Setup the Backus Normal Form (BNF) parser logic.
        """
        # Set an empty formula attribute
        self.formula = None

        # Instantiate blank parser for BNF construction
        self.bnf = Forward()

        # Expression for parenthesis, which are suppressed in the atoms
        # after matching.
        lpar = Literal(const.LPAR).suppress()
        rpar = Literal(const.RPAR).suppress()

        # Expression for mathematical constants: Euler number and Pi
        e = Keyword(const.EULER)
        pi = Keyword(const.PI)
        null = Keyword(const.NULL)
        _true = Keyword(const.TRUE)
        _false = Keyword(const.FALSE)

        # Prepare operator expressions
        addop = oneOf(const.ADDOP)
        multop = oneOf(const.MULTOP)
        powop = oneOf(const.POWOP)
        unary = reduce(operator.add, (Optional(x) for x in const.UNOP))

        # Expression for floating point numbers, allowing for scientific notation.
        number = Regex(const.NUMBER)

        # Variables are alphanumeric strings that represent keys in the input
        # data dictionary.
        variable = delimitedList(Word(alphanums), delim=const.VARIABLE_NAME_SEPARATOR, combine=True)

        # Functional calls
        function = Word(alphanums) + lpar + self.bnf + rpar

        # Atom core - a single element is either a math constant,
        # a function or a variable.
        atom_core = function | pi | e | null | _true | _false | number | variable

        # Atom subelement between parenthesis
        atom_subelement = lpar + self.bnf.suppress() + rpar

        # In atoms, pi and e need to be before the letters for it to be found
        atom = (
            unary + atom_core.setParseAction(self.push_first) | atom_subelement
        ).setParseAction(self.push_unary_operator)

        # By defining exponentiation as "atom [ ^ factor ]..." instead of
        # "atom [ ^ atom ]...", we get right-to-left exponents, instead of
        # left-to-right that is, 2^3^2 = 2^(3^2), not (2^3)^2.
        factor = Forward()
        factor << atom + ZeroOrMore((powop + factor).setParseAction(self.push_first))

        term = factor + ZeroOrMore((multop + factor).setParseAction(self.push_first))
        self.bnf << term + ZeroOrMore((addop + term).setParseAction(self.push_first))
开发者ID:geodesign,项目名称:django-raster,代码行数:58,代码来源:parser.py


示例15: _string_to_ast

    def _string_to_ast(self, input_string):
        """ Parse a smart search string and return it in an AST like form
        """

        # simple words
        # we need to use a regex to match on words because the regular
        # Word(alphanums) will only match on American ASCII alphanums and since
        # we try to be Unicode / internationally friendly we need to match much
        # much more. Trying to expand a word class to catch it all seems futile
        # so we match on everything *except* a few things, like our operators
        comp_word = Regex("[^*\s=><~!]+")
        word = Regex("[^*\s=><~!]+").setResultsName('word')
        # numbers
        comp_number = Word(nums)
        number = Word(nums).setResultsName('number')

        # IPv4 address
        ipv4_oct = Regex("((2(5[0-5]|[0-4][0-9])|[01]?[0-9][0-9]?))")
        comp_ipv4_address = Combine(ipv4_oct + ('.' + ipv4_oct*3))
        ipv4_address = Combine(ipv4_oct + ('.' + ipv4_oct*3)).setResultsName('ipv4_address')

        # IPv6 address
        ipv6_address = Regex("((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?").setResultsName('ipv6_address')
        ipv6_prefix = Combine(ipv6_address + Regex("/(12[0-8]|1[01][0-9]|[0-9][0-9]?)")).setResultsName('ipv6_prefix')

        # VRF RTs of the form number:number
        vrf_rt = Combine((comp_ipv4_address | comp_number) + Literal(':') + comp_number).setResultsName('vrf_rt')

        # tags
        tags = Combine( Literal('#') + comp_word).setResultsName('tag')

        # operators for matching
        match_op = oneOf(' '.join(self.match_operators)).setResultsName('operator')
        boolean_op = oneOf(' '.join(self.boolean_operators)).setResultsName('boolean')
        # quoted string
        d_quoted_string = QuotedString('"', unquoteResults=True, escChar='\\')
        s_quoted_string = QuotedString('\'', unquoteResults=True, escChar='\\')
        quoted_string = (s_quoted_string | d_quoted_string).setResultsName('quoted_string')
        # expression to match a certain value for an attribute
        expression = Group(word + match_op + (quoted_string | vrf_rt | word | number)).setResultsName('expression')
        # we work on atoms, which are single quoted strings, match expressions,
        # tags, VRF RT or simple words.
        # NOTE: Place them in order of most exact match first!
        atom = Group(ipv6_prefix | ipv6_address | quoted_string | expression | tags | vrf_rt | boolean_op | word)

        enclosed = Forward()
        parens = nestedExpr('(', ')', content=enclosed)
        enclosed << (
                parens | atom
                ).setResultsName('nested')

        content = Forward()
        content << (
                ZeroOrMore(enclosed)
                )

        res = content.parseString(input_string)
        return res
开发者ID:fredsod,项目名称:NIPAP,代码行数:58,代码来源:smart_parsing.py


示例16: expression

    def expression(self):
        from pyparsing import Suppress,Combine,Optional,oneOf,OneOrMore,Word,nums,Group,alphas,alphanums,Literal,SkipTo,empty,lineEnd
        cvtInt = lambda toks: int(toks[0])
        cvtReal = lambda toks: float(toks[0])
        cvtTuple = lambda toks : tuple(toks.asList())
        nameJoin = lambda toks : "".join([tok.replace("#","") for tok in toks[0]])
        #lambda toks: " ".join([str(t) for t in toks[0]])
        
        # define punctuation as suppressed literals
        lparen,rparen,lbrack,rbrack,lbrace,rbrace,colon = map(Suppress,"()[]{}:")

        integer = Combine(Optional(oneOf("+ -")) + Word(nums))\
            .setName("integer")\
            .setParseAction( cvtInt )
        real = Combine(Optional(oneOf("+ -")) + Word(nums) + "." +
                       Optional(Word(nums)) +
                       Optional(oneOf("e E")+Optional(oneOf("+ -")) +Word(nums))).setName("real").setParseAction( cvtReal )

        # TREE DEFINITION
        # ((seq2: 0.537243, seq1: 0.000004): 0.255741, seq3: 0.281503);
        tree_w_branches = (
            OneOrMore(Word("():,."+alphas+nums))+Literal(";")
            ).setParseAction(lambda tokens: " ".join(tokens[:-1])+";")

        # SITE PROBABILITIES
        # site Freq Data:
        # 1    1    AAA: A(0.978) A(1.000)
        site_prob = (
            integer.setResultsName("site",listAllMatches=True) + 
            integer.setResultsName("freq",listAllMatches=True) + 
            Word(alphas+"-").setResultsName("extant",listAllMatches=True) + colon + 
            Group(OneOrMore(Group(Word(alphas,exact=1)+lparen+real+rparen))).setResultsName("probability",listAllMatches=True) +
            lineEnd
            )

        # ANCESTRAL SEQUENCES
        # seq1       ACC
        # node #4    ACC
        # Optional # character with node # needs to be joined into a single name
        sequence =  (
                     Group(Word(alphanums)+
                           Optional(Combine(Literal("#")+Word(nums)))).setParseAction(nameJoin).setResultsName("name",listAllMatches=True)+
                           Word(alphas+"- ").setResultsName("sequence", listAllMatches=True)+lineEnd
                    )
                     
        
        return (SkipTo(Literal("Ancestral reconstruction by AAML."),include=True).suppress() +
                tree_w_branches.setResultsName("tree") +
                SkipTo(Literal("site")+Literal("Freq")+Literal("Data:"), include=True,).suppress()+
                Group(OneOrMore(site_prob)).setResultsName("sites")+
                SkipTo(Literal("List of extant and reconstructed sequences")+Word(nums)+Word(nums), include=True).suppress()+
                Group(OneOrMore(sequence)).setResultsName("sequences")+
                SkipTo(Literal("for a site."),include=True).suppress()+
                Group(OneOrMore(real)).setResultsName("probability")+
                empty
                )
开发者ID:bsmithers,项目名称:hpf,代码行数:56,代码来源:paml.py


示例17: _getPattern

    def _getPattern(self):
        arith_expr = Forward()
        comp_expr = Forward()
        logic_expr = Forward()
        LPAR, RPAR, SEMI = map(Suppress, "();")
        identifier = Word(alphas+"_", alphanums+"_")
        multop = oneOf('* /')
        plusop = oneOf('+ -')
        expop = Literal( "^" )
        compop = oneOf('> < >= <= != ==')
        andop = Literal("AND")
        orop = Literal("OR")
        current_value = Literal( "." )
        assign = Literal( "=" )
        # notop = Literal('NOT')
        function = oneOf(' '.join(self.FUNCTIONS))
        function_call = Group(function.setResultsName('fn') + LPAR + Optional(delimitedList(arith_expr)) + RPAR)
        aggregate_column = QuotedString(quoteChar='{', endQuoteChar='}')
        single_column = QuotedString(quoteChar='[', endQuoteChar=']')
        integer = Regex(r"-?\d+")
        real = Regex(r"-?\d+\.\d*")

        # quotedString enables strings without quotes to pass

        operand = \
            function_call.setParseAction(self.__evalFunction) | \
            aggregate_column.setParseAction(self.__evalAggregateColumn) | \
            single_column.setParseAction(self.__evalSingleColumn) | \
            ((real | integer).setParseAction(self.__evalConstant)) | \
            quotedString.setParseAction(self.__evalString).addParseAction(removeQuotes) | \
            current_value.setParseAction(self.__evalCurrentValue) | \
            identifier.setParseAction(self.__evalString)

        arith_expr << operatorPrecedence(operand,
            [
             (expop, 2, opAssoc.LEFT, self.__expOp),
             (multop, 2, opAssoc.LEFT, self.__multOp),
             (plusop, 2, opAssoc.LEFT, self.__addOp),
            ])

        # comp_expr = Group(arith_expr + compop + arith_expr)
        comp_expr << operatorPrecedence(arith_expr,
            [
                (compop, 2, opAssoc.LEFT, self.__evalComparisonOp),
            ])

        logic_expr << operatorPrecedence(comp_expr,
            [
                (andop, 2, opAssoc.LEFT, self.__evalLogicOp),
                (orop, 2, opAssoc.LEFT, self.__evalLogicOp)
            ])

        pattern = logic_expr + StringEnd()
        return pattern
开发者ID:ArnoldOchieng,项目名称:echo-sense,代码行数:54,代码来源:expressionParser.py


示例18: getrule

def getrule():
    """
    Using pyparsing, get rule out of a string.
    """
    arrow = pp.Literal("==>")
    buff = pp.Word(pp.alphas, "".join([pp.alphanums, "_"]))
    special_valueLHS = pp.oneOf([x for x in _LHSCONVENTIONS.keys()])
    end_buffer = pp.Literal(">")
    special_valueRHS = pp.oneOf([x for x in _RHSCONVENTIONS.keys()])
    chunk = getchunk()
    rule_reader = pp.Group(pp.OneOrMore(pp.Group(special_valueLHS + buff + end_buffer + pp.Group(pp.Optional(chunk))))) + arrow + pp.Group(pp.OneOrMore(pp.Group(special_valueRHS + buff + end_buffer + pp.Group(pp.Optional(chunk)))))
    return rule_reader
开发者ID:jakdot,项目名称:pyactr,代码行数:12,代码来源:utilities.py


示例19: _makeGrammar

def _makeGrammar():
    """
    Define the simple string selector grammar using PyParsing
    """
    
    #float definition
    point = Literal('.')
    plusmin = Literal('+') | Literal('-')
    number = Word(nums)
    integer = Combine(Optional(plusmin) + number)
    floatn = Combine(integer + Optional(point + Optional(number)))
    
    #vector definition
    lbracket = Literal('(')
    rbracket = Literal(')')
    comma = Literal(',')
    vector = Combine(lbracket + floatn('x') + comma + \
                     floatn('y') + comma + floatn('z') + rbracket)
    
    #direction definition
    simple_dir = oneOf(['X','Y','Z','XY','XZ','YZ'])
    direction = simple_dir('simple_dir') | vector('vector_dir')
    
    #CQ type definition
    cqtype = oneOf(['Plane','Cylinder','Sphere','Cone','Line','Circle','Arc'],
                   caseless=True)
    cqtype = cqtype.setParseAction(upcaseTokens)
    
    #type operator        
    type_op = Literal('%')
    
    #direction operator
    direction_op = oneOf(['>','<'])
    
    #index definition
    ix_number = Group(Optional('-')+Word(nums))
    lsqbracket = Literal('[').suppress()
    rsqbracket = Literal(']').suppress()
    
    index = lsqbracket + ix_number('index') + rsqbracket
    
    #other operators
    other_op = oneOf(['|','#','+','-'])
    
    #named view
    named_view = oneOf(['front','back','left','right','top','bottom'])
    
    return direction('only_dir') | \
           (type_op('type_op') + cqtype('cq_type')) | \
           (direction_op('dir_op') + direction('dir') + Optional(index)) | \
           (other_op('other_op') + direction('dir')) | \
           named_view('named_view')
开发者ID:adam-urbanczyk,项目名称:cadquery,代码行数:52,代码来源:selectors.py


示例20: __init__

    def __init__(self, EvaluateVariableChild=None, EvaluateNumberChild=None):
        EvaluateVariableChild = EvaluateVariableChild or EvaluateVariable
        EvaluateNumberChild = EvaluateNumberChild or EvaluateNumber
        # what is a float number
        floatNumber = Regex(r'[-]?\d+(\.\d*)?([eE][-+]?\d+)?')
        # a variable is a combination of letters, numbers, and underscor
        variable = Word(alphanums + "_")
        # a sign is plus or minus
        signOp = oneOf('+ -')
        # an operand is a variable or a floating point number
        operand = floatNumber ^ variable
        # when a floatNumber is found, parse it with evaluate number
        floatNumber.setParseAction(EvaluateNumberChild)
        # when a variable is found, parse it with the EvaluateVariableChild
        # or EvaluateVariable
        variable.setParseAction(EvaluateVariableChild)
        # comparisons include lt,le,gt,ge,eq,ne
        comparisonOp = oneOf("< <= > >= == !=")
        # negation of the boolean is !
        notOp = oneOf("!")
        # an expression is a either a comparison or
        # a NOT operation (where NOT a is essentially (a == False))
        comparisonExpression = operatorPrecedence(operand,
                                                  [
                                                   (comparisonOp,
                                                    2,
                                                    opAssoc.LEFT,
                                                    EvaluateComparison
                                                    ),
                                                   (notOp,
                                                    1,
                                                    opAssoc.RIGHT,
                                                    EvaluateNot
                                                    ),
                                                  ])

        # boolean logic of AND or OR
        boolOp = oneOf("& |")

        # a bool expression contains a nested bool expression or a comparison,
        # joined with a boolean operation
        boolExpression = Forward()
        boolPossible = boolExpression | comparisonExpression
        self.boolExpression = operatorPrecedence(boolPossible,
                                                 [
                                                  (boolOp,
                                                   2,
                                                   opAssoc.RIGHT,
                                                   EvaluateOrAn 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyparsing.operatorPrecedence函数代码示例发布时间:2022-05-27
下一篇:
Python pyparsing.nestedExpr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap