当前位置: 首页>>代码示例>>Python>>正文


Python pyparsing.Literal方法代码示例

本文整理汇总了Python中pyparsing.Literal方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.Literal方法的具体用法?Python pyparsing.Literal怎么用?Python pyparsing.Literal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing的用法示例。


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

示例1: _collect_from_leaves

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def _collect_from_leaves(e, backtrack):
    result = []
    look_further = True
    for leaf in e.leaves:
        if isinstance(leaf, Dictation):
            # Add regex for a single dictation word.
            result.append(_word_regex_str)
        elif isinstance(leaf, Literal):
            # Add first word of literal.
            result.append(leaf.text.split()[0])
        else:
            # Skip references.
            continue

        # Break out of the loop if the leaf is required.
        if not leaf.is_optional:
            if not backtrack:
                look_further = False
            break
    return result, look_further 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:22,代码来源:expansions.py

示例2: _build_precedence

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def _build_precedence(self, precedence_table):
        # C's & dereference operator.
        precedence = []
        for operators, arity, associativity in precedence_table:
            operators = [pyparsing.Literal(x) for x in operators]

            if arity in [_UNARY, _BINARY]:
                operators = pyparsing.Or(operators)

            precedence.append((
                operators,
                arity,
                associativity,
                self._construct_operator(arity),
            ))
        return precedence 
开发者ID:google,项目名称:rekall,代码行数:18,代码来源:expression_parser.py

示例3: anything_beetween

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def anything_beetween(opener_and_closer):
    """Builds a (pyparsing) parser for the content inside delimiters.

    Args:
    opener_and_closer: a string containing two elements: opener and closer

    Returns:
      A (pyparsing) parser for the content inside delimiters.
    """
    opener = pyparsing.Literal(opener_and_closer[0])
    closer = pyparsing.Literal(opener_and_closer[1])
    char_removal_mapping = dict.fromkeys(map(ord, opener_and_closer))
    other_chars = unicode(string.printable).translate(char_removal_mapping)
    word_without_delimiters = pyparsing.Word(other_chars).setName(
        "other_chars")
    anything = pyparsing.Forward()
    delimited_block = opener + anything + closer
    # pylint: disable=expression-not-assigned
    anything << pyparsing.ZeroOrMore(
        word_without_delimiters.setName("word_without_delimiters")
        | delimited_block.setName("delimited_block")
    )

    # Combine all the parts into a single string.
    return pyparsing.Combine(anything) 
开发者ID:google,项目名称:rekall,代码行数:27,代码来源:parsers.py

示例4: anything_beetween

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def anything_beetween(opener_and_closer):
    """Builds a (pyparsing) parser for the content inside delimiters.

    Args:
    opener_and_closer: a string containing two elements: opener and closer

    Returns:
      A (pyparsing) parser for the content inside delimiters.
    """
    opener = pyparsing.Literal(opener_and_closer[0])
    closer = pyparsing.Literal(opener_and_closer[1])
    char_removal_mapping = dict.fromkeys(list(map(ord, opener_and_closer)))
    other_chars = str(string.printable).translate(char_removal_mapping)
    word_without_delimiters = pyparsing.Word(other_chars).setName(
        "other_chars")
    anything = pyparsing.Forward()
    delimited_block = opener + anything + closer
    # pylint: disable=expression-not-assigned
    anything << pyparsing.ZeroOrMore(
        word_without_delimiters.setName("word_without_delimiters")
        | delimited_block.setName("delimited_block")
    )

    # Combine all the parts into a single string.
    return pyparsing.Combine(anything) 
开发者ID:google,项目名称:rekall,代码行数:27,代码来源:yara_support.py

示例5: _parse_filter

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def _parse_filter():
        op = pyparsing.oneOf('! & |')
        lpar  = pyparsing.Literal('(').suppress()
        rpar  = pyparsing.Literal(')').suppress()

        k = pyparsing.Word(pyparsing.alphanums)
        # NOTE: We may need to expand on this list, but as this is not a real
        # LDAP server we should be OK.
        # Value to contain:
        #   numbers, upper/lower case letters, astrisk, at symbol, minus, full
        #   stop, backslash or a space
        v = pyparsing.Word(pyparsing.alphanums + "-*@.\\ äöü")
        rel = pyparsing.oneOf("= ~= >= <=")

        expr = pyparsing.Forward()
        atom = pyparsing.Group(lpar + op + expr + rpar) \
                            | pyparsing.Combine(lpar + k + rel + v + rpar)
        expr << atom + pyparsing.ZeroOrMore( expr )

        return expr 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:ldap3mock.py

