本文整理汇总了Python中pyparsing.ZeroOrMore类的典型用法代码示例。如果您正苦于以下问题:Python ZeroOrMore类的具体用法?Python ZeroOrMore怎么用?Python ZeroOrMore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ZeroOrMore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _extract_keyword_values_termination
def _extract_keyword_values_termination(self, line):
"""
Extracts the keyword, the values and the termination of an input line.
The values are returned as a list.
:arg line: input line
:return: keyword, values, comment
"""
keywordletters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-="
keyword = Word(keywordletters, max=8)("keyword")
value = Word(alphanums + ".-+")
values = Group(Optional(delimitedList(value)))("vals")
termination = ZeroOrMore(Word(printables))("termination")
termination.setParseAction(lambda tokens: " ".join(tokens))
expr = keyword + Suppress("(") + values + Suppress(")") + termination + stringEnd
try:
result = expr.parseString(line)
except ParseException:
return None, None, None
return result.keyword, result.vals, result.termination
开发者ID:pymontecarlo,项目名称:pymontecarlo-penelope,代码行数:26,代码来源:geometry.py
示例2: parse_macro_arguments
def parse_macro_arguments(argument_string, return_kwargs=False):
if not argument_string:
return None
import re
from pyparsing import Group, Or, QuotedString, Regex, Suppress, ZeroOrMore
# General argument string parser
argstring_def = ZeroOrMore(Or([ \
QuotedString('"'), # long arguments
Group(Regex('[\w]+', flags=re.UNICODE) + # keyword arguments
Suppress('=').leaveWhitespace() +
Or([Regex('[\w]+'), QuotedString('"')])),
Regex(r'\(\(.*\)\)', flags=re.UNICODE), # nested macros
Regex('[\S]+', flags=re.UNICODE) # basic arguments
]))
args = argstring_def.parseString(argument_string).asList()
# The keyword arguments are stored as lists in the `args' variable,
# extract them and convert them into a dict, then return
if return_kwargs:
kwargs = {}
for arg in args:
if isinstance(arg, list):
kwargs[str(arg[0])] = arg[1]
args.remove(arg) # remove the nested list
return args, kwargs
return args
开发者ID:andrejtokarcik,项目名称:python-sneakylang,代码行数:28,代码来源:macro_caller.py
示例3: _logicals_
def _logicals_(atomic):
"""
Return a new parser parsing logical expressions on atomics.
This parser recognizes the following grammar, with precedences
parser := atomic | '~' parser | parser '&' parser | parser '|' parser |
parser '->' parser | parser '<->' parser
Returned AST uses .ast package's classes.
"""
parser = Forward()
atom = (atomic | Suppress("(") + parser + Suppress(")"))
notstrict = "~" + atom
notstrict.setParseAction(lambda tokens: Not(tokens[1]))
not_ = notstrict | atom
and_ = not_ + ZeroOrMore("&" + not_)
and_.setParseAction(lambda tokens: _left_(And, tokens))
or_ = and_ + ZeroOrMore("|" + and_)
or_.setParseAction(lambda tokens: _left_(Or, tokens))
implies = ZeroOrMore(or_ + "->") + or_
implies.setParseAction(lambda tokens: _right_(Implies, tokens))
iff = implies + ZeroOrMore("<->" + implies)
iff.setParseAction(lambda tokens: _left_(Iff, tokens))
parser <<= iff
return parser
开发者ID:ancailliau,项目名称:pynusmv,代码行数:29,代码来源:parsing.py
示例4: defineParsers
def defineParsers():
#Enable a fast parsing mode with caching.
ParserElement.enablePackrat()
#end of line terminates statements, so it is not regular whitespace
ParserElement.setDefaultWhitespaceChars('\t ')
func_call = Forward() #forward declaration because this is a recursive rule
#The "terminal" rules
symbol = Word(alphas+'_-', alphanums+'_-') .setParseAction(action_symbol)
q_symbol = quotedString .setParseAction(action_q_symbol)
bracket_term = Literal("(").suppress() - func_call \
+ Literal(")").suppress()
word = symbol | q_symbol | bracket_term
#The function call
#Parse: "foo | bar | baz" or "foo"
pipeline = (word + ZeroOrMore("|" - word)) .setParseAction(action_pipeline)
#Parse "foo|bar op1 op2 op3"
func_call << (pipeline - ZeroOrMore(word)) .setParseAction(action_func_call)
#High level structure of program
line = LineEnd() | func_call - LineEnd() #empty line or function call
program = ZeroOrMore(line) + StringEnd() #multiple lines are a program
#define the comments
program.ignore('%' + restOfLine)
#no tab expansion
program.parseWithTabs()
#return additional func_call parser to make testing more easy
return program, func_call
开发者ID:eike-welk,项目名称:freeode,代码行数:31,代码来源:simple_config_lang.py
示例5: _logical_parser
def _logical_parser(expression):
"""
Return a new parser parsing logical expressions.
This parser recognizes the following grammar, with precedence:
<logical> ::= expression | '~' <logical> | <logical> '&' <logical>
| <logical> '|' <logical> | <logical> '->' <logical>
| <logical> '<->' <logical>
.. note:: The parser uses :mod:`pytlq.ast` module's classes to build ASTs.
.. credit:: Adapted from Simon Busard's parser parsing logical expressions
on atomics.
"""
parser = Forward()
not_strict = Literal('~') + expression
not_strict.setParseAction(lambda tokens: Not(tokens[1]))
not_ = (not_strict | expression)
and_ = not_ + ZeroOrMore(Literal('&') + not_)
and_.setParseAction(lambda tokens: _left(And, tokens))
or_ = and_ + ZeroOrMore(Literal('|') + and_)
or_.setParseAction(lambda tokens: _left(Or, tokens))
imply = ZeroOrMore(or_ + Literal('->')) + or_
imply.setParseAction(lambda tokens: _right(Imply, tokens))
iff = imply + ZeroOrMore(Literal('<->') + imply)
iff.setParseAction(lambda tokens: _left(Iff, tokens))
parser <<= iff
return parser
开发者ID:sbusard,项目名称:PyTLQ,代码行数:31,代码来源:parser.py
示例6: parser
def parser(cls, width, height):
"""Parse a BZW file.
For now, we're only supporting a subset of BZW's allobjects.
"""
comment = '#' + SkipTo(LineEnd())
bzw = ZeroOrMore(Box.parser() | Base.parser()).ignore(comment)
bzw.setParseAction(lambda toks: cls(width, height, toks))
return bzw
开发者ID:Altair3,项目名称:Tanks,代码行数:9,代码来源:world.py
示例7: _parse_items
def _parse_items(self, source):
ParserElement.setDefaultWhitespaceChars(' \t\r')
EOL = LineEnd().suppress()
comment = Literal('#') + Optional( restOfLine ) + EOL
string = CharsNotIn("\n")
line = Group(
Word(alphanums + '-')('key') + Literal(':').suppress() + Optional(Combine(string + ZeroOrMore(EOL + Literal(' ') + string)))("value") + EOL
)
group = ZeroOrMore(line)
group.ignore(comment)
return group.parseString(source, True)
开发者ID:centrumholdings,项目名称:citools,代码行数:11,代码来源:control.py
示例8: parser
def parser():
rule = Forward()
body = OneOrMore(CharsNotIn('{};') + ';')
sel = CharsNotIn('{};')
rule <<= sel + Group( '{' + ZeroOrMore( rule | body ) + '}' )
rule.setParseAction( make_action(Rule) )
stylesheet = ZeroOrMore( rule )
stylesheet.ignore( cStyleComment )
return stylesheet
开发者ID:svbatalov,项目名称:css-extract,代码行数:12,代码来源:parse.py
示例9: build_parser
def build_parser():
key = Word(alphanums).setResultsName('key')
value = restOfLine.setParseAction(
lambda string, location, tokens: tokens[0].strip()
).setResultsName('value')
property_ = Group(key + Suppress(Literal('=')) + value)
properties = Group(OneOrMore(property_)).setResultsName('properties')
section_name = (Suppress('[') + OneOrMore(CharsNotIn(']')) +
Suppress(']')).setResultsName('section')
section = Group(section_name + properties)
ini_file = ZeroOrMore(section).setResultsName('sections')
ini_file.ignore(pythonStyleComment)
return ini_file
开发者ID:seanfisk,项目名称:gitconfig-parser,代码行数:13,代码来源:parser.py
示例10: transform_human
def transform_human(text):
"""Transform user input into something Script can read."""
# these are parseActions for pyparsing.
def str_literal_to_hex(s, loc, toks):
for i, t in enumerate(toks):
toks[i] = ''.join(['0x', t.encode('hex')])
return toks
# ^ parseActions for pyparsing end here.
str_literal = QuotedString('"')
str_literal.setParseAction(str_literal_to_hex)
transformer = ZeroOrMore( str_literal )
return transformer.transformString(text)
开发者ID:instagibbs,项目名称:hashmal,代码行数:13,代码来源:scriptedit.py
示例11: create_grammar
def create_grammar():
global arrows
global stereotypes
assert len(arrows) > 0
assert len(stereotypes) > 0
linechars = ''.join((c for c in printables if c not in '}\n')) + ' \t'
norbracket = ''.join((c for c in printables if c != ']')) + ' \t'
nogt = ''.join((c for c in printables if c != '>')) + ' \t'
norparen = ''.join((c for c in printables if c != ')')) + ' \t'
line = Word(linechars)
cls_body = Group(ZeroOrMore(line))
classkeyword = Keyword('class').setResultsName('type')
st_names = stereotypes.keys()
st = Literal(st_names[0])
for s in st_names[1:]:
st = st | Literal(s)
stereotype = Group(Optional(Literal('<<').suppress() + st + Literal('>>').suppress()))
identifier_list = Word(alphas) + ZeroOrMore(Literal(',').suppress() + Word(alphas))
baseclasses = Group(Optional(Literal(':').suppress() + identifier_list))
cls = Group(stereotype + classkeyword + Word(alphas) + baseclasses + \
Literal('{').suppress() + cls_body + Literal('}').suppress())
arrow_names = arrows.keys()
arrow_names.sort(lambda x,y: -cmp(len(x), len(y)))
arrow = Keyword(arrow_names[0])
for ar in arrow_names[1:]:
arrow = arrow | Keyword(ar)
relation_caption = Literal('(').suppress() + Word(norparen) + \
Literal(')').suppress()
quantifier = Literal('[').suppress() + Word(norbracket) + Literal(']').suppress()
relation = Group(
Word(alphas) + Group(Optional(quantifier)) + \
arrow.setResultsName('type') + \
Word(alphas) + Group(Optional(quantifier)) + \
Group(Optional(relation_caption))
)
grammar = ZeroOrMore(cls | relation)
grammar.ignore(cStyleComment)
grammar.ignore("//" + restOfLine)
return grammar
开发者ID:Droggelbecher,项目名称:Grail,代码行数:50,代码来源:generate_clsgraph.py
示例12: gramma
def gramma():
## Tokens
point = Literal('.')
prefix_op = Literal('.')
choice_op = Literal('+')
parallel = Literal("||") | Literal("<>")
#ident = Word(alphas, alphanums+'_')
ratename = Word(alphas.lower(),alphanums+"_")
lpar = Literal('(').suppress()
rpar = Literal(')').suppress()
lsqpar = Literal('[').suppress()
rsqpar = Literal(']').suppress()
define = Literal('=')
semicol = Literal(';').suppress()
col = Literal(',').suppress()
number = Word(nums)
integer = number
floatnumber = Combine( integer + Optional( point + Optional(number)))
passiverate = Word('infty') | Word('T')
internalrate = Word('tau')
pound = Literal('#').suppress()
percent = Literal('%').suppress()
peparate = (ratename | floatnumber | internalrate | passiverate).setParseAction(_check_var)
peparate_indef = floatnumber | internalrate | passiverate
sync = Word('<').suppress() + ratename + ZeroOrMore(col + ratename) + Word('>').suppress()
coop_op = (parallel | sync).setParseAction(_create_sync_set)
activity = (ratename + col + peparate).setParseAction(_create_activity)
procdef = (Word(alphas.upper(), alphanums+"_") + Optional(lsqpar + peparate_indef + rsqpar)).setParseAction(_create_procdef)
## RATES Definitions
ratedef = (Optional(percent)+ratename + define + peparate_indef).setParseAction(assign_var) + semicol
prefix = Forward()
choice = Forward()
coop = Forward()
process = ( activity
| procdef
| lpar + coop + rpar
).setParseAction(_create_process)
prefix << (process + ZeroOrMore(prefix_op + prefix)).setParseAction( _create_prefix)
choice << (prefix + ZeroOrMore(choice_op + choice)).setParseAction(_create_choice)
coop << (choice + ZeroOrMore(coop_op + coop)).setParseAction(_create_coop)
rmdef = (Optional(pound) + procdef + define + coop + semicol).setParseAction(_create_definition)
system_eq = Optional(pound) + coop
pepa = ZeroOrMore(ratedef) + ZeroOrMore(rmdef) + system_eq.setParseAction(_create_system_equation)
pepacomment = '//' + restOfLine
pepa.ignore(pepacomment)
return pepa
开发者ID:allanderek,项目名称:pyPEPA,代码行数:49,代码来源:parser_func.py
示例13: getkw_bnf
def getkw_bnf(self):
sect_begin = Literal("{").suppress()
sect_end = Literal("}").suppress()
array_begin = Literal("[").suppress()
array_end = Literal("]").suppress()
tag_begin = Literal("<").suppress()
tag_end = Literal(">").suppress()
eql = Literal("=").suppress()
dmark = Literal('$').suppress()
end_data=Literal('$end').suppress()
prtable = alphanums+r'!$%&*+-./<>[email protected]^_|~'
ival=Regex('[-]?\d+')
dval=Regex('-?\d+\.\d*([eE]?[+-]?\d+)?')
lval=Regex('([Yy]es|[Nn]o|[Tt]rue|[Ff]alse|[Oo]n|[Oo]ff)')
# Helper definitions
kstr= quotedString.setParseAction(removeQuotes) ^ \
dval ^ ival ^ lval ^ Word(prtable)
name = Word(alphas+"_",alphanums+"_")
vec=array_begin+delimitedList(dval ^ ival ^ lval ^ Word(prtable) ^ \
Literal("\n").suppress() ^ \
quotedString.setParseAction(removeQuotes))+array_end
sect=name+sect_begin
tag_sect=name+Group(tag_begin+name+tag_end)+sect_begin
# Grammar
keyword = name + eql + kstr
vector = name + eql + vec
data=Combine(dmark+name)+SkipTo(end_data)+end_data
section=Forward()
sect_def=(sect | tag_sect ) #| vec_sect)
input=section | data | vector | keyword
section << sect_def+ZeroOrMore(input) + sect_end
# Parsing actions
ival.setParseAction(self.conv_ival)
dval.setParseAction(self.conv_dval)
lval.setParseAction(self.conv_lval)
keyword.setParseAction(self.store_key)
vector.setParseAction(self.store_vector)
data.setParseAction(self.store_data)
sect.setParseAction(self.add_sect)
tag_sect.setParseAction(self.add_sect)
sect_end.setParseAction(self.pop_sect)
bnf=ZeroOrMore(input) + StringEnd().setFailAction(parse_error)
bnf.ignore(pythonStyleComment)
return bnf
开发者ID:juselius,项目名称:libgetkw,代码行数:49,代码来源:getkw.py
示例14: read
def read(self, file_or_filename):
""" Parses a PSAT data file and returns a case object
file_or_filename: File object or path to PSAT data file
return: Case object
"""
self.file_or_filename = file_or_filename
logger.info("Parsing PSAT case file [%s]." % file_or_filename)
t0 = time.time()
self.case = Case()
# Name the case
if isinstance(file_or_filename, basestring):
name, _ = splitext(basename(file_or_filename))
else:
name, _ = splitext(file_or_filename.name)
self.case.name = name
bus_array = self._get_bus_array_construct()
line_array = self._get_line_array_construct()
# TODO: Lines.con - Alternative line data format
slack_array = self._get_slack_array_construct()
pv_array = self._get_pv_array_construct()
pq_array = self._get_pq_array_construct()
demand_array = self._get_demand_array_construct()
supply_array = self._get_supply_array_construct()
# TODO: Varname.bus (Bus names)
# Pyparsing case:
case = \
ZeroOrMore(matlab_comment) + bus_array + \
ZeroOrMore(matlab_comment) + line_array + \
ZeroOrMore(matlab_comment) + slack_array + \
ZeroOrMore(matlab_comment) + pv_array + \
ZeroOrMore(matlab_comment) + pq_array + \
ZeroOrMore(matlab_comment) + demand_array + \
ZeroOrMore(matlab_comment) + supply_array
case.parseFile(file_or_filename)
elapsed = time.time() - t0
logger.info("PSAT case file parsed in %.3fs." % elapsed)
return self.case
开发者ID:Waqquas,项目名称:pylon,代码行数:48,代码来源:psat.py
示例15: __init__
def __init__(self, path, text, state=None):
self.path = path
self.base_path = os.path.dirname(path)
self.text = text
self.state = state
opcode_name = Word(alphanums + '_')
value = Regex(r'.*?(?=\s*(([a-zA-Z0-9_]+=)|//|<[a-z]|$))', re.MULTILINE)
opcode = locatedExpr(opcode_name) + Literal('=').suppress() + value
opcode.setParseAction(self.handle_opcode)
section_name = Literal('<').suppress() + Word(alphas) + Literal('>').suppress()
section = section_name
section.setParseAction(self.handle_section)
include = Literal('#include').suppress() + locatedExpr(QuotedString('"'))
include.setParseAction(self.handle_include)
statement = (section
^ opcode
^ include)
self.sfz_file = ZeroOrMore(statement) + stringEnd
comment = Literal('//') + restOfLine
self.sfz_file.ignore(comment)
开发者ID:odahoda,项目名称:noisicaa,代码行数:26,代码来源:sfzparser.py
示例16: parse_template
def parse_template(template_text):
identifier = Word(alphas, alphanums + '_')
param = Group(identifier('name') + Suppress(':') + CharsNotIn(',)')('value'))
param_list = Group(Suppress('(') + delimitedList(param, delim=',') + Suppress(')'))
benchmark_id = originalTextFor(identifier + '.' + identifier + '.' + identifier)
measurement_id = Group(benchmark_id('benchmark') + Optional(param_list('params')) + Suppress('[') + identifier('local_id') + Suppress(']'))
macro = Group(Suppress('${') + measurement_id('measurement') + Suppress('}'))
raw_text_block = originalTextFor(CharsNotIn('$'))
text = ZeroOrMore(Group(raw_text_block('text') | macro('macro')))('template')
text.leaveWhitespace()
return text.parseString(template_text).asDict()
开发者ID:koplyarov,项目名称:benchmarks,代码行数:16,代码来源:benchmarks-template.py
示例17: parse_cp2k_warnings
def parse_cp2k_warnings(file_name, package_warnings):
"""
Parse All the warnings found in an output file
"""
p = ZeroOrMore(Suppress(SkipTo("*** WARNING")) + SkipTo('\n\n'))
# Return dict of Warnings
messages = p.parseFile(file_name).asList()
# Search for warnings that match the ones provided by the user
warnings = {m: assign_warning(package_warnings, m) for m in messages}
if not warnings:
return None
else:
return warnings
开发者ID:SCM-NV,项目名称:qmworks,代码行数:16,代码来源:cp2KParser.py
示例18: __init__
def __init__(self):
key_name = Word(re.sub(r"[\[\]=\"]", "", printables))
kgrp_name = Word(re.sub(r"[\[\]\.]", "", printables))
basic_int = Optional("-") + ("0" | Word(nums))
types = dict(
string = QuotedString("\"", escChar="\\"),
integer = Combine(basic_int),
float = Combine(basic_int + "." + Word(nums)),
datetime = Regex(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z"),
boolean = Keyword("true") | Keyword("false"),
array = Forward(),
)
pure_array = Or(delimitedList(type_) for type_ in types.values())
types["array"] << Group(Suppress("[") + Optional(pure_array) +
Suppress("]"))
value = Or(type_ for type_ in types.values())
keyvalue = key_name + Suppress("=") + value + Suppress(LineEnd())
keygroup_namespace = kgrp_name + ZeroOrMore(Suppress(".") + kgrp_name)
keygroup = "[" + keygroup_namespace + "]" + LineEnd()
comments = pythonStyleComment
self._toplevel = ZeroOrMore(keyvalue | keygroup)
self._toplevel.ignore(comments)
for k, v in types.items():
v.setParseAction(getattr(self, "_parse_"+k))
keyvalue.setParseAction(self._parse_keyvalue)
keygroup_namespace.setParseAction(self._parse_keygroup_namespace)
开发者ID:bryant,项目名称:pytoml,代码行数:31,代码来源:__init__.py
示例19: fromString
def fromString(inputText, verbose=False):
if verbose: print 'Verbose:', verbose
text = nestedExpr("/*", "*/").suppress().transformString(inputText)
semicolon = Suppress(Word(";"))
quote = Suppress(Word("\""))
op = Suppress(Word("{"))
cl = Suppress(Word("}"))
opp = Suppress(Word("("))
clp = Suppress(Word(")"))
lt = Suppress(Word("<"))
gt = Suppress(Word(">"))
identifier = Word(alphas+"_",alphanums+"_")
typeIdentifier = Word(alphas+"_",alphanums+"_:")
## Imports
idslImport = Suppress(Word("import")) + quote + CharsNotIn("\";").setResultsName('path') + quote + semicolon
idslImports = ZeroOrMore(idslImport)
dictionaryDef = Word("dictionary") + lt + CharsNotIn("<>;") + gt + identifier.setResultsName('name') + semicolon
sequenceDef = Word("sequence") + lt + CharsNotIn("<>;") + gt + identifier.setResultsName('name') + semicolon
enumDef = Word("enum") + identifier.setResultsName('name') + op + CharsNotIn("{}") + cl + semicolon
structDef = Word("struct") + identifier.setResultsName('name') + op + CharsNotIn("{}") + cl + semicolon
exceptionDef = Word("exception") + identifier.setResultsName('name') + op + CharsNotIn("{}") + cl + semicolon
raiseDef = Suppress(Word("throws")) + typeIdentifier + ZeroOrMore( Literal(',') + typeIdentifier )
decoratorDef = Literal('idempotent') | Literal('out')
retValDef = typeIdentifier.setResultsName('ret')
firstParam = Group( Optional(decoratorDef.setResultsName('decorator')) + typeIdentifier.setResultsName('type') + identifier.setResultsName('name'))
nextParam = Suppress(Word(',')) + firstParam
params = firstParam + ZeroOrMore(nextParam)
remoteMethodDef = Group(Optional(decoratorDef) + retValDef + typeIdentifier.setResultsName('name') + opp + Optional( params).setResultsName('params') + clp + Optional(raiseDef) + semicolon )
interfaceDef = Word("interface") + typeIdentifier.setResultsName('name') + op + Group(ZeroOrMore(remoteMethodDef)) + cl + semicolon
moduleContent = Group(structDef | enumDef | exceptionDef | dictionaryDef | sequenceDef | interfaceDef)
module = Suppress(Word("module")) + identifier.setResultsName("name") + op + ZeroOrMore(moduleContent).setResultsName("contents") + cl + semicolon
IDSL = idslImports.setResultsName("imports") + module.setResultsName("module")
IDSL.ignore( cppStyleComment )
tree = IDSL.parseString(text)
return IDSLParsing.module(tree)
开发者ID:BasilMVarghese,项目名称:robocomp,代码行数:46,代码来源:parseIDSL.py
示例20: getkw_bnf
def getkw_bnf(self):
sect_begin = Literal("{").suppress()
sect_end = Literal("}").suppress()
array_begin = Literal("[").suppress()
array_end = Literal("]").suppress()
arg_begin = Literal("(").suppress()
arg_end = Literal(")").suppress()
eql = Literal("=").suppress()
dmark = Literal('$').suppress()
end_data=Literal('$end').suppress()
prtable = alphanums+r'!$%&*+-./<>[email protected]^_|~'
# Helper definitions
kstr=Word(prtable) ^ quotedString.setParseAction(removeQuotes)
name = Word(alphas+"_",alphanums+"_")
vec=array_begin+delimitedList(Word(prtable) ^ \
Literal("\n").suppress() ^ \
quotedString.setParseAction(removeQuotes))+array_end
sect=name+sect_begin
key_sect=name+Group(arg_begin+kstr+arg_end)+sect_begin
vec_sect=name+Group(arg_begin+vec+ arg_end)+sect_begin
# Grammar
keyword = name + eql + kstr
vector = name + eql + vec
data=Combine(dmark+name)+SkipTo(end_data)+end_data
section=Forward()
sect_def=(sect | key_sect | vec_sect)
input=section | data | vector | keyword
section << sect_def+ZeroOrMore(input) + sect_end
# Parsing actions
keyword.setParseAction(self.store_key)
vector.setParseAction(self.store_vector)
data.setParseAction(self.store_data)
sect.setParseAction(self.add_sect)
key_sect.setParseAction(self.add_sect)
vec_sect.setParseAction(self.add_vecsect)
sect_end.setParseAction(self.pop_sect)
bnf=ZeroOrMore(input) + StringEnd().setFailAction(parse_error)
bnf.ignore(pythonStyleComment)
return bnf
开发者ID:juselius,项目名称:gimic,代码行数:44,代码来源:getkw.py
注:本文中的pyparsing.ZeroOrMore类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论