本文整理汇总了Python中pyparsing.ZeroOrMore方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.ZeroOrMore方法的具体用法?Python pyparsing.ZeroOrMore怎么用?Python pyparsing.ZeroOrMore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing
的用法示例。
在下文中一共展示了pyparsing.ZeroOrMore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _type_reference
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _type_reference(self):
"""A reference to a type.
The type may be already defined in place or just referred by name.
"""
identifier = (
self._typeof_expression()
# Inline struct definition.
# e.g. struct { int x; } foo;
| self._struct_definition_possibly_with_fields()
| self._enum_definition()
| self._numeric_type_identifier()
| self._compound_type_identifier()
| self._identifier()
)
return (
pyparsing.ZeroOrMore(_VOLATILE)
+ identifier
).setParseAction(self._create_type_reference)
示例2: _maybe_attributes
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _maybe_attributes(self):
"""Possibly match some attributes.
The syntax of attributes is described here:
https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
"""
return pyparsing.Group(
pyparsing.ZeroOrMore(
_ATTRIBUTE
+ _DOUBLE_OPEN_PARENTHESIS
+ pyparsing.delimitedList(
pyparsing.Group(
self._identifier()("name")
+ pyparsing.Optional(
_OPEN_PARENTHESIS
+ parsers.anything_beetween("()")("args")
+ _CLOSE_PARENTHESIS
)
)
)
+ _DOUBLE_CLOSE_PARENTHESIS
).setParseAction(self._make_attribute)
)("attributes")
示例3: anything_beetween
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [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 ZeroOrMore [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 ZeroOrMore [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 ZeroOrMore [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: _apply_modifiers
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _apply_modifiers(rule, modifiers):
if 'grouped' in modifiers:
rule = pp.Group(rule)
if 'optional' in modifiers:
rule = pp.Optional(rule)
else:
for modifier in modifiers:
if modifier.startswith('at_least'):
times = rule_at_least.parseString(modifier)[0]
if times > 0:
rule_multiple = rule
for _ in range(1, times):
rule_multiple = rule_multiple + rule
rule = rule_multiple + pp.ZeroOrMore(rule)
else:
rule = pp.Optional(pp.ZeroOrMore(rule))
return rule
示例8: _parse
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _parse(mystr):
LBRACE, RBRACE, EQUAL = map(pp.Suppress, "{}=")
field = pp.Word(pp.printables + ' ', excludeChars='[]=')
field.addParseAction(pp.tokenMap(str.rstrip))
string = pp.dblQuotedString().setParseAction(pp.removeQuotes)
number = pp.pyparsing_common.number()
date_expr = pp.Regex(r'\d\d\d\d-\d\d-\d\d')
time_expr = pp.Regex(r'\d\d:\d\d:\d\d\.\d\d\d')
nan = pp.Keyword('nan')
scalar_value = (string | date_expr | time_expr | number | nan)
list_marker = pp.Suppress("[]")
value_list = pp.Forward()
jobject = pp.Forward()
memberDef1 = pp.Group(field + EQUAL + scalar_value)
memberDef2 = pp.Group(field + EQUAL + jobject)
memberDef3 = pp.Group(field + list_marker + EQUAL + LBRACE + value_list +
RBRACE)
memberDef = memberDef1 | memberDef2 | memberDef3
value_list <<= (pp.delimitedList(scalar_value, ",") |
pp.ZeroOrMore(pp.Group(pp.Dict(memberDef2))))
value_list.setParseAction(lambda t: [pp.ParseResults(t[:])])
members = pp.OneOrMore(memberDef)
jobject <<= pp.Dict(LBRACE + pp.ZeroOrMore(memberDef) + RBRACE)
# force empty jobject to be a dict
jobject.setParseAction(lambda t: t or {})
parser = members
parser = pp.OneOrMore(pp.Group(pp.Dict(memberDef)))
return parser.parseString(mystr)
示例9: _make_matcher_element
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _make_matcher_element(self):
# Define an extra parse action for the child's matcher element.
def f(tokens):
if tokens.asList():
# Add current match values to the _repetitions_matched list.
self._repetitions_matched.append(save_current_matches(self.child))
# Wipe current match values for the next repetition (if any).
self.child.reset_for_new_match()
return tokens
# Get the child's matcher element and add the extra parse action.
child_element = self.child.matcher_element.addParseAction(f)
# Determine the parser element type to use.
type_ = pyparsing.ZeroOrMore if self.is_optional else pyparsing.OneOrMore
# Handle the special case of a repetition ancestor, e.g. ((a b)+)+
rep = self.repetition_ancestor
if rep:
# Check if there are no other branches.
c = rep.child
only_branch = True
while c is not self:
if len(c.children) > 1:
only_branch = False
break
else:
c = c.children[0]
# Use an And element instead if self is the only branch because
# it makes no sense to repeat a repeat like this!
if only_branch:
type_ = pyparsing.And
child_element = [child_element]
return self._set_matcher_element_attributes(type_(child_element))
示例10: _base_or_array_expression
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _base_or_array_expression(self):
array_indices = pyparsing.ZeroOrMore(
_OPEN_BRACKETS
+ self.expression
+ _CLOSE_BRACKETS
)
return (
self._base_expression()
+ pyparsing.Group(array_indices)
).setParseAction(self._create_base_or_array_expression)
示例11: XXXX_cast_expression
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [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)
示例12: _integer
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _integer(self):
integer = self._hexadecimal_as_string() | self._decimal_as_string()
# Python does not care about suffixes so we just drop them.
possible_suffix = pyparsing.Literal('u') | 'U' | 'll' | 'LL' | 'l' | 'L'
maybe_suffix = (
pyparsing.ZeroOrMore(possible_suffix)
).suppress()
return (
integer
+ maybe_suffix
).setParseAction(util.action(lambda x: int(x, base=0)))
示例13: _program
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _program(self):
return pyparsing.ZeroOrMore(
self._element()
| self._typedef()
).setParseAction(self._make_prog)
示例14: _enum_definition
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [as 别名]
def _enum_definition(self):
"""Detect an enum definition.
e.g.
enum foo {
OPTION_1: 1 + 2,
OPTION_2
}
"""
return (
_ENUM
+ pyparsing.Optional(self._identifier())("enum_name")
+ _OPEN_CURLY
+ pyparsing.ZeroOrMore(
pyparsing.Group(
self._identifier()("name")
+ pyparsing.Optional(
_EQUALS
# This allows us to get even invalid expressions.
+ pyparsing.SkipTo(pyparsing.Word(",}"))("expression")
)
+ pyparsing.Optional(_COMMA)
)
)("fields")
+ _CLOSE_CURLY
+ self._maybe_attributes()("attributes")
).setParseAction(self._process_enum_definition)
示例15: __init__
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ZeroOrMore [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