fix semantics with var in array

This commit is contained in:
Christoph Brandau
2025-08-04 12:57:01 +02:00
parent 894a5b8b52
commit 3613391c23
+36 -4
View File
@@ -45,6 +45,37 @@ class _Highlighter(Visitor):
self._tokens = [] self._tokens = []
self.log_to_output = log_to_output self.log_to_output = log_to_output
def _get_token_info(self, node):
"""Hilfsmethode um Token-Informationen aus verschiedenen Node-Typen zu extrahieren."""
if not hasattr(node, "pos"):
return None
# Einfacher Fall: Node hat direkten value
if hasattr(node, "value") and node.value is not None:
line, col = node.pos
return (line - 1, col - 1), len(node.value)
# CompoundBareWord: versuche erstes Segment
if hasattr(node, "children") and node.children:
first_segment = node.children[0]
if (
hasattr(first_segment, "value")
and first_segment.value is not None
and hasattr(first_segment, "pos")
):
line, col = first_segment.pos
return (line - 1, col - 1), len(first_segment.value)
# Fallback: Gesamtlänge aus Positionen berechnen
if hasattr(node, "end_pos"):
start_line, start_col = node.pos
end_line, end_col = node.end_pos
if start_line == end_line:
length = end_col - start_col
return (start_line - 1, start_col - 1), length
return None
def visit_quoted_word(self, word: QuotedWord): def visit_quoted_word(self, word: QuotedWord):
if not word.contents: if not word.contents:
return return
@@ -78,13 +109,14 @@ class _Highlighter(Visitor):
) )
if routine.contents == "set" and command.args: if routine.contents == "set" and command.args:
first_arg = command.args[0] first_arg = command.args[0]
if hasattr(first_arg, "pos") and hasattr(first_arg, "value"): token_info = self._get_token_info(first_arg)
line, col = first_arg.pos if token_info:
(line, col), length = token_info
self._tokens.append( self._tokens.append(
( (
( (
(line - 1, col - 1), (line, col),
len(first_arg.value), length,
"variable", "variable",
[TokenModifier.declaration], [TokenModifier.declaration],
) )