Skip to content

Commit

Permalink
Try to use a table (need help with the error)
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeata committed Jan 17, 2025
1 parent e18cb0c commit 56b0219
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Manual/Meta/Monotonicity.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ import Manual.Meta.Lean
import Manual.Meta.Table

open Lean Meta Elab
open Verso Doc Elab
open Verso Doc Elab Manual
open SubVerso.Highlighting Highlighted


namespace Manual

def mkTable (rows : Array (Array Syntax)) (header : String) (name : String) : TermElabM Term := do
if h : rows.size = 0 then
throwError "Expected at least one row"
else
let columns := rows[0].size
if columns = 0 then
throwError "Expected at least one column"
if rows.any (·.size != columns) then
throwError s!"Expected all rows to have same number of columns, but got {rows.map (·.size)}"

let blocks : Array (Syntax.TSepArray `term ",") := rows.map (Syntax.TSepArray.mk)
``(Block.other (Block.table $(quote columns) $(quote header) $(quote name)) #[Block.ul #[$[Verso.Doc.ListItem.mk #[$blocks,*]],*]])

@[block_role_expander monotonicityLemmas]
def monotonicityLemmas : BlockRoleExpander
| #[], #[] => do
let names := (Meta.Monotonicity.monotoneExt.getState (← getEnv)).values
let names := names.qsort (toString · < toString ·)

let itemStx : TSyntaxArray `term ← names.mapM fun name => do
let rows : Array (Array Syntax) ← names.mapM fun name => do
-- Extract the target pattern
let ci ← getConstInfo name
let targetStx : TSyntax `term
Expand All @@ -42,10 +55,10 @@ def monotonicityLemmas : BlockRoleExpander

let hl : Highlighted ← constTok name name.toString
let nameStx ← `(Inline.other {Inline.name with data := ToJson.toJson $(quote hl)} #[Inline.code $(quote name.getString!)])
`(Verso.Doc.Block.para #[$nameStx, Inline.text ": applies to ", $targetStx])
pure #[nameStx, targetStx]

let theList`(Verso.Doc.Block.ul #[$[⟨#[$itemStx]⟩],*])
return #[theList]
let tableStxmkTable rows "foo" "bar"
return #[tableStx]
| _, _ => throwError "Unexpected arguments"

-- #eval do
Expand Down

0 comments on commit 56b0219

Please sign in to comment.