当前位置: 首页>>代码示例>>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;未经允许,请勿转载。