theory Cartouche_Examples imports Main
keywords "cartouche" :: diag begin
subsection‹Regular outer syntax›
text‹Text cartouches may be used in the outer syntax category ‹text›,
as alternative to the traditional ‹verbatim› tokens. An example is
this text block.› ― ‹The same works for small side-comments.›
notepad begin txt‹Cartouches work as additional syntax for embedded language tokens
(types, terms, props) and as a replacement for the ‹altstring› category
(for literal fact references). For example:›
fix x y :: 'a assume‹x = y› note‹x = y› have‹x = y›by (rule ‹x = y›) from‹x = y›have‹x = y› .
txt‹Of course, this can be nested inside formal comments and
antiquotations, e.g. like this @{thm ‹x = y›} or this @{thm sym
[OF ‹x = y›]}.›
have‹x = y› by (tactic ‹resolve_tac 🍋 @{thms ‹x = y›} 1›)
― ‹more cartouches involving ML› end
subsection‹Outer syntax: cartouche within command syntax›
ML ‹
Outer_Syntax.command 🍋‹cartouche› ""
(Parse.cartouche >> (fn s =>
Toplevel.keep (fn _ => writeln s))) ›
cartouche ‹abc›
cartouche ‹abc ‹αβγ› xzy›
subsection‹Inner syntax: string literals via cartouche›
ML ‹
local
fun mk_char (s, pos) =
let
val c =
if Symbol.is_ascii s then ord s
else if s = "🍋" then 10
else error ("String literal contains illegal symbol: " ^ quote s ^ Position.here pos);
in list_comb (Syntax.const 🍋‹Char›, String_Syntax.mk_bits_syntax 8 c) end;
fun mk_string [] = Const (🍋‹Nil›, 🍋‹string›)
| mk_string (s :: ss) =
Syntax.const 🍋‹Cons› $ mk_char s $ mk_string ss;
in
fun string_tr content args =
let fun err () = raise TERM ("string_tr", args) in
(case args of
[(c as Const (🍋‹_constrain›, _)) $ Free (s, _) $ p] =>
(case Term_Position.decode_position1 p of
SOME {pos, ...} => c $ mk_string (content (s, pos)) $ p
| NONE => err ())
| _ => err ())
end;
end; ›
lemma‹A ∧ B ⟶ B ∧ A› by (‹resolve_tac 🍋 @{thms impI} 1›, ‹eresolve_tac 🍋 @{thms conjE} 1›, ‹resolve_tac 🍋 @{thms conjI} 1›, ‹assume_tac 🍋 1›+)
subsection‹ML syntax›
text‹Input source with position information:›
ML ‹
val s: Input.source = ‹abc123def456›;
Output.information ("Look here!" ^ Position.here (Input.pos_of s));
‹abc123def456› |> Input.source_explode |> List.app (fn (s, pos) =>
if Symbol.is_digit s then Position.report pos Markup.ML_numeral else ()); ›
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.