當前位置: 首頁>>代碼示例>>Python>>正文


Python pyparsing.alphanums方法代碼示例

本文整理匯總了Python中pyparsing.alphanums方法的典型用法代碼示例。如果您正苦於以下問題:Python pyparsing.alphanums方法的具體用法?Python pyparsing.alphanums怎麽用?Python pyparsing.alphanums使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyparsing的用法示例。


在下文中一共展示了pyparsing.alphanums方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def parse(input_string):
        word = Word(alphanums)
        command = Group(OneOrMore(word))
        token = Suppress("->")
        device = Group(OneOrMore(word))
        argument = Group(OneOrMore(word))
        event = command + token + device + Optional(token + argument)
        parse_results = event.parseString(input_string)
        cmd = parse_results[0]
        dev = parse_results[1]
        cmd_str = "_".join(cmd)
        dev_str = "_".join(dev)
        try:
            val = parse_results[2]
        except IndexError:
            val_str = None
        else:
            val_str = "_".join(val)
        return cmd_str, dev_str, val_str 
開發者ID:jackdbd,項目名稱:design-patterns,代碼行數:21,代碼來源:interpreter.py

示例2: grammar

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def grammar():
    parenthesis = Forward()
    parenthesis <<= "(" + ZeroOrMore(CharsNotIn("()") | parenthesis) + ")"

    field_def = OneOrMore(Word(alphanums + "_\"'`:-") | parenthesis)
    field_def.setParseAction(field_act)

    tablename_def = ( Word(alphas + "`_") | QuotedString("\"") )

    field_list_def = field_def + ZeroOrMore(Suppress(",") + field_def)
    field_list_def.setParseAction(field_list_act)

    create_table_def = Literal("CREATE") + "TABLE" + tablename_def.setResultsName("tableName") + "(" + field_list_def.setResultsName("fields") + ")" + ";"
    create_table_def.setParseAction(create_table_act)

    add_fkey_def = Literal("FOREIGN") + "KEY" + "(" + Word(alphanums).setResultsName("keyName") + ")" + "REFERENCES" + Word(alphanums).setResultsName("fkTable") + "(" + Word(alphanums + "_").setResultsName("fkCol") + ")" + Optional(Literal("DEFERRABLE")) + ";"
    add_fkey_def.setParseAction(add_fkey_act)

    other_statement_def = OneOrMore(CharsNotIn(";")) + ";"
    other_statement_def.setParseAction(other_statement_act)

    comment_def = "--" + ZeroOrMore(CharsNotIn("\n"))
    comment_def.setParseAction(other_statement_act)

    return OneOrMore(comment_def | create_table_def | add_fkey_def | other_statement_def) 
開發者ID:LGE-ARC-AdvancedAI,項目名稱:auptimizer,代碼行數:27,代碼來源:sql_graphviz.py

示例3: parse

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def parse(self, flags):
        _flags = []
        for k, v in flags.items():
            if v == True:
                _flags.append(k)
            elif v in [False, None]:
                pass
            else:
                _flags.append(k + "_" + v)

        def cb_conditional(s, l, t):
            if (t.cond in _flags) != (t.negate == "!"):
                return t.expr
            else:
                return []

        word = Word(alphanums + ":<>.[]_-,=~/^~")
        conditional = Forward()
        conditional << (
            Optional("!")("negate")
            + word("cond")
            + Suppress("?")
            + Suppress("(")
            + OneOrMore(conditional ^ word)("expr")
            + Suppress(")")
        ).setParseAction(cb_conditional)
        string = word
        string_list = OneOrMore(conditional ^ string)
        s = " ".join(string_list.parseString(self.__str__()))
        logger.debug(
            "Parsing '{}' with flags {} => {}".format(self.__str__(), str(_flags), s)
        )
        return s 
開發者ID:olofk,項目名稱:fusesoc,代碼行數:35,代碼來源:core.py

示例4: static_function

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def static_function(self):
        return (
            (pyparsing.Keyword("static") | pyparsing.Keyword("inline"))
            + pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums + "_*&"))
            + parsers.anything_in_parentheses()
            + parsers.anything_in_curly()
        ).suppress() 
開發者ID:google,項目名稱:rekall,代碼行數:9,代碼來源:preprocessing_parser.py

