1 (* Title: src/Tools/isac/BridgeJEdit/Calculation.thy
2 Author: Walther Neuper, JKU Linz
3 (c) due to copyright terms
5 Outer syntax for Isabelle/Isac's Calculation.
10 (**)"~~/src/Tools/isac/Knowledge/Build_Thydata" (*remove after devel.of BridgeJEdit*)
11 (**)"~~/src/Tools/isac/MathEngine/MathEngine"
12 (**)"HOL-SPARK.SPARK" (*remove after devel.of BridgeJEdit*)
14 "Example" :: thy_load (*(isac_example)~(spark_vcg) ..would involve registering in Isabelle/Scala*)
15 and(**)"Problem" :: thy_decl (*r oot-problem + recursively in Solution *)
16 and "Specification" "Model" "References" :: diag (* structure only *)
17 and "Solution" :: thy_decl (* structure only *)
18 and "Where" "Given" "Find" "Relate" :: prf_decl (* await input of term *)
19 (*and "Where" (* only output, preliminarily *)*)
20 and "RTheory" :: thy_decl (* await input of string; "R" distingues "Problem".."RProblem" *)
21 and "RProblem" "RMethod" :: thy_decl (* await input of string list *)
22 and "Tactic" (* optional for each step 0..end of calculation *)
24 (** )declare [[ML_print_depth = 99999]]( **)
26 ML_file preliminary.sml
29 section \<open>new code for Outer_Syntax Example, Problem, ...\<close>
31 code for Example, Problem shifted into structure Preliminary.
34 subsubsection \<open>cp from Pure.thy\<close>
36 \<close> ML \<open> (* for "from" ~~ "Given:" *)
38 val facts = Parse.and_list1 Parse.thms1;
39 facts: (Facts.ref * Token.src list) list list parser;
42 (writeln "####-## from parser";
43 Parse.$$$ ":" |-- Parse.and_list1 Parse.thms1)(** ) --| Parse.$$$ "Where"( **);
44 facts: (Facts.ref * Token.src list) list list parser;
49 subsubsection \<open>tools to analyse parsing in Outer_Syntax >> \<close>
51 \<close> text \<open> (*original basics.ML*)
52 op |>> : ('a * 'b) * ('a -> 'c) -> 'c * 'b;
53 fun (x, y) |>> f = (f x, y);
54 \<close> text \<open> (*original scan.ML*)
55 op >> : ('a -> 'b * 'c) * ('b -> 'd) -> 'a -> 'd * 'c; (*---vvv*)
56 fun (scan >> f) xs = scan xs |>> f;
58 \<close> ML \<open> (*cp.from originals*)
60 fun (scan @>> f) xs = scan xs |>> f;
61 op @>> : ('a -> 'b * 'c) * ('b -> 'd) -> 'a -> 'd * 'c; (*---^^^*)
62 \<close> ML \<open> (*appl.to parser*)
63 op @>> : (Token.src -> 'b * Token.src) * ('b -> 'd) -> Token.src -> 'd * Token.src; (*---^^^*)
65 \<close> ML \<open> (*add analysis*)
67 datatype T = Pos of (int * int * int) * Properties.T;
69 fun s_to_string (Pos ((line, offset, end_offset), _)) = ("Pos ((" ^
70 string_of_int line ^ ", " ^ string_of_int offset ^ ", " ^ string_of_int end_offset ^ "), [_])")
72 s_to_string: src -> string
74 datatype T = Token of (Symbol_Pos.text * Position.range) * (kind * string) * slot
76 Token.pos_of; (*^^^^^^^^^^^^^^^*)
77 Token.end_pos_of; (*^^^^^^^^^^^^^*)
78 Token.unparse; (*^^^^^^^^^^^^^*)
80 fun string_of_tok tok = ("\nToken ((" ^
81 Position.to_string (Token.pos_of tok) ^ ", " ^
82 Position.to_string (Token.end_pos_of tok) ^ "), " ^
83 Token.unparse tok ^ ", _)")
85 fun string_of_toks toks = fold (curry op ^) (map string_of_tok toks |> rev |> separate ", ") "";
86 string_of_toks: Token.src -> string;
88 Token.s_to_string: Token.src -> string; (*<-- string_of_toks WN*)
90 fun (scan @>> f) xs = (@{print}{a = "_ >> ", toks = xs(*GIVES\<rightarrow>"?"*)}; scan xs) |>> f;
91 fun (scan @>> f) xs = (writeln ("toks= " ^ Token.s_to_string xs); scan xs) |>> f;
92 op @>> : (Token.src -> 'b * Token.src) * ('b -> 'd) -> Token.src -> 'd * Token.src; (*---^^^*)
94 op @>> : (Token.T list -> 'a * 'b) * ('a -> 'c) -> Token.T list -> 'c * 'b
96 \<close> ML \<open> (*Scan < Token in bootstrap, thus we take Token.s_to_string as argument of >> *)
99 fun ((write, scan) @@>> f) xs = (write xs; scan xs) |>> f;
100 op @@>> : (('a -> 'b) * ('a -> 'c * 'd)) * ('c -> 'e) -> 'a -> 'e * 'd
104 subsubsection \<open>TODO\<close>
111 section \<open>setup command_keyword + preliminary test\<close>
115 Outer_Syntax.command \<^command_keyword>\<open>Example\<close> "start a Calculation from a Formalise-file"
116 (Resources.provide_parse_file -- Parse.parname
117 >> (Toplevel.theory o (*vvvvvvvvvvvvvvvvvvvv--- HACK makes test independent from session Isac*)
118 (Preliminary.load_formalisation @{theory Biegelinie} ParseC.formalisation)) );
121 Outer_Syntax.command \<^command_keyword>\<open>Problem\<close>
122 "start a Specification, either from scratch or from preceding 'Example'"
123 ((writeln o Token.s_to_string, ParseC.problem_headline)
124 @@>> (Toplevel.theory o Preliminary.init_specify));
126 Preliminary.init_specify: ParseC.problem_headline -> theory -> theory;
127 (Toplevel.theory o Preliminary.init_specify)
128 : ParseC.problem_headline -> Toplevel.transition -> Toplevel.transition;
130 (**) Preliminary.init_specify: ParseC.problem_headline -> theory -> theory;(**)
132 (**)(Toplevel.theory o Preliminary.init_specify):
133 ParseC.problem_headline -> Toplevel.transition -> Toplevel.transition;(**)
134 (* ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^*)
136 fun dummy (_(*":"*): string) thy =
138 val refs' = Refs_Data.get thy
139 val o_model = OMod_Data.get thy
140 val i_model = IMod_Data.get thy
142 @{print} {a = "### dummy Specification", refs = refs', o_model = o_model, i_model = i_model}
146 Outer_Syntax.command \<^command_keyword>\<open>Specification\<close> "Specification dummy"
147 ((writeln o Token.s_to_string, Parse.$$$ ":") @@>> (Toplevel.theory o dummy))
150 Outer_Syntax.command \<^command_keyword>\<open>Model\<close> "Model dummy"
151 ((writeln o Token.s_to_string, Parse.$$$ ":") @@>> (Toplevel.theory o dummy))
154 Outer_Syntax.command \<^command_keyword>\<open>Given\<close> "input Given items to the Model of a Specification"
155 (* (facts >> (Toplevel.proof o Proof.from_thmss_cmd));*)
156 ((writeln o Token.s_to_string, facts) @@>> (Toplevel.proof o Proof.from_thmss_cmd));
158 Outer_Syntax.command \<^command_keyword>\<open>Where\<close> "input Find items to the Model of a Specification"
159 (facts @>> (Toplevel.proof o Proof.from_thmss_cmd));
161 Outer_Syntax.command \<^command_keyword>\<open>Find\<close> "input Find items to the Model of a Specification"
162 (facts @>> (Toplevel.proof o Proof.from_thmss_cmd));
164 Outer_Syntax.command \<^command_keyword>\<open>Relate\<close> "input Relate items to the Model of a Specification"
165 (facts @>> (Toplevel.proof o Proof.from_thmss_cmd));
167 (Toplevel.proof o Proof.from_thmss_cmd)
169 (Facts.ref * Token.src list) list list -> Toplevel.transition -> Toplevel.transition
170 (* ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^*)
173 Outer_Syntax.command @{command_keyword References} "References dummy"
174 (Parse.$$$ ":" >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
176 Outer_Syntax.command @{command_keyword RTheory} "RTheory dummy"
177 (Parse.$$$ ":" -- Parse.string
178 >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
180 Outer_Syntax.command @{command_keyword RProblem} "RProblem dummy"
181 (Parse.$$$ ":" -- (Parse.$$$ "[" |-- Parse.list1 Parse.string --| Parse.$$$ "]")
182 >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
184 Outer_Syntax.command @{command_keyword RMethod} "RMethod dummy"
185 (Parse.$$$ ":" -- (Parse.$$$ "[" |-- Parse.list1 Parse.string --| Parse.$$$ "]")
186 >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
188 Outer_Syntax.command @{command_keyword Solution} "Solution dummy"
189 (Parse.$$$ ":" >> (fn _ => Toplevel.keep (fn _ => ignore (writeln ""))));
194 subsection \<open>runs with test-Example\<close>
196 Example \<open>/usr/local/isabisac/src/Tools/isac/Examples/exp_Statics_Biegel_Timischl_7-70.str\<close>
198 Problem ("Biegelinie", ["Biegelinien"])
203 Given: "Traegerlaenge " "Streckenlast " (*Bad context for command "Given"\<^here> -- using reset state*)
204 Where: "q_0 ist_integrierbar_auf {| 0, L |}" "0 < L"
206 Relate: "Randbedingungen "
209 RTheory: "" (*Bad context for command "RTheory"\<^here> -- using reset state*)
217 TODO: compare click on above Given: "Traegerlaenge ", "Streckenlast "
218 with click on from \<open>0 < d\<close> in SPARK/../Greatest_Common_Divisorthy