Repository navigation
Description
Summary
Found while fixing #1262 (Ruby func_start/Mode D 0/117 recall). After that
fix, 111/117 real methods in the language-crucible Ruby corpus are detected
-- the remaining 6 misses (all in rails/generator.rb) trace to a separate,
pre-existing bug in prism.py, not the detector.py Mode D logic #1262 fixed.
Root cause
Prism._strip_python_docstrings (in gitgalaxy/core/prism.py) is shared by
python/micropython/ruby (see _strip_segment_comments's call at the top of
that method). Its plain-string alternatives are:
'"(?:\\.|[^"\\])*"|'
"'(?:\\.|[^'\\])*'|"Neither re.DOTALL is set, so \\.'s . cannot match a literal newline.
When a double-quoted string uses backslash-newline line continuation --
legal in both Ruby and Python -- e.g.:
system "bundle exec dartsass \
#{@guides_dir}/assets/stylesrc/style.scss:#{@output_dir}/... \
...\""the plain-string alternative can't consume the \<newline> pair, so it never
matches the string as one atomic span. The regex falls through to the same
pattern's bare-comment alternative ((?:^|(?<=[ \t]))#[^\n]*), which then
matches Ruby's #{...} string-interpolation opener on each continuation
line (it looks exactly like a # comment start after leading whitespace)
and blanks the rest of that line to whitespace -- corrupting real code
(including, further down the file, def/end lines) for the rest of the
multi-line string's extent.
Confirmed via the language-crucible ruby corpus
(language-crucible/data/ruby/rails/generator.rb): def copy_assets,
def add_digests, def generate?, def output_file_for,
def output_path_for, and def generate_guide are all present in the raw
file but come back blanked to whitespace in prism's code_stream, causing
detector.py's Mode D scope-depth tracking to lose 6 real methods.
This isn't ruby-specific in principle -- Python also permits backslash-
continued string literals, so the same corruption shape should reproduce
there too (untested; ruby's #{...} interpolation syntax makes the failure
mode obvious, Python has no equivalent single-line lookalike marker
immediately after the continuation, so it may be latent/harder to trigger
there).
Suggested fix direction
Widen the plain-string alternatives' escape handling to cross newlines,
e.g. \\[\s\S] instead of \\., so a backslash-newline pair is consumed as
part of the string rather than left for a later alternative to misinterpret.
Needs the full Differential Scan protocol (crucible_check.py across all
languages, not just ruby) since _strip_python_docstrings is shared by
python/micropython/ruby -- out of scope for a ruby-only PR.
References
- Found while working [TIER 1] Ruby func_start matches 0/117 real methods in language-crucible corpus #1262 (epic Epic: Fix extraction accuracy gaps found by the tree-sitter accuracy audit #1261)
gitgalaxy/core/prism.py::Prism._strip_python_docstrings- Repro file:
language-crucible/data/ruby/rails/generator.rb
Activity
fix(core): Ruby func_start recurses into class/module bodies (0/117 -…
fix(core): eliminate exponential backtracking in UNTERMINATED_QUOTE_T…
fix(core): prism.py loses def/comment lines after a backslash-continu…