示例6: grammar

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [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

示例7: _parse_duplicate

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def _parse_duplicate(self, line: str) -> Optional[int]:
        if not self._is_support_packet_duplicate:
            return None

        packet_pattern = (
            pp.SkipTo(pp.Word("+" + pp.nums) + pp.Literal("duplicates,"))
            + pp.Word("+" + pp.nums)
            + pp.Literal("duplicates,")
        )

        try:
            duplicate_parse_list = packet_pattern.parseString(_to_unicode(line))
        except pp.ParseException:
            return 0

        return int(duplicate_parse_list[-2].strip("+")) 
开发者ID:thombashi,项目名称:pingparsing,代码行数:18,代码来源:_parser.py

示例8: make_expansion

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def make_expansion(e):
        """
        Take an object, turn it into an Expansion if it isn't one and return it.

        :param e: str | Expansion
        :returns: Expansion
        """
        if isinstance(e, Expansion):
            return e
        elif isinstance(e, string_types):
            return Literal(e)
        else:
            raise TypeError("expected a string or Expansion, got %s instead"
                            % e) 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:16,代码来源:expansions.py

示例9: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def __init__(self, text, case_sensitive=False):
        # Set _text and use the text setter to validate the input.
        self._text = ""
        self.text = text
        self._case_sensitive = bool(case_sensitive)
        super(Literal, self).__init__([]) 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:8,代码来源:expansions.py

示例10: case_sensitive

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def case_sensitive(self):
        """
        Case sensitivity used when matching and compiling :class:`Literal` rule
        expansions.

        This property can be ``True`` or ``False``. Matching and compilation will
        be *case-sensitive* if ``True`` and *case-insensitive* if ``False``. The
        default value is ``False``.

        :rtype: bool
        :returns: literal case sensitivity
        """
        return self._case_sensitive 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:15,代码来源:expansions.py

示例11: compile

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def compile(self, ignore_tags=False):
        super(Literal, self).compile()
        if self.tag and not ignore_tags:
            return "%s%s" % (self.text, self.compiled_tag)
        else:
            return self.text 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:8,代码来源:expansions.py

示例12: _make_matcher_element

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def _make_matcher_element(self):
        # Return a case-sensitive or case-insensitive pyparsing Literal element.
        text = self._text
        if self.case_sensitive:
            matcher_cls = pyparsing.Literal
        else:
            matcher_cls = pyparsing.CaselessLiteral
        return self._set_matcher_element_attributes(matcher_cls(text)) 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:10,代码来源:expansions.py

示例13: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def __init__(self):
        # Pass the empty string to the Literal constructor so that calling compile
        # yields "" or "" + the tag
        super(Dictation, self).__init__("")
        self._use_current_match = False 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:7,代码来源:expansions.py

示例14: parse_line

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def parse_line(attribute, string):

    Grammar = Suppress(Keyword('mpc.{}'.format(attribute)) + Keyword('=')) + String('data') + Suppress(Literal(';') + Optional(Comments))
    result, i, j = Grammar.scanString(string).next()

    return [int_else_float_except_string(s) for s in result['data'].asList()] 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:8,代码来源:case_parser.py

示例15: parse_table

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Literal [as 别名]
def parse_table(attribute, string):
    Line = OneOrMore(Float)('data') + Literal(';') + Optional(Comments, default='')('name')
    Grammar = Suppress(Keyword('mpc.{}'.format(attribute)) + Keyword('=') + Keyword('[') + Optional(Comments)) + OneOrMore(Group(Line)) + Suppress(Keyword(']') + Optional(Comments))

    result, i, j = Grammar.scanString(string).next()

    _list = list()
    for r in result:
        _list.append([int_else_float_except_string(s) for s in r['data'].asList()])

    return _list 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:13,代码来源:case_parser.py


注:本文中的pyparsing.Literal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。