Skip to content

Commit fe3239b

Browse files
hyperpolymathclaude
andcommitted
fix(extractors): UTF-8 byte indexing + empty-captures guards
extract_mathlib4.jl: `length(m.match)` counts characters but `content[]` indexes bytes; fall back to `ncodeunits(m.match)` so multi-byte Lean sources (Unicode operators) don't hit StringIndexError mid-file. extract_hol4.jl: DISCH_TAC-style regex have zero capture groups; guard `hyp_match.captures[1]` with `isempty(hyp_match.captures)` to stop the crash that killed the premise pass after writing all 127k proof_states. Corpus impact: hol4 now emits ~140k premise records, mathlib4 no longer flags every file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 65e6a45 commit fe3239b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

scripts/extract_hol4.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ function run()::Tuple{Int,Int}
542542
thm_name = entry["theorem"]
543543
for hyp_pattern in hol4_hyp_patterns
544544
for hyp_match in eachmatch(hyp_pattern, proof_text)
545+
# `DISCH_TAC` et al. match without capturing; skip rather than
546+
# indexing into an empty captures vector (BoundsError).
547+
isempty(hyp_match.captures) && continue
545548
raw = hyp_match.captures[1] === nothing ? "" : hyp_match.captures[1]
546549
hyps = [strip(h) for h in split(raw, ',')]
547550
for hyp in hyps

scripts/extract_mathlib4.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ function extract_mathlib4_proofs()
7474
)
7575
push!(proof_states, proof_state)
7676

77-
# Look for proof tactics (simplified)
78-
proof_start = m.offset + length(m.match)
79-
remaining_content = content[min(proof_start, end):end]
77+
# Look for proof tactics (simplified). Use byte lengths:
78+
# `length(m.match)` counts characters, not bytes, and indexing
79+
# a `String` by a char index that lands mid-UTF-8 throws
80+
# StringIndexError — common for mathlib4 files with Unicode.
81+
proof_start = m.offset + ncodeunits(m.match)
82+
remaining_content = content[min(proof_start, ncodeunits(content)+1):end]
8083

8184
# Extract tactics from the "by" clause
8285
by_match = match(r"by\s+([^\n]+)", remaining_content)

0 commit comments

Comments
 (0)