# HG changeset patch # User wenzelm # Date 1417354980 -3600 # Node ID 8606f2ee11b14109f6a10a1219987e38e377138b # Parent dd8ec9138112535691a5204c3185feae77e22ae4 update_cartouches; diff -r dd8ec9138112 -r 8606f2ee11b1 src/HOL/ex/Cartouche_Examples.thy --- a/src/HOL/ex/Cartouche_Examples.thy Sun Nov 30 14:02:48 2014 +0100 +++ b/src/HOL/ex/Cartouche_Examples.thy Sun Nov 30 14:43:00 2014 +0100 @@ -1,4 +1,4 @@ -section {* Some examples with text cartouches *} +section \Some examples with text cartouches\ theory Cartouche_Examples imports Main @@ -7,7 +7,7 @@ "text_cartouche" :: thy_decl begin -subsection {* Regular outer syntax *} +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 @@ -33,21 +33,21 @@ end -subsection {* Outer syntax: cartouche within command syntax *} +subsection \Outer syntax: cartouche within command syntax\ -ML {* +ML \ Outer_Syntax.command @{command_spec "cartouche"} "" (Parse.cartouche >> (fn s => Toplevel.imperative (fn () => writeln s))) -*} +\ cartouche \abc\ cartouche \abc \\\\\ xzy\ -subsection {* Inner syntax: string literals via cartouche *} +subsection \Inner syntax: string literals via cartouche\ -ML {* +ML \ local val mk_nib = Syntax.const o Lexicon.mark_const o @@ -76,14 +76,14 @@ | _ => err ()) end; end; -*} +\ syntax "_cartouche_string" :: "cartouche_position \ string" ("_") -parse_translation {* +parse_translation \ [(@{syntax_const "_cartouche_string"}, K (string_tr (Symbol_Pos.cartouche_content o Symbol_Pos.explode)))] -*} +\ term "\\" term "\abc\" @@ -92,15 +92,15 @@ term "\\001\010\100\" -subsection {* Alternate outer and inner syntax: string literals *} +subsection \Alternate outer and inner syntax: string literals\ -subsubsection {* Nested quotes *} +subsubsection \Nested quotes\ syntax "_string_string" :: "string_position \ string" ("_") -parse_translation {* +parse_translation \ [(@{syntax_const "_string_string"}, K (string_tr Lexicon.explode_string))] -*} +\ term "\"\"" term "\"abc\"" @@ -109,9 +109,9 @@ term "\"\001\010\100\"" -subsubsection {* Term cartouche and regular quotes *} +subsubsection \Term cartouche and regular quotes\ -ML {* +ML \ Outer_Syntax.command @{command_spec "term_cartouche"} "" (Parse.inner_syntax Parse.cartouche >> (fn s => Toplevel.keep (fn state => @@ -119,7 +119,7 @@ val ctxt = Toplevel.context_of state; val t = Syntax.read_term ctxt s; in writeln (Syntax.string_of_term ctxt t) end))) -*} +\ term_cartouche \""\ term_cartouche \"abc"\ @@ -128,34 +128,34 @@ term_cartouche \"\001\010\100"\ -subsubsection {* Further nesting: antiquotations *} +subsubsection \Further nesting: antiquotations\ setup -- "ML antiquotation" -{* +\ ML_Antiquotation.inline @{binding term_cartouche} (Args.context -- Scan.lift (Parse.inner_syntax Parse.cartouche) >> (fn (ctxt, s) => ML_Syntax.atomic (ML_Syntax.print_term (Syntax.read_term ctxt s)))) -*} +\ setup -- "document antiquotation" -{* +\ Thy_Output.antiquotation @{binding ML_cartouche} (Scan.lift Args.cartouche_source_position) (fn {context, ...} => fn source => let val toks = ML_Lex.read "fn _ => (" @ ML_Lex.read_source false source @ ML_Lex.read ");"; val _ = ML_Context.eval_in (SOME context) ML_Compiler.flags (Input.pos_of source) toks; in "" end); -*} +\ -ML {* +ML \ @{term_cartouche \""\}; @{term_cartouche \"abc"\}; @{term_cartouche \"abc" @ "xyz"\}; @{term_cartouche \"\"\}; @{term_cartouche \"\001\010\100"\}; -*} +\ -text {* +text \ @{ML_cartouche \ ( @@ -167,16 +167,16 @@ ) \ } -*} +\ -subsubsection {* Uniform nesting of sub-languages: document source, ML, term, string literals *} +subsubsection \Uniform nesting of sub-languages: document source, ML, term, string literals\ -ML {* +ML \ Outer_Syntax.command @{command_spec "text_cartouche"} "" (Parse.opt_target -- Parse.source_position Parse.cartouche >> Thy_Output.document_command) -*} +\ text_cartouche \ @@ -194,9 +194,9 @@ \ -subsection {* Proof method syntax: ML tactic expression *} +subsection \Proof method syntax: ML tactic expression\ -ML {* +ML \ structure ML_Tactic: sig val set: (Proof.context -> tactic) -> Proof.context -> Proof.context @@ -215,15 +215,15 @@ (ML_Lex.read "fn ctxt: Proof.context =>" @ ML_Lex.read_source false source)); in Data.get ctxt' ctxt end; end; -*} +\ -subsubsection {* Explicit version: method with cartouche argument *} +subsubsection \Explicit version: method with cartouche argument\ -method_setup ml_tactic = {* +method_setup ml_tactic = \ Scan.lift Args.cartouche_source_position >> (fn arg => fn ctxt => SIMPLE_METHOD (ML_Tactic.ml_tactic arg ctxt)) -*} +\ lemma "A \ B \ B \ A" apply (ml_tactic \rtac @{thm impI} 1\) @@ -234,17 +234,17 @@ lemma "A \ B \ B \ A" by (ml_tactic \blast_tac ctxt 1\) -ML {* @{lemma "A \ B \ B \ A" by (ml_tactic \blast_tac ctxt 1\)} *} +ML \@{lemma "A \ B \ B \ A" by (ml_tactic \blast_tac ctxt 1\)}\ -text {* @{ML "@{lemma \"A \ B \ B \ A\" by (ml_tactic \blast_tac ctxt 1\)}"} *} +text \@{ML "@{lemma \"A \ B \ B \ A\" by (ml_tactic \blast_tac ctxt 1\)}"}\ -subsubsection {* Implicit version: method with special name "cartouche" (dynamic!) *} +subsubsection \Implicit version: method with special name "cartouche" (dynamic!)\ -method_setup "cartouche" = {* +method_setup "cartouche" = \ Scan.lift Args.cartouche_source_position >> (fn arg => fn ctxt => SIMPLE_METHOD (ML_Tactic.ml_tactic arg ctxt)) -*} +\ lemma "A \ B \ B \ A" apply \rtac @{thm impI} 1\