當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。