Skip to content

Commit 6c9c806

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 5d3b191 commit 6c9c806

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/verso-blog/VersoBlog.lean

Lines changed: 8 additions & 8 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
@@ -470,7 +470,7 @@ def leanInit : CodeBlockExpanderOf LeanInitBlockConfig
470470
if header.raw[1].isNone then -- if the "prelude" option was not set, use the current env
471471
let commandState := configureCommandState (← getEnv) {}
472472
let commandState := { commandState with scopes := [{ header := "", opts := pp.tagAppFns.set {} true }] }
473-
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState state)}
473+
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState)}
474474
else
475475
if header.raw[2].getArgs.isEmpty then
476476
let (env, msgs) ← processHeader header opts msgs context 0
@@ -480,7 +480,7 @@ def leanInit : CodeBlockExpanderOf LeanInitBlockConfig
480480
liftM (m := IO) (throw <| IO.userError "Errors during import; aborting")
481481
let commandState := configureCommandState env {}
482482
let commandState := { commandState with scopes := [{ header := "", opts := pp.tagAppFns.set {} true }] }
483-
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState state)}
483+
modifyEnv <| fun env => exampleContextExt.modifyState env fun s => {s with contexts := s.contexts.insert config.exampleContext.getId (.inline commandState)}
484484
if config.show then
485485
``(Block.code $(quote str.getString)) -- TODO highlighting hack
486486
else
@@ -494,8 +494,8 @@ open SubVerso.Highlighting Highlighted in
494494
def lean : CodeBlockExpanderOf LeanBlockConfig
495495
| config, str => withTraceNode `Elab.Verso.block.lean (fun _ => pure m!"lean block") <| withoutAsync do
496496
let x := config.exampleContext
497-
let (commandState, _state)match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
498-
| some (.inline commandState state) => pure (commandState, state)
497+
let commandState ← match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
498+
| some (.inline commandState) => pure (commandState)
499499
| some (.subproject ..) => throwErrorAt x "Expected an example context for inline Lean, but found a subproject"
500500
| some (.module ..) => throwErrorAt x "Expected an example context for inline Lean, but found a module"
501501
| none => throwErrorAt x "Can't find example context"
@@ -527,7 +527,7 @@ def lean : CodeBlockExpanderOf LeanBlockConfig
527527

528528
if config.keep && !config.error then
529529
modifyEnv fun env => exampleContextExt.modifyState env fun st => {st with
530-
contexts := st.contexts.insert x.getId (.inline {s.commandState with messages := {} } s.parserState)
530+
contexts := st.contexts.insert x.getId (.inline {s.commandState with messages := {} })
531531
}
532532
if let some infoName := config.name then
533533
modifyEnv fun env => messageContextExt.modifyState env fun st => {st with
@@ -633,8 +633,8 @@ def leanInline : RoleExpanderOf LeanInlineConfig
633633
let `(inline|code( $str:str )) := code
634634
| throwErrorAt code "Expected an inline code element"
635635
let x := config.exampleContext
636-
let (commandState, _)match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
637-
| some (.inline commandState state) => pure (commandState, state)
636+
let commandState ← match exampleContextExt.getState (← getEnv) |>.contexts.find? x.getId with
637+
| some (.inline commandState) => pure commandState
638638
| some (.subproject ..) => throwErrorAt x "Expected an example context for inline Lean, but found a subproject"
639639
| some (.module ..) => throwErrorAt x "Expected an example context for inline Lean, but found a module"
640640
| none => throwErrorAt x "Can't find example context"

0 commit comments

Comments
 (0)