本文整理汇总了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
示例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
示例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)
示例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)
示例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
示例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)
示例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("+"))
示例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)
示例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__([])
示例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
示例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
示例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))
示例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
示例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()]
示例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