本文整理汇总了Python中pyparsing.Group.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Group.copy方法的具体用法?Python Group.copy怎么用?Python Group.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Group
的用法示例。
在下文中一共展示了Group.copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_string
# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import copy [as 别名]
def parse_string(self, string):
'''Populate a new object from a string.
Parsing is hard, so we're going to call out to the pyparsing
library here. I hope you installed it!
'''
from pyparsing import Suppress, Regex, quotedString, restOfLine, Keyword, nestedExpr, Group, OneOrMore, Word, Literal, alphanums, removeQuotes, replaceWith
gr_eq = Literal('=')
gr_stripped_string = quotedString.copy().setParseAction( removeQuotes )
gr_opt_quoted_string = gr_stripped_string | restOfLine
gr_name = Keyword('name', caseless=True) + gr_eq + gr_opt_quoted_string
gr_name.setParseAction(lambda x, y=self: y._set_name(x[2]))
gr_yn = Keyword('yes', caseless=True).setParseAction(replaceWith('1')) | Keyword('no', caseless=True).setParseAction(replaceWith('0'))
gr_phrase = Group(OneOrMore(gr_stripped_string | Word(alphanums)) + gr_eq + gr_opt_quoted_string)
def np(words, fn = gr_opt_quoted_string, action=print):
p = Keyword(words[0], caseless=True)
for w in words[1:]:
p = p | Keyword(w, caseless=True)
p = p + gr_eq + fn
p.setParseAction(action)
return p
gr_ifsc = np(PList('Ignore File Set Changes'), gr_yn, action=self._parse_setter(IGNORECHANGES))
gr_evss = np(PList('Enable VSS'), gr_yn, action=self._parse_setter(VSSENABLED))
gr_i_option = Group(Keyword(OPTIONS, caseless=True) + nestedExpr('{','}', Regex('[^\}]+', re.MULTILINE)))
gr_e_option = gr_i_option.copy()
gr_i_file = gr_phrase.copy()
gr_e_file = gr_phrase.copy()
gr_inc = Keyword('include', caseless=True) + nestedExpr('{','}', OneOrMore(gr_i_option | gr_i_file))
gr_inc.addParseAction(self._parse_add_entry)
gr_exc = Keyword('exclude', caseless=True) + nestedExpr('{','}', OneOrMore(gr_e_option | gr_e_file))
gr_exc.addParseAction(self._parse_add_entry)
gr_res = OneOrMore(gr_name | gr_inc | gr_exc | gr_ifsc | gr_evss)
result = gr_res.parseString(string, parseAll=True)
return 'Fileset: ' + self[NAME]