本文整理汇总了Python中pyparsing.Group方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.Group方法的具体用法?Python pyparsing.Group怎么用?Python pyparsing.Group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing
的用法示例。
在下文中一共展示了pyparsing.Group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expression
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def expression(self):
expression = pyparsing.Forward()
# (1 + (2 + 3))
nested_expression = pyparsing.nestedExpr(
"(", ")", expression).setParseAction(self._combine_lists)
# FOO(2 , 3)
function_call = (
_TOKEN().setResultsName("function")
+ _OPEN_PARENTHESIS()
+ pyparsing.delimitedList(
pyparsing.Combine(expression, adjacent=False, joinString=" "),
delim=",").setResultsName("func_args")
+ _CLOSE_PARENTHESIS()
)
expression << pyparsing.OneOrMore(
function_call.setParseAction(self._is_known_function)
| pyparsing.Group(nested_expression)
| _TOKEN()
| _NOT_TOKEN()
)
return pyparsing.Combine(expression, adjacent=False, joinString=" ")
示例2: getLogLineBNF
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def getLogLineBNF():
global logLineBNF
if logLineBNF is None:
integer = Word( nums )
ipAddress = delimitedList( integer, ".", combine=True )
timeZoneOffset = Word("+-",nums)
month = Word(string.uppercase, string.lowercase, exact=3)
serverDateTime = Group( Suppress("[") +
Combine( integer + "/" + month + "/" + integer +
":" + integer + ":" + integer + ":" + integer ) +
timeZoneOffset +
Suppress("]") )
logLineBNF = ( ipAddress.setResultsName("ipAddr") +
Suppress("-") +
("-" | Word( alphas+nums+"@._" )).setResultsName("auth") +
serverDateTime.setResultsName("timestamp") +
dblQuotedString.setResultsName("cmd").setParseAction(getCmdFields) +
(integer | "-").setResultsName("statusCode") +
(integer | "-").setResultsName("numBytesSent") +
dblQuotedString.setResultsName("referrer").setParseAction(removeQuotes) +
dblQuotedString.setResultsName("clientSfw").setParseAction(removeQuotes) )
return logLineBNF
示例3: _parse_filter
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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
示例4: parse
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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
示例5: _apply_modifiers
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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
示例6: _parse
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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)
示例7: parse_table
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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
示例8: _base_or_array_expression
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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)
示例9: _arguments
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _arguments(self):
return pyparsing.Group(
pyparsing.Optional(pyparsing.delimitedList(self._argument()))
)
示例10: _multiword_argument
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _multiword_argument(self):
return pyparsing.Group(
self._variable()
+ pyparsing.OneOrMore(self._variable())
).setParseAction(util.action(pre_ast.CompositeBlock))
示例11: _enum_definition
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [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)
示例12: _arguments
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def _arguments(self):
return pyparsing.Group(
pyparsing.Optional(
pyparsing.delimitedList(self.expression())))
示例13: meta_section
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def meta_section():
return pyparsing.Group(
pyparsing.Literal("meta") +
_COLON +
pyparsing.OneOrMore(
statement()
).setResultsName("statements")
).setResultsName("meta")
示例14: statement
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def statement():
return pyparsing.Group(
_IDENTIFIER.setResultsName("lhs") + _EQUALS +
pyparsing.Combine(
(anything_in_curly() |
pyparsing.QuotedString("'", escChar="\\", unquoteResults=False) |
pyparsing.QuotedString("\"", escChar="\\", unquoteResults=False) |
_REGEX) +
pyparsing.ZeroOrMore(_KEYWORD),
adjacent=False,
joinString=" ",
).setResultsName("rhs")
)
示例15: strings_section
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import Group [as 别名]
def strings_section():
return pyparsing.Group(
pyparsing.Literal("strings") +
_COLON +
pyparsing.OneOrMore(statement()).setResultsName("statements")
).setResultsName("strings")