Repository navigation
Description
What
Prism._strip_single_line_comments() (the comment stripper for every language whose
lexical_family is line_exclusive) drives its delimiter list from a single shared
config list — LEXICAL_FAMILY_HEURISTICS["lexical_families"]["line_exclusive"]["delimiters"],
currently ["#", "<#", "#>", "=begin", "=end", ";", "dnl", "%"] — applied identically to
every language bucketed into that family, rather than each language's own real comment
token(s).
; is only a real comment delimiter for assembly/agc_assembly. % is only a real comment
delimiter for matlab. But 20 languages currently share line_exclusive: python, shell,
ruby, assembly, agc_assembly, perl, embedded_python, zig, dockerfile, matlab,
makefile, markdown, csv, yaml, pbtxt, m4, tcl, nix, batch, jcl — so for the
other 18, a bare ; or % anywhere in the source (not just at a real comment position) gets
misdetected as a comment start and the rest of that line is silently discarded from
code_stream.
Worse, _strip_single_line_comments() does zero string-shielding — it runs the delimiter regex
directly against each raw line — so ;/% characters inside string literals trigger the
same false truncation, not just bare operator/statement-separator usage.
Concrete repro
from gitgalaxy.core.prism import Prism
from gitgalaxy.standards.language_standards import LANGUAGE_DEFINITIONS
from gitgalaxy.standards.gitgalaxy_config import LEXICAL_FAMILY_HEURISTICS
prism = Prism(LEXICAL_FAMILY_HEURISTICS, LANGUAGE_DEFINITIONS)
code = '''import re
SQL_TERMINATOR = r";"
def foo():
query = "SELECT 1;"
x = 1
return x
def bar():
y = 100 % 7
return y
'''
print(prism.split_streams(code, "python")["code_stream"])Output:
import re
SQL_TERMINATOR = r"
def foo():
query = "SELECT 1
x = 1
return x
def bar():
y =
return y
Three separate corruptions from three lines of ordinary Python:
r";"(a raw string containing just a semicolon) loses its closing quote and everything after."SELECT 1;"— the;inside the string literal truncates it mid-string.100 % 7— the modulo operator is misread as a comment start.
The first two also leave the code_stream with an odd/unbalanced quote count, which cascades into
the downstream #1184-class bug (_build_indentation_safe_stream desync) for any code after it
in the same file — so this bug's damage isn't limited to the corrupted line itself.
Impact
Found while re-measuring Python function-extraction recall against ast ground truth after
landing #1183 and #1184 (docs/language_status/python.md's measured-accuracy pass, via the real
production pipeline — prism.split_streams() → detector.splice() — not the isolated
_slice_by_indentation() call used to validate #1184 in isolation). Corpus-wide recall on
GitGalaxy's own 228-file Python self-scan corpus is still only ~60% (1465/2436 real functions,
via a fresh full self-scan) even with #1182/#1183/#1184 all fixed — this bug is the dominant
remaining cause. gitgalaxy/core/detector.py itself is a worst-case example (it's the file that
defines every language's comment delimiters and contains many raw-string/regex-pattern
literals): direct _slice_by_indentation() call finds 33/33 real functions, but through the
real pipeline only 11/33 survive.
Since ;/% are common in ordinary code across most of the 18 non-assembly/non-matlab
line_exclusive languages (statement separators, modulo operators, SQL/regex/URL string
content), this is very likely not Python-specific in practice — filed against Python because
that's where it was found and measured, but the fix belongs in the shared
_strip_single_line_comments()/_compile_single_line_delimiter_pattern() machinery in
prism.py, not a per-language patch.
Suggested fix direction (not yet implemented)
The line_exclusive family's delimiter list needs to be per-language, not one list shared
across all 20 members — e.g. each language's own lexical_family config should carry (or
resolve to) only its actual real delimiter token(s), the same way _build_brace_safe_stream
already does for C-family comment tokens. Separately, _strip_single_line_comments() shielding
zero string-literals before searching for delimiters is its own gap (see the "SELECT 1;" case
above) worth closing at the same time, following the same single-combined-pass pattern used to
fix #1184.
How this was found
Diffing GitGalaxy's own self-scan of its own repo against Python's ast module as ground
truth (same methodology as #1183/#1184), through the real production pipeline rather than an
isolated function call, while re-measuring accuracy for docs/language_status/python.md after
#1183/#1184 landed. Confirmed via a minimal 9-line reproduction, not inferred from the corpus
diff alone.
Activity
docs(language-status): refresh python.md's measured-accuracy pass after
ci(core): add AST-accuracy baseline-gated regression check (#1200)
fix(core): resolve line_exclusive comment delimiters per-language, no…