def parseSelector(selectorstring):
# *select = @attr1 | /tf1/@attr | @attr1//objtype
"""
def enumtype(*args,**kwargs): #s, l, t, selectortype=None):
print(args)
selectortype = kwargs['selectortype']
if selectortype is None or not isinstance(selectortype, str):
raise ValueError('enumtype requires a selectortype string but got a', type(selectortype))
return selectortype
"""
def attrtype():
return AttrSelector() # 'ATTRTYPE'
def fullpathtype():
return FullPathSelector() #'FULLPATH'
def attrbyobjtype():
return AttrByObjectSelector() #'ATTRBYOBJECT'
def attrexpr(selectorstring=None):
attrmatch = p.Combine(p.Literal('@').suppress() + p.Word(p.alphanums))
return attrmatch.searchString(selectorstring)[0][0]
def expr(selectorstring=None, returntype=False):
attrmatch = p.Combine(p.Literal('@').suppress() + p.Word(p.alphanums))
fullpathmatch = p.Combine(p.OneOrMore(p.Literal('/') + p.Word(p.alphanums))) + p.Literal(
'/').suppress() + p.Combine(p.Literal('@').suppress() + p.Word(p.alphanums))
attrbyobjmatch = p.Combine(p.Literal('@').suppress() + p.Word(p.alphanums)) + p.Literal('//').suppress() + p.Word(p.alphanums)
matchgroup = (fullpathmatch | attrbyobjmatch | attrmatch)
if returntype:
attrmatch.setParseAction(attrtype)
fullpathmatch.setParseAction(fullpathtype)
attrbyobjmatch.setParseAction(attrbyobjtype)
return matchgroup.parseString(selectorstring)
_selectorconfig = expr(selectorstring=selectorstring)
_selectortype = expr(selectorstring=selectorstring, returntype=True)
_selectorattr = attrexpr(selectorstring=selectorstring)
return {
'type': _selectortype[0],
'config': _selectorconfig[:2], #TODO unclear why [0] returns only a subset of the matches
'attribute': _selectorattr
}
评论列表
文章目录