Skip to content

Commit dbf1cd1

Browse files
committed
refactor: remove unused parser state in example's environment extension
Only `Command.State` is needed to thread several example blocks. Note that before we used the parsing state resulting from the last code block, so we did resume from an offset that could be potentially much before the current code block. This worked as the string in that case was empty (produced by `parserInputString`), but would have failed once we have reuse of the input source string.
1 parent a9c31d5 commit dbf1cd1

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/verso-blog/VersoBlog.lean

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ where
196196
section
197197

198198
inductive LeanExampleData where
199-
| inline (commandState : Command.State) (parserState : Parser.ModuleParserState)
199+
| inline (commandState : Command.State)
200200
| subproject (loaded : NameSuffixMap Example)
201201
| module (positioned : Array ModuleItem)
202202
deriving Inhabited
@@ -447,7 +447,7 @@ def leanInit : CodeBlockExpanderOf LeanInitBlockConfig
447447
if header.raw[1].isNone then -- if the "prelude" option was not set, use the current env
448448
let commandState := configureCommandState (← getEnv) {}
449449
let commandState := { commandState with scopes := [{ header := "", opts := pp.tagAppFns.set {} true }] }
450-
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState state)}
450+
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState)}
451451
else
452452
if header.raw[2].getArgs.isEmpty then
453453
let (env, msgs) ← processHeader header opts msgs context 0
@@ -457,7 +457,7 @@ def leanInit : CodeBlockExpanderOf LeanInitBlockConfig
457457
liftM (m := IO) (throw <| IO.userError "Errors during import; aborting")
458458
let commandState := configureCommandState env {}
459459
let commandState := { commandState with scopes := [{ header := "", opts := pp.tagAppFns.set {} true }] }
460-
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState state)}
460+
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState)}
461461
if config.show then
462462
``(Block.code $(quote str.getString)) -- TODO highlighting hack
463463
else
@@ -471,16 +471,17 @@ open SubVerso.Highlighting Highlighted in
471471
def lean : CodeBlockExpanderOf LeanBlockConfig
472472
| config, str => withTraceNode `Elab.Verso.block.lean (fun _ => pure m!"lean block") <| withoutAsync do
473473
let x := config.exampleContext
474-
let (commandState, state)match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
475-
| some (.inline commandState state) => pure (commandState, state)
474+
let commandState ← match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
475+
| some (.inline commandState) => pure (commandState)
476476
| some (.subproject ..) => throwErrorAt x "Expected an example context for inline Lean, but found a subproject"
477477
| some (.module ..) => throwErrorAt x "Expected an example context for inline Lean, but found a module"
478478
| none => throwErrorAt x "Can't find example context"
479479
let (context, startPos) ← strLitInputContext str.raw (← getFileName)
480+
let state := { pos := startPos }
480481
-- Process with empty messages to avoid duplicate output
481482
let s ←
482483
withTraceNode `Elab.Verso.block.lean (fun _ => pure m!"Elaborating commands") <|
483-
IO.processCommands context { state with pos := startPos } { commandState with messages.unreported := {} }
484+
IO.processCommands context state { commandState with messages.unreported := {} }
484485
for t in s.commandState.infoState.trees do
485486
pushInfoTree t
486487

@@ -501,7 +502,7 @@ def lean : CodeBlockExpanderOf LeanBlockConfig
501502

502503
if config.keep && !config.error then
503504
modifyEnv fun env => exampleContextExt.modifyState env fun st => {st with
504-
contexts := st.contexts.insert x.getId (.inline {s.commandState with messages := {} } s.parserState)
505+
contexts := st.contexts.insert x.getId (.inline {s.commandState with messages := {} })
505506
}
506507
if let some infoName := config.name then
507508
modifyEnv fun env => messageContextExt.modifyState env fun st => {st with
@@ -606,8 +607,8 @@ private def leanInlineImpl : RoleExpanderOf LeanInlineConfig
606607
let `(inline|code( $str:str )) := code
607608
| throwErrorAt code "Expected an inline code element"
608609
let x := config.exampleContext
609-
let (commandState, _)match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
610-
| some (.inline commandState state) => pure (commandState, state)
610+
let commandState ← match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
611+
| some (.inline commandState) => pure commandState
611612
| some (.subproject ..) => throwErrorAt x "Expected an example context for inline Lean, but found a subproject"
612613
| some (.module ..) => throwErrorAt x "Expected an example context for inline Lean, but found a module"
613614
| none => throwErrorAt x "Can't find example context"

0 commit comments

Comments
 (0)