I/R: Add Ir.init_with_header for keyword-aware theory init#228
Open
ike-mulder-aws wants to merge 1 commit into
Open
I/R: Add Ir.init_with_header for keyword-aware theory init#228ike-mulder-aws wants to merge 1 commit into
ike-mulder-aws wants to merge 1 commit into
Conversation
A .thy file may declare new outer-syntax keywords in its header
(`theory T imports Main keywords "frobnicate" :: thy_decl begin`).
Ir.init has no way to declare such keywords on the new theory, so a
subsequent ML step using
Outer_Syntax.local_theory @{command_keyword frobnicate} fails with
"Bad outer syntax command". This blocks replaying any .thy that
declares new keywords.
Add Ir.init_with_header taking a {clauses: string} record. The clauses
text is the literal content between `imports ...` and `begin` in a .thy
header — typically a `keywords` clause. We synthesize a fake header,
parse it via Thy_Header.read, and chain Thy_Header.add_keywords on the
freshly-built theory. The other valid header clause — `abbrevs`,
declaring jEdit autocomplete abbreviations — is parsed-and-discarded
by Isabelle itself (it has no ML-level effect), so extracting #keywords
captures everything that matters at the theory level.
Ir.init becomes a one-line forwarder: no caller breakage. Segment
specs are rejected when clauses is non-empty — recorded segments
already carry their .thy's keywords.
Tests:
- test_register_keyword_fails_without_header: demonstrates the gap.
- test_init_with_header_succeeds_for_keyword: inverse, with the same
ML step succeeding once keywords are declared at init time.
- test_init_with_header_empty_clauses_is_noop and
test_init_with_header_rejects_segment.
Signed-off-by: Ike Mulder <ikemul@amazon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A .thy file may declare new outer-syntax keywords in its header (
theory T imports Main keywords "frobnicate" :: thy_decl begin). Ir.init has no way to declare such keywords on the new theory, so a subsequent ML step usingOuter_Syntax.local_theory @{command_keyword frobnicate} fails with "Bad outer syntax command". This blocks replaying any .thy that declares new keywords.
Add Ir.init_with_header taking a {clauses: string} record. The clauses text is the literal content between
imports ...andbeginin a .thy header — typically akeywordsclause. We synthesize a fake header, parse it via Thy_Header.read, and chain Thy_Header.add_keywords on the freshly-built theory. The other valid header clause —abbrevs, declaring jEdit autocomplete abbreviations — is parsed-and-discarded by Isabelle itself (it has no ML-level effect), so extracting #keywords captures everything that matters at the theory level.Ir.init becomes a one-line forwarder: no caller breakage. Segment specs are rejected when clauses is non-empty — recorded segments already carry their .thy's keywords.
Tests:
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.