From 1c1a8d6355a52a89ce03f0b1e4858711081da593 Mon Sep 17 00:00:00 2001 From: David Thrane Christiansen Date: Sat, 16 Aug 2025 11:41:47 +0200 Subject: [PATCH 1/2] feat: improve argument syntax Adds deprecation warnings for the old named argument syntax, and adds flag syntax similar to that of tactics. --- doc/UsersGuide/Extensions.lean | 6 +- doc/UsersGuide/Markup.lean | 11 +- doc/UsersGuide/Output.lean | 4 +- examples/package-manual/PackageManual.lean | 6 +- .../PackageManual/DocFeatures.lean | 4 +- examples/textbook/DemoTextbook.lean | 8 +- .../website/DemoSite/Blog/AnchorBased.lean | 2 +- .../website/DemoSite/Blog/Conditionals.lean | 10 +- .../website/DemoSite/Blog/Subprojects.lean | 6 +- src/verso-blog/VersoBlog.lean | 63 ++++--- src/verso-manual/VersoManual/Docstring.lean | 22 ++- src/verso-manual/VersoManual/Glossary.lean | 2 +- src/verso-manual/VersoManual/InlineLean.lean | 65 +++---- .../VersoManual/InlineLean/IO.lean | 4 +- .../VersoManual/InlineLean/Signature.lean | 2 +- .../VersoManual/InlineLean/SyntaxError.lean | 2 +- src/verso-manual/VersoManual/Table.lean | 2 +- src/verso/Verso/Code/External.lean | 2 +- src/verso/Verso/Doc.lean | 4 +- src/verso/Verso/Doc/ArgParse.lean | 162 ++++++++++++---- src/verso/Verso/Doc/Elab.lean | 16 +- src/verso/Verso/Parser.lean | 177 ++++++++++++++---- src/verso/Verso/Syntax.lean | 6 +- 23 files changed, 414 insertions(+), 172 deletions(-) diff --git a/doc/UsersGuide/Extensions.lean b/doc/UsersGuide/Extensions.lean index d6f0970cb..9fa08d546 100644 --- a/doc/UsersGuide/Extensions.lean +++ b/doc/UsersGuide/Extensions.lean @@ -31,12 +31,14 @@ tag := "extension-syntax" All four extension points share a common syntax. They are invoked by name, with a sequence of arguments. These arguments may be positional or by name, and their values may be identifiers, string literals, or numbers. +Boolean flags may be passed by preceding their name with `-` or `+` for {lean}`false` or {lean}`true`, respectively. :::paragraph In this example, the directive `syntax` is invoked with the positional argument `term` and the named argument `title` set to `"Example"`. +The flag `check` is set to `false`. It contains a descriptive paragraph and the code block `grammar`, which is invoked with no arguments: ```` -:::syntax term (title := example) +:::syntax term (title := example) -check This is an example grammar: ```grammar term ::= term "<+-+>" term @@ -49,7 +51,7 @@ term ::= term "<+-+>" term More formally, an invocation of an extension should match this grammar: ``` CALL := IDENT ARG* -ARG := VAL | "(" IDENT ":=" VAL ")" +ARG := VAL | "(" IDENT ":=" VAL ")" | "+" IDENT | "-" IDENT VAL := IDENT | STRING | NUM ``` A `CALL` may occur after an opening fence on a code block. diff --git a/doc/UsersGuide/Markup.lean b/doc/UsersGuide/Markup.lean index 316cb4fb2..d00047f58 100644 --- a/doc/UsersGuide/Markup.lean +++ b/doc/UsersGuide/Markup.lean @@ -97,7 +97,7 @@ partial def preview (stx : Syntax) : m Std.Format := | `(block| command{$x $args*}) => do let args ← args.toList.mapM (preview ·.raw) pure s!"<{x.getId.toString} {Std.Format.prefixJoin " " args |>.pretty}/>" - | `(argument|$x:ident := $v) => do + | `(argument|($x:ident := $v)) | `(argument|$x:ident := $v) => do pure <| s!"{x.getId.toString}=\"{← preview v.raw}\"" | `(argument|$v:arg_val) => preview v.raw | `(arg_val|$v:ident) => pure s!"{v.getId}" @@ -419,6 +419,15 @@ Metadata blocks begin and end with `%%%`, and they contain any syntax that would ``` ::: +:::markupPreview "Blah" +``` +a b c +``` +``` +

a b c

+``` +::: + ## Block Syntax %%% diff --git a/doc/UsersGuide/Output.lean b/doc/UsersGuide/Output.lean index 73bdba854..8a08e77c8 100644 --- a/doc/UsersGuide/Output.lean +++ b/doc/UsersGuide/Output.lean @@ -56,7 +56,7 @@ The differences are: * Interpolated Lean strings (with `s!`) may be used in any context that expects a string. For example, this definition creates a `