add updates libs
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
"""Classes for representing and interacting with Tcl syntax trees. """
|
||||
"""Classes for representing and interacting with Tcl syntax trees."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class Visitor:
|
||||
@@ -222,6 +224,31 @@ class Node:
|
||||
for child in self.children:
|
||||
child.accept(visitor, recurse=True)
|
||||
|
||||
def _pos_match(self, line: int, col: int) -> bool:
|
||||
"""Return True if pos is within this node's block"""
|
||||
if self.pos is None:
|
||||
return False
|
||||
if self.end_pos is None:
|
||||
return line == self.pos[0] and col == self.pos[1]
|
||||
return (
|
||||
line >= self.pos[0]
|
||||
and line <= self.end_pos[0]
|
||||
and (col >= self.pos[1] or line > self.pos[0])
|
||||
and (col < self.end_pos[1] or line < self.end_pos[0])
|
||||
)
|
||||
|
||||
def find_by_pos(self, line: int, col: int) -> Node | None:
|
||||
"""Find the deepest child node in the tree (i.e. most granular match) that
|
||||
matches the given position."""
|
||||
if not self._pos_match(line, col):
|
||||
return None
|
||||
|
||||
for child in self.children:
|
||||
if child._pos_match(line, col):
|
||||
return child.find_by_pos(line, col)
|
||||
|
||||
return self
|
||||
|
||||
|
||||
class Script(Node):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -236,6 +263,11 @@ class Script(Node):
|
||||
|
||||
|
||||
class Comment(Node):
|
||||
value: str
|
||||
|
||||
def __init__(self, value: str, pos=None, end_pos=None):
|
||||
super().__init__(value, pos=pos, end_pos=end_pos)
|
||||
|
||||
def accept(self, visitor, recurse=False):
|
||||
if recurse:
|
||||
self._recurse(visitor)
|
||||
@@ -243,7 +275,7 @@ class Comment(Node):
|
||||
|
||||
|
||||
class Command(Node):
|
||||
def __init__(self, routine, *args, pos=None, end_pos=None):
|
||||
def __init__(self, routine: Node, *args: Node, pos=None, end_pos=None):
|
||||
self.routine = routine
|
||||
self.args = args
|
||||
super().__init__(routine, *args, pos=pos, end_pos=end_pos)
|
||||
@@ -288,6 +320,8 @@ class BracedWord(Node):
|
||||
|
||||
@property
|
||||
def contents_pos(self):
|
||||
if self.line is None or self.col is None:
|
||||
return None
|
||||
return (self.line, self.col + 1)
|
||||
|
||||
|
||||
@@ -315,6 +349,8 @@ class QuotedWord(Node):
|
||||
def contents_pos(self):
|
||||
if self.contents is None:
|
||||
return None
|
||||
if self.line is None or self.col is None:
|
||||
return None
|
||||
return (self.line, self.col + 1)
|
||||
|
||||
|
||||
@@ -337,7 +373,7 @@ class VarSub(Node):
|
||||
|
||||
|
||||
class ArgExpansion(Node):
|
||||
def __init__(self, list, pos=None, end_pos=None):
|
||||
def __init__(self, list: Node, pos=None, end_pos=None):
|
||||
self.list = list
|
||||
super().__init__(list, pos=pos, end_pos=end_pos)
|
||||
|
||||
@@ -346,6 +382,10 @@ class ArgExpansion(Node):
|
||||
self._recurse(visitor)
|
||||
visitor.visit_arg_expansion(self)
|
||||
|
||||
@property
|
||||
def contents(self):
|
||||
return self.list.contents
|
||||
|
||||
|
||||
class List(Node):
|
||||
"""This Node currently exists exclusively for implementing the switch
|
||||
|
||||
Reference in New Issue
Block a user