refactor node markers, remove need to be aware of nodes
This commit is contained in:
parent
2d06ae0f65
commit
5e56e9b4f6
|
@ -369,13 +369,8 @@ class NodeKeywords(MappingMixin):
|
||||||
|
|
||||||
@attr.s(cmp=False, hash=False)
|
@attr.s(cmp=False, hash=False)
|
||||||
class NodeMarkers(object):
|
class NodeMarkers(object):
|
||||||
node = attr.ib(repr=False)
|
|
||||||
own_markers = attr.ib(default=attr.Factory(list))
|
own_markers = attr.ib(default=attr.Factory(list))
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_node(cls, node):
|
|
||||||
return cls(node=node)
|
|
||||||
|
|
||||||
def update(self, add_markers):
|
def update(self, add_markers):
|
||||||
"""update the own markers
|
"""update the own markers
|
||||||
"""
|
"""
|
||||||
|
@ -386,7 +381,6 @@ class NodeMarkers(object):
|
||||||
find markers in own nodes or parent nodes
|
find markers in own nodes or parent nodes
|
||||||
needs a better place
|
needs a better place
|
||||||
"""
|
"""
|
||||||
for node in reversed(self.node.listchain()):
|
for mark in self.own_markers:
|
||||||
for mark in node._markers.own_markers:
|
if mark.name == name:
|
||||||
if mark.name == name:
|
yield mark
|
||||||
yield mark
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Node(object):
|
||||||
|
|
||||||
#: keywords/markers collected from all scopes
|
#: keywords/markers collected from all scopes
|
||||||
self.keywords = NodeKeywords(self)
|
self.keywords = NodeKeywords(self)
|
||||||
self._markers = NodeMarkers.from_node(self)
|
self._markers = NodeMarkers()
|
||||||
|
|
||||||
#: allow adding of extra keywords to use for matching
|
#: allow adding of extra keywords to use for matching
|
||||||
self.extra_keyword_matches = set()
|
self.extra_keyword_matches = set()
|
||||||
|
@ -184,7 +184,9 @@ class Node(object):
|
||||||
|
|
||||||
def find_markers(self, name):
|
def find_markers(self, name):
|
||||||
"""find all marks with the given name on the node and its parents"""
|
"""find all marks with the given name on the node and its parents"""
|
||||||
return self._markers.find(name)
|
for node in reversed(self.listchain()):
|
||||||
|
for mark in node._markers.find(name):
|
||||||
|
yield mark
|
||||||
|
|
||||||
def get_marker(self, name):
|
def get_marker(self, name):
|
||||||
""" get a marker object from this node or None if
|
""" get a marker object from this node or None if
|
||||||
|
|
Loading…
Reference in New Issue