示例5: _cast_transformer

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def _cast_transformer(self):
        """Removes obvious casts."""
        return pyparsing.Combine(
            pyparsing.Regex(r"\([^()]*\)").suppress()
            + (pyparsing.Word(pyparsing.alphanums + "_")
               | pyparsing.Literal("(")),
            adjacent=False) 
開發者ID:google,項目名稱:rekall,代碼行數:9,代碼來源:expression_parser.py

示例6: _type_property

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def _type_property(self):
        return (
            _TYPE_PROPERTY_KEYWORD
            + _OPEN_PARENTHESIS
            + pyparsing.Word(pyparsing.alphanums + ' _*[]')
            + _CLOSE_PARENTHESIS
        ).setParseAction(self._create_sizeof_type) 
開發者ID:google,項目名稱:rekall,代碼行數:9,代碼來源:expression_parser.py

示例7: XXXX_cast_expression

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def XXXX_cast_expression(self):
        """A function returning a parser for parsing cast expressions.

        Args:
            expression: a pyparsing parser for parsing an expression to be cast.

        Returns:
            A (pyparsing) parser for parsing cast expressions.
        """
        word = pyparsing.Word(pyparsing.alphanums + '_*[]')
        nested = pyparsing.Forward().setName("nested")
        nested << pyparsing.Combine(
            pyparsing.Literal('(').suppress()
            + pyparsing.Combine(
                pyparsing.ZeroOrMore(self._integer() | word | nested))
            + pyparsing.Literal(')').suppress()
        )
        typeof_expression = (
            _OPEN_PARENTHESIS
            + pyparsing.Keyword('typeof')
            + nested("typeof_arg")
            + _CLOSE_PARENTHESIS
        )

        type_expression = (
            typeof_expression
            | nested("simple_type")
        )
        return (
            type_expression
            + ~(_PLUS | _MINUS)
            + self.expression("expression")
        ).setParseAction(self._create_cast_expression) 
開發者ID:google,項目名稱:rekall,代碼行數:35,代碼來源:expression_parser.py

示例8: _identifier_with_dots

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def _identifier_with_dots(self):
        return pyparsing.Word(
            pyparsing.alphas + '_.', pyparsing.alphanums + '_.') 
開發者ID:google,項目名稱:rekall,代碼行數:5,代碼來源:expression_parser.py

示例9: identifier

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def identifier():
    return pyparsing.Word(pyparsing.alphas + '_', pyparsing.alphanums + '_') 
開發者ID:google,項目名稱:rekall,代碼行數:4,代碼來源:parsers.py

