Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  Cartouche_Examples.thy

  Sprache: Isabelle
 

(*  Title:      HOL/ex/Cartouche_Examples.thy
    Author:     Makarius
*)


section Some examples with text cartouches

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 context @{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 const_syntaxChar, String_Syntax.mk_bits_syntax 8 c) end;

 fun mk_string [] = Const (const_syntaxNil, typstring)
 | mk_string (s :: ss) =
 Syntax.const const_syntaxCons $ 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 (syntax_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;
 


syntax "_cartouche_string" :: cartouche_position string  (_)

parse_translation 
 [(syntax_const_cartouche_string,
 K (string_tr (Symbol_Pos.cartouche_content o Symbol_Pos.explode)))]
 


term 
term abc
term abc @ xyz
term 🚫


subsection Alternate outer and inner syntax: string literals

subsubsection Nested quotes

syntax "_string_string" :: string_position string  (_)

parse_translation 
 [(syntax_const_string_string, K (string_tr Lexicon.explode_string))]
 


term ""
term "abc"
term "abc" @ "xyz"
term "🚫"
term "\001\010\100"


subsubsection Further nesting: antiquotations

ML 
 term"";
 term"abc";
 term"abc" @ "xyz";
 term"🚫";
 term"\001\010\100";
 


text 
 🚫
 (
 term"";
 term"abc";
 term"abc" @ "xyz";
 term"🚫";
 term"\001\010\100"
 )
 

 



subsubsection Uniform nesting of sub-languages: document source, ML, term, string literals

text

 🚫
 (
 term"";
 term"abc";
 term"abc" @ "xyz";
 term"🚫";
        \<^term>\<open>"\001\010\100"\<close>
      )
    \<close>
\<close>


subsection \<open>Proof method syntax: ML tactic expression\<close>

ML \<open>
structure ML_Tactic:
sig
  val set: (Proof.context -> tactic) -> Proof.context -> Proof.context
  val ml_tactic: Input.source -> Proof.context -> tactic
end =
struct
  structure Data = Proof_Data(type T = Proof.context -> tactic fun init _ = K no_tac);

  val set = Data.put;

  fun ml_tactic source ctxt =
    let
      val ctxt' = ctxt
        |> Context.proof_map (ML_Context.expression (Input.pos_of source)
          (ML_Lex.read "Theory.local_setup (ML_Tactic.set (fn ctxt: Proof.context => (" @
           ML_Lex.read_source source @ ML_Lex.read ")))"));
    in Data.get ctxt' ctxt end;
end
\<close>


subsubsection \<open>Explicit version: method with cartouche argument\<close>

method_setup ml_tactic = \<open>
  Scan.lift Args.cartouche_input
    >> (fn arg => fn ctxt => SIMPLE_METHOD (ML_Tactic.ml_tactic arg ctxt))
\<close>

lemma \<open>A \<and> B \<longrightarrow> B \<and> A\<close>
  apply (ml_tactic \<open>resolve_tac \<^context> @{thms impI} 1\<close>)
  apply (ml_tactic \<open>eresolve_tac \<^context> @{thms conjE} 1\<close>)
  apply (ml_tactic \<open>resolve_tac \<^context> @{thms conjI} 1\<close>)
  apply (ml_tactic \<open>ALLGOALS (assume_tac \<^context>)\<close>)
  done

lemma \<open>A \<and> B \<longrightarrow> B \<and> A\<close> by (ml_tactic \<open>blast_tac ctxt 1\<close>)

ML \<open>@{lemma \<open>A \<and> B \<longrightarrow> B \<and> A\<close> by (ml_tactic \<open>blast_tac ctxt 1\<close>)}\<close>

text \<open>\<^ML>\<open>@{lemma \<open>A \<and> B \<longrightarrow> B \<and> A\<close> by (ml_tactic \<open>blast_tac ctxt 1\<close>)}\<close>\<close>


subsubsection \<open>Implicit version: method with special name "cartouche" (dynamic!)\<close>

method_setup "cartouche" = \<open>
  Scan.lift Args.cartouche_input
    >> (fn arg => fn ctxt => SIMPLE_METHOD (ML_Tactic.ml_tactic arg ctxt))
\<close>

lemma \<open>A \<and> B \<longrightarrow> B \<and> A\<close>
  apply \<open>resolve_tac \<^context> @{thms impI} 1\<close>
  apply \<open>eresolve_tac \<^context> @{thms conjE} 1\<close>
  apply \<open>resolve_tac \<^context> @{thms conjI} 1\<close>
  apply \<open>ALLGOALS (assume_tac \<^context>)\<close>
  done

lemma \<open>A \<and> B \<longrightarrow> B \<and> A\<close>
  by (\<open>resolve_tac \<^context> @{thms impI} 1\<close>,
    \<open>eresolve_tac \<^context> @{thms conjE} 1\<close>,
    \<open>resolve_tac \<^context> @{thms conjI} 1\<close>,
    \<open>assume_tac \<^context> 1\<close>+)


subsection \<open>ML syntax\<close>

text \<open>Input source with position information:\<close>
ML \<open>
  val s: Input.source = \<open>abc123def456\<close>;
  Output.information ("Look here!" ^ Position.here (Input.pos_of s));

  \<open>abc123def456\<close> |> Input.source_explode |> List.app (fn (s, pos) =>
    if Symbol.is_digit s then Position.report pos Markup.ML_numeral else ());
\<close>

end

Messung V0.5 in Prozent
C=88 H=93 G=90

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002