Skip to content

Commit 3b095ad

Browse files
committed
parser: fix position bug with unbraced list
1 parent 7cdd8e4 commit 3b095ad

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/tclint/parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ def parse_list(self, node):
510510
if node.contents is None:
511511
return None
512512

513-
# Hack: we know contents start 1 col over, since first char denotes the list
514-
ts = Lexer(pos=(node.line, node.col + 1))
513+
ts = Lexer(pos=node.contents_pos)
515514
ts.input(node.contents)
516515

517516
DELIMITERS = {TOK_WS, TOK_BACKSLASH_NEWLINE, TOK_NEWLINE}

tests/test_parser.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,20 @@ def test_proc_args():
759759
)
760760
)
761761

762+
command = tree.children[0]
763+
args_list = command.args[1]
764+
assert args_list.pos == (1, 10)
765+
assert args_list.end_pos == (1, 23)
766+
arg1 = args_list.children[0]
767+
assert arg1.pos == (1, 12)
768+
arg2 = args_list.children[1]
769+
assert arg2.pos == (1, 14)
770+
assert arg2.end_pos == (1, 21)
771+
arg2_name = arg2.children[0]
772+
assert arg2_name.pos == (1, 16)
773+
arg2_default = arg2.children[1]
774+
assert arg2_default.pos == (1, 18)
775+
762776

763777
def test_broken_command():
764778
def bad_command_parser(*args):
@@ -786,3 +800,15 @@ def test_expr_unbalanced_close_paren():
786800
# close paren was silently dropped).
787801
with pytest.raises(TclSyntaxError):
788802
parse("expr {$foo )}")
803+
804+
805+
def test_unbraced_list():
806+
script = "proc foo foo {}"
807+
tree = parse(script)
808+
assert tree == Script(
809+
Command(BareWord("proc"), BareWord("foo"), List(BareWord("foo")), Script())
810+
)
811+
command = tree.children[0]
812+
args_list_node = command.args[1]
813+
assert args_list_node.pos == (1, 10)
814+
assert args_list_node.children[0].pos == (1, 10)

0 commit comments

Comments
 (0)