示例10: __init__

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def __init__(self):
        # create parsing grammer
        sQStringLiteral = pyparsing.QuotedString("'")
        sQStringLiteral.setParseAction(
            lambda s, loc, toks: StringLiteral(s, loc, toks, False))

        dQStringLiteral = pyparsing.QuotedString('"', '\\')
        dQStringLiteral.setParseAction(
            lambda s, loc, toks: StringLiteral(s, loc, toks, True))

        stringLiteral = sQStringLiteral | dQStringLiteral

        functionCall = pyparsing.Forward()
        functionArg = stringLiteral | functionCall
        functionCall << pyparsing.Word(pyparsing.alphas, pyparsing.alphanums+'-') + \
            pyparsing.Suppress('(') + \
            pyparsing.Optional(functionArg +
                pyparsing.ZeroOrMore(pyparsing.Suppress(',') + functionArg)) + \
            pyparsing.Suppress(')')
        functionCall.setParseAction(
            lambda s, loc, toks: FunctionCall(s, loc, toks))

        predExpr = pyparsing.infixNotation(
            stringLiteral ^ functionCall ,
            [
                ('!',  1, pyparsing.opAssoc.RIGHT, lambda s, loc, toks: NotOperator(s, loc, toks)),
                ('<',  2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('<=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('>',  2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('>=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('==', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('!=', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryStrOperator)),
                ('&&', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryBoolOperator)),
                ('||', 2, pyparsing.opAssoc.LEFT,  infixBinaryOp(BinaryBoolOperator))
            ])

        self.__ifgrammer = predExpr 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:39,代碼來源:stringparser.py

示例11: __parse_tc_filter_network

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def __parse_tc_filter_network(text):
        network_pattern = pp.SkipTo("{:s}=".format(Tc.Param.DST_NETWORK), include=True) + pp.Word(
            pp.alphanums + "." + "/"
        )

        return network_pattern.parseString(text)[-1] 
開發者ID:thombashi,項目名稱:tcconfig,代碼行數:8,代碼來源:_importer.py

示例12: __init__

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def __init__(self):
        if PYPARSING:
            category = Word(alphas + "_-*", alphanums + "_-*")
            operator = oneOf("and or ,")
            neg_operator = "not"
            elementRef = category
            definition = elementRef + ZeroOrMore(operator + elementRef)
            nestedformula = Group(Suppress(Optional(Literal("("))) + definition + Suppress(Optional(Literal(")"))))
            neg_nestedformula = Optional(neg_operator) + nestedformula
            self.finalformula = neg_nestedformula + ZeroOrMore(operator + neg_nestedformula)

            elementRef.setParseAction(self.__compute_element)
            neg_nestedformula.setParseAction(self.__compute_neg_formula)
            nestedformula.setParseAction(self.__compute_formula)
            self.finalformula.setParseAction(self.__myreduce) 
開發者ID:xmendez,項目名稱:wfuzz,代碼行數:17,代碼來源:modulefilter.py

示例13: getchunk

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def getchunk():
    """
    Using pyparsing, create chunk reader for chunk strings.
    """
    slot = pp.Word("".join([pp.alphas, "_"]), "".join([pp.alphanums, "_"]))
    special_value = pp.Group(pp.oneOf([ACTRVARIABLE, "".join([ACTRNEG, ACTRVARIABLE]), ACTRNEG, VISIONGREATER, VISIONSMALLER, "".join([VISIONGREATER, ACTRVARIABLE]), "".join([VISIONSMALLER, ACTRVARIABLE])])\
            + pp.Word("".join([pp.alphanums, "_", '"', "'"])))
    strvalue = pp.QuotedString('"', unquoteResults=False)
    strvalue2 = pp.QuotedString("'", unquoteResults=False)
    varvalue = pp.Word("".join([pp.alphanums, "_"]))
    value = varvalue | special_value | strvalue | strvalue2
    chunk_reader = pp.OneOrMore(pp.Group(slot + value))
    return chunk_reader 
開發者ID:jakdot,項目名稱:pyactr,代碼行數:15,代碼來源:utilities.py

示例14: getrule

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
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,代碼行數:14,代碼來源:utilities.py

示例15: parser

# 需要導入模塊: import pyparsing [as 別名]
# 或者: from pyparsing import alphanums [as 別名]
def parser(self):
        """
        This function returns a parser.
        The grammar should be like most full text search engines (Google, Tsearch, Lucene).
        
        Grammar:
        - a query consists of alphanumeric words, with an optional '*' wildcard
          at the end of a word
        - a sequence of words between quotes is a literal string
        - words can be used together by using operators ('and' or 'or')
        - words with operators can be grouped with parenthesis
        - a word or group of words can be preceded by a 'not' operator
        - the 'and' operator precedes an 'or' operator
        - if an operator is missing, use an 'and' operator
        """
        operatorOr = Forward()
        
        operatorWord = Group(Combine(Word(alphanums) + Suppress('*'))).setResultsName('wordwildcard') | \
                            Group(Word(alphanums)).setResultsName('word')
        
        operatorQuotesContent = Forward()
        operatorQuotesContent << (
            (operatorWord + operatorQuotesContent) | operatorWord
        )
        
        operatorQuotes = Group(
            Suppress('"') + operatorQuotesContent + Suppress('"')
        ).setResultsName("quotes") | operatorWord
        
        operatorParenthesis = Group(
            (Suppress("(") + operatorOr + Suppress(")"))
        ).setResultsName("parenthesis") | operatorQuotes

        operatorNot = Forward()
        operatorNot << (Group(
            Suppress(Keyword("not", caseless=True)) + operatorNot
        ).setResultsName("not") | operatorParenthesis)

        operatorAnd = Forward()
        operatorAnd << (Group(
            operatorNot + Suppress(Keyword("and", caseless=True)) + operatorAnd
        ).setResultsName("and") | Group(
            operatorNot + OneOrMore(~oneOf("and or") + operatorAnd)
        ).setResultsName("and") | operatorNot)
        
        operatorOr << (Group(
            operatorAnd + Suppress(Keyword("or", caseless=True)) + operatorOr
        ).setResultsName("or") | operatorAnd)

        return operatorOr.parseString 
開發者ID:nil0x42,項目名稱:phpsploit,代碼行數:52,代碼來源:searchparser.py


注:本文中的pyparsing.alphanums方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。