From 240cf6392931ea37e271bb2632b6205c46ea8a24 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Mon, 31 Oct 2022 22:10:55 +0100
Subject: [PATCH] Get rid of tokens that don't span the current chunk being
 printed

---
 gdb-port/top-level-parse.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py
index 10fbe0d..a6c3f6f 100644
--- a/gdb-port/top-level-parse.py
+++ b/gdb-port/top-level-parse.py
@@ -402,6 +402,9 @@ class TopLevelParse:
 			token_length = tokenmap_entry['end'] - tokenmap_entry['start']
 			start_col = max(tokenmap_entry['start'] - start, 0)
 			end_col = min(tokenmap_entry['end'] - start, w)
+			if end_col < start: #TODO: better control flow here, deletion branch could be merged
+				del self.tokens_from_previous_chunk[index]
+				continue
 			charbuf_dynamic.append([' '] * w)
 			charbuf_dynamic[current_row][start_col:end_col] = ['X'] * min(token_length, end_col-start_col) # TODO: charbuf_dynamic[-1]
 			hparseresult_addr = tokenmap_entry['hparseresult']
-- 
GitLab