本文整理汇总了Python中pyparsing.Suppress.setResultsName方法的典型用法代码示例。如果您正苦于以下问题:Python Suppress.setResultsName方法的具体用法?Python Suppress.setResultsName怎么用?Python Suppress.setResultsName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Suppress
的用法示例。
在下文中一共展示了Suppress.setResultsName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fromString
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
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(")"))
identifier = Word( alphas+"_", alphanums+"_" )
commIdentifier = Group(identifier.setResultsName('identifier') + Optional(opp + (CaselessLiteral("ice")|CaselessLiteral("ros")).setResultsName("type") + clp))
# Imports
idslImport = Suppress(CaselessLiteral("import")) + quote + CharsNotIn("\";").setResultsName('path') + quote + semicolon
idslImports = ZeroOrMore(idslImport)
# Communications
implementsList = Group(CaselessLiteral('implements') + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon)
requiresList = Group(CaselessLiteral('requires') + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon)
subscribesList = Group(CaselessLiteral('subscribesTo') + commIdentifier + ZeroOrMore(Suppress(Word(',')) + commIdentifier) + semicolon)
publishesList = Group(CaselessLiteral('publishes') + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon)
communicationList = implementsList | requiresList | subscribesList | publishesList
communications = Group( Suppress(CaselessLiteral("communications")) + op + ZeroOrMore(communicationList) + cl + semicolon)
# Language
language = Suppress(CaselessLiteral("language")) + (CaselessLiteral("cpp")|CaselessLiteral("python")) + semicolon
# GUI
gui = Group(Optional(Suppress(CaselessLiteral("gui")) + CaselessLiteral("Qt") + opp + identifier + clp + semicolon ))
# additional options
options = Group(Optional(Suppress(CaselessLiteral("options")) + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon))
componentContents = communications.setResultsName('communications') & language.setResultsName('language') & gui.setResultsName('gui') & options.setResultsName('options')
component = Suppress(CaselessLiteral("component")) + identifier.setResultsName("name") + op + componentContents.setResultsName("properties") + cl + semicolon
CDSL = idslImports.setResultsName("imports") + component.setResultsName("component")
CDSL.ignore( cppStyleComment )
tree = CDSL.parseString(text)
return CDSLParsing.component(tree)
示例2: parse_issue
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
def parse_issue(issue):
"""Given an issue, return data that needs saving"""
from pyparsing import Word, Suppress, Literal, OneOrMore, Optional, nums, printables
sprint = (Literal('Sprint') | Literal('sprint')) + Word(nums)
points = Suppress(Literal('(')) + Word(nums) + Suppress(Literal(')'))
deadline = Suppress(Literal('<')) + Word(nums)
name = OneOrMore(Word(printables))
title = Optional(sprint).setResultsName("sprint") + \
Optional(name).setResultsName("name") + \
Optional(deadline).setResultsName("deadline") + \
points.setResultsName("points")
try:
_, r = title.parseString(issue['title'])
print r
except:
pass
示例3: fromString
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
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)
示例4: detect_token
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
def detect_token(jade):
doctype = LineStart() + oneOf('!!! doctype') + Optional(oneOf('5 html xml' \
+ ' default transitional strict frameset 1.1 basic mobile', True))
doctype.setParseAction(parse_doctype)
element_id = Suppress('#') + Word(alphanums + '_' + '-')
element_class = Suppress('.') + Word(alphanums + '_' + '-')
selectors = (element_id.setResultsName('element_id') \
+ ZeroOrMore(element_class).setResultsName('element_class')) \
| (OneOrMore(element_class).setResultsName('element_class') \
+ Optional(element_id).setResultsName('element_id'))
selectors.setParseAction(parse_selectors)
element = selectors.setResultsName('selectors') \
| (Word(alphas).setResultsName('element_name') \
+ Optional(selectors).setResultsName('selectors'))
element.setParseAction(parse_element)
attribute = CharsNotIn('('+')')
attributes = nestedExpr(content=attribute)
tag = element.setResultsName('element') \
+ Optional(attributes).setResultsName('attributes')
tag.setParseAction(parse_tag)
# TODO: block-comment and conditional-comment
unbuffered_comment = Suppress(Suppress('//-') + restOfLine)
buffered_comment = Suppress('//') + restOfLine
buffered_comment.setParseAction(parse_buffered_comment)
# Order matters here, as buffered will pick up
# unbuffered comments if set first
comment = unbuffered_comment | buffered_comment
source = doctype | tag | comment
parsed = source.parseString(jade)
return ' '.join(parsed)
'''
示例5: delimitedList
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
header = dollar + restOfLine
parseKey = (Word(alphas, max=2)).setResultsName("atomLabel") + \
(restOfLine).setResultsName("basisName")
basisFormat = delimitedList(Word(nums), '/')
contraction = Suppress(parenthesis + slash + brackets) + openBra + basisFormat + closeBra
basisHeader = natural + restOfLine
parseContr = pound + Suppress(Word(alphas, max=2)) + contraction
parseCoeff = Suppress(basisHeader) + OneOrMore(floatNumber)
parseBasisData = OneOrMore(Group(parseCoeff.setResultsName("contractions")))
parseBasis = (star + parseKey +
parseContr.setResultsName("format") + star +
parseBasisData.setResultsName("coeffs"))
topParseB = Suppress(header) + OneOrMore(Group(parseBasis))
# ==================> MOs <==================
headerMO = Suppress(SkipTo(Literal("[MO]")) + restOfLine)
sym = Literal("Sym") + restOfLine
spin = Literal("Spin") + restOfLine
occ = Literal("Occ") + restOfLine
示例6: __init__
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
class BgpPolicyParser:
"""Parser class"""
def __init__(self, network):
self.network = network
self.g_business_relationship = nx.DiGraph()
self.user_defined_sets = {}
self.user_library_calls = []
self.user_defined_functions = {}
# Grammars
#TODO: tidy this up
attribute_unnamed = Word(alphanums+'_'+".")
attribute = attribute_unnamed.setResultsName("attribute")
self.attribute = attribute
lt = Literal("<").setResultsName("<")
le = Literal("<=").setResultsName("<=")
eq = Literal("=").setResultsName("=")
ne = Literal("!=").setResultsName("!=")
ge = Literal(">=").setResultsName(">=")
gt = Literal(">").setResultsName(">")
wildcard = Literal("*").setResultsName("wildcard")
self.wildcard = wildcard
self.prefix_lists = {}
self.tags_to_allocate = set()
self.allocated_tags = {}
self._opn = {
'<': operator.lt,
'<=': operator.le,
'=': operator.eq,
'!=': operator.ne,
'>=': operator.ge,
'>': operator.gt,
'&': set.intersection,
'|': set.union,
}
# map alphanum chars to alphanum equivalents for use in tags
self._opn_to_tag = {
'<': "lt",
'<=': "le",
'=': "eq",
'!=': "ne",
'>=': "ge",
'>': "gt",
'&': "and",
'|': "or",
}
# Both are of comparison to access in same manner when evaluating
comparison = (lt | le | eq | ne | ge | gt).setResultsName("comparison")
stringComparison = (eq | ne).setResultsName("comparison")
#
#quoted string is already present
float_string = Word(nums).setResultsName("value").setParseAction(lambda t: float(t[0]))
integer_string = Word(nums).setResultsName("value").setParseAction(lambda t: int(t[0]))
#TODO: use numString, and make integer if fiull stop
#TODO: allow parentheses? - should be ok as pass to the python parser
ipField = Word(nums, max=3)
ipAddress = Combine( ipField + "." + ipField + "." + ipField + "." + ipField ).setResultsName("ipAddress")
boolean_and = Literal("&").setResultsName("&")
boolean_or = Literal("|").setResultsName("|")
boolean = (boolean_and | boolean_or).setResultsName("boolean")
self._boolean = boolean # need to use in checking
#TODO fix this matching 2a.ab when that should match a string
numericQuery = Group(attribute + comparison + float_string).setResultsName( "numericQuery")
stringValues = (attribute_unnamed | quotedString.setParseAction(removeQuotes)
).setResultsName("value")
stringQuery = Group(attribute + stringComparison + stringValues).setResultsName( "stringQuery")
wildcardQuery = wildcard.setResultsName("wildcardQuery")
singleQuery = numericQuery | stringQuery | wildcardQuery
singleQuery.setFailAction(parse_fail_action)
self.nodeQuery = singleQuery + ZeroOrMore(boolean + singleQuery)
self.u_egress = Literal("egress->").setResultsName("u_egress")
self.v_ingress = Literal("->ingress").setResultsName("v_ingress")
self.u_ingress = Literal("ingress<-").setResultsName("u_ingress")
self.v_egress = Literal("<-egress").setResultsName("v_egress")
edgeType = ( self.u_egress | self.u_ingress | self.v_egress
| self.v_ingress).setResultsName("edgeType").setFailAction(parse_fail_action)
self.edgeQuery = ("(" + self.nodeQuery.setResultsName("query_a") + ")"
+ edgeType
+ "(" + self.nodeQuery.setResultsName("query_b")
+ ")").setFailAction(parse_fail_action)
#start of BGP queries
originQuery = (Literal("Origin").setResultsName("attribute") +
#this is a workaround for the match, comparison, value 3-tuple in processing
Literal("(").setResultsName("comparison") +
Group(self.nodeQuery).setResultsName("value") + Suppress(")")).setResultsName("originQuery")
transitQuery = (Literal("Transit").setResultsName("attribute") +
#.........这里部分代码省略.........
示例7: Optional
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
Optional(Group('@' + Word(alphanums + '_-')).setResultsName('moleculeCompartment')))
species_definition = Group(Optional(Group('@' + Word(alphanums + '_')).setResultsName('speciesCompartment') + Suppress('::')) +
delimitedList(molecule_instance, delim='.').setResultsName('speciesPattern'))
reaction_definition = Group(Group(delimitedList(species_definition, delim='+')).setResultsName('reactants') + (uni_arrow | bi_arrow) +
Group(delimitedList(species_definition, delim='+')).setResultsName('products') +
Group(lbracket + (numarg | (identifier + Suppress(Optional('()')))) + Optional(comma + (numarg| (identifier + Suppress(Optional('()'))))) + rbracket).setResultsName('rate'))
# generic hash section grammar
hashed_section = (hashsymbol + Group(OneOrMore(name) + section_enclosure2_))
#hash system_constants
#system_constants = Group()
hashed_system_constants = Group(hashsymbol + Suppress(system_constants_) + lbrace + OneOrMore(statement) + rbrace)
# hash molecule_entry
diffusion_entry_ = Group((diffusion_constant_2d_.setResultsName('2D') | diffusion_constant_3d_.setResultsName('3D')) + Suppress(equal) + (function_entry_.setResultsName('function') | (identifier | numarg).setResultsName('variable')))
molecule_entry = Group(molecule_definition + Optional(Group(lbrace + Optional(diffusion_entry_.setResultsName('diffusionFunction')) + (ZeroOrMore(statement)).setResultsName('moleculeParameters') + rbrace)))
hashed_molecule_section = Group(hashsymbol + Suppress(define_molecules_) + lbrace + OneOrMore(molecule_entry) + rbrace)
#hash function entry
function_name = Group(identifier + '()')
math_function_entry = Group(function_name.setResultsName('functionName') + Suppress(equal) + Group(restOfLine).setResultsName('functionBody'))
hashed_function_section = Group(hashsymbol + Suppress(define_functions_) + lbrace + ZeroOrMore(math_function_entry) +rbrace)
# hash reaction entry
hashed_reaction_section = Group(hashsymbol + Suppress(define_reactions_) + lbrace + OneOrMore(reaction_definition) + rbrace)
# hash observable entry
count_definition = Group(count_ + lbracket + species_definition.setResultsName('speciesPattern') + Suppress(',') + identifier + rbracket)
observable_entry = Group(lbrace + Group(delimitedList(count_definition, delim='+')).setResultsName('patterns') + rbrace + Suppress('=>') + quotedString.setResultsName('outputfile'))
示例8: bytes_requested
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
def bytes_requested():
br = Suppress('(') + Word(nums) + Suppress('bytes)')
return br.setResultsName('bytes_requested')
示例9: subjects
# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import setResultsName [as 别名]
def subjects():
subjects = Suppress('[') + delimitedList(subject(), ',') + Suppress(']')
return subjects.setResultsName('subjects')