1 /* THIS IS A DUMMY IMPLEMENTATION OF Isabelle2016-1 ...
2 TTitle: Pure/Syntax/syntax.ML
3 Author: Tobias Nipkow and Markus Wenzel, TU Muenchen
5 Standard Isabelle syntax, based on arbitrary context-free grammars
6 (specified by mixfix declarations).
8 package isac.gui.mawen.syntax
10 import isac.gui.mawen.syntax.isabelle.XLibrary
11 import isac.gui.mawen.syntax.isabelle.XTerm
12 import isac.gui.mawen.syntax.Ast._ //"._" simplifies "Ast.Ast" to "Ast"
14 import edu.tum.cs.isabelle.pure._
16 import scala.collection.immutable.TreeMap
20 /* Data for presentation of Const which are not contained in (Scala-) Term:
21 * _0: string used in ASTs
22 * _1: string as shown by Isabelle's pretty printing
23 * _2: infixl | infixr | prefix | postfix
24 * _3: priority, which determines parentheses to be set
26 * This replaces structure Syntax in Pure/Syntax/syntax.ML etc:
27 * val lookup_const: syntax -> string -> string option
28 * fun lookup_const (Syntax ({consts, ...}, _)) = Symtab.lookup consts;
31 "HOL.eq" -> ("=", " = ", "infixl", 50), //see ~~/src/HOL/HOL.thy
32 "Groups.plus_class.plus" -> ("+", " + ", "infixl", 65), //see ~~/src/HOL/Groups.thy
33 "Groups.minus_class.minus" -> ("-", " - ", "infixl", 65), //see ~~/src/HOL/Groups.thy
34 "Groups.plus_class.uminus" -> ("-", " -", "prefix", 80), //see ~~/src/HOL/Groups.thy
35 "Groups.times_class.times" -> ("*", " * ", "infixl", 70), //see ~~/src/HOL/Groups.thy
36 "Fields.inverse_class.divide" -> ("/", " / ", "infixl", 70), //see ~~/src/HOL/Fields.thy
37 "Atools.pow" -> ("^", " ^ ", "infixr", 80), //see ~~/src/Tools/isac/Knowledge/Atools.thy
38 "Power.power_class.power" -> ("^", " ^ ", "infixr", 80), //see ~~/src/HOL/Power.thy
39 "Transcendental.sin" -> ("sin", "sin ", "prefix", 70), //see ~~/src/HOL/Transcendental.thy
40 "Transcendental.cos" -> ("cos", "cos ", "prefix", 70), //see ~~/src/HOL/Transcendental.thy
41 "Integrate.Integral" -> ("Integral", "Integral ", "prefix", 91) //see ~~/src/Tools/isac/Knowledge/Integrate.thy
42 //...ERROR: implicit conversion found: ...
44 /* an exact copy of isa_const with another key:
45 * _0: string used in Isabelle Term
48 "=" -> ("HOL.eq", " = ", "infixl", 50, "CMCSC8", '='.toInt), //see ~~/src/HOL/HOL.thy
49 "+" -> ("Groups.plus_class.plus", " + ", "infixl", 65, "CMCSC8", '+'.toInt), //see ~~/src/HOL/Groups.thy
50 "-" -> ("Groups.minus_class.minus", " - ", "infixl", 65, "CMCSC8", '-'.toInt), //see ~~/src/HOL/Groups.thy
51 "-" -> ("Groups.plus_class.uminus", " -", "prefix", 80, "CMCSC8", '-'.toInt), //see ~~/src/HOL/Groups.thy
52 "*" -> ("Groups.times_class.times", " * ", "infixl", 70, "CMCSC8", '*'.toInt), //see ~~/src/HOL/Groups.thy
53 "/" -> ("Fields.inverse_class.divide", " / ", "infixl", 70, "", 0), //see ~~/src/HOL/Fields.thy
54 "^" -> ("Atools.pow", " ^ ", "infixr", 80, "", 0), //see ~~/src/Tools/isac/Knowledge/Atools.thy
55 "^" -> ("Power.power_class.power", " ", "infixr", 80, "", 0), //see ~~/src/HOL/Power.thy
56 "sin" -> ("Transcendental.sin", "sin ", "prefix", 70, "", 0), //see ~~/src/HOL/Transcendental.thy
57 "cos" -> ("Transcendental.cos", "cos ", "prefix", 70, "", 0), //see ~~/src/HOL/Transcendental.thy
58 "Integral" -> ("Integrate.Integral", "Integral ", "prefix", 91, "", 0) //see ~~/src/Tools/isac/Knowledge/Integrate.thy
59 //...ERROR: implicit conversion found: ...
61 /* so not every constant needs to be in Util.isa_const */
62 def isa_ast(str: String): String = { //key is the String in Term.Const
63 isa_const.get(str) match {
64 case Some((ast, _, _, _)) => ast
65 case None => str.substring(str.lastIndexOf(".") + 1)}}
66 def ast_isa(str: String): String = { //key is the String in Ast.Constant
67 ast_const.get(str) match {
68 case Some((ast, _, _, _, _, _)) => ast
69 case None => str.substring(str.lastIndexOf(".") + 1)}}
71 def isa_math(str: String): String = { //key is the String in Term.Const
72 isa_const.get(str) match {
73 case Some((_, isa, _, _)) => isa
74 case None => str.substring(str.lastIndexOf(".") + 1) + " "}}
75 def ast_math(str: String): String = { //key is the String in Ast.Constant
76 ast_const.get(str) match {
77 case Some((_, isa, _, _, _, _)) => isa
78 case None => str.substring(str.lastIndexOf(".") + 1) + " "}}
80 def isa_fix(str: String): String = { //key is the String in Term.Const
81 isa_const.get(str) match {
82 case Some((_, _, fix, _)) => fix
83 case None => "prefix"}}
84 def ast_fix(str: String): String = { //key is the String in Ast.Constant
85 ast_const.get(str) match {
86 case Some((_, _, fix, _, _, _)) => fix
87 case None => "prefix"}}
89 def isa_prior(str: String): Int = { //key is the String in Term.Const
90 isa_const.get(str) match {
91 case Some((_, _, _, prior)) => prior
93 def ast_prior(str: String): Int = { //key is the String in Ast.Constant
94 ast_const.get(str) match {
95 case Some((_, _, _, prior, _, _)) => prior
98 /* ~~/src/Pure/Syntax/syntax.ML:
99 * val print_rules: syntax -> string -> (Ast.ast * Ast.ast) list
100 * fun print_rules (Syntax ({print_ruletab, ...}, _)) = Symtab.lookup_list print_ruletab;
102 var symtab = TreeMap(
103 "List.list.Cons" -> List(
104 //ML try_rules lhs: Appl(List(Constant("\<^const>List.list.Cons"), Variable("x"), Constant("\<^const>List.list.Nil")))
105 //ML try_rules rhs: Appl(List(Constant("_list"), Variable("x")))
106 //rule for the last element
108 Constant("List.list.Cons"),
110 Constant("List.list.Nil"))),
114 //ML try_rules lhs: Appl(List(Constant("\<^const>List.list.Cons"), Variable("x"), Appl(List(Constant("_list"), Variable("xs")))))
115 //ML try_rules rhs: Appl(List(Constant("_list"), Appl(List(Constant("_args"), Variable("x"), Variable("xs")))))
116 //rule for earlier elements: rewriting begins at the last element
118 Constant("List.list.Cons"),
125 Appl(List(Constant("_args"),
127 Variable("xs"))))))),
128 "Product_Type.Pair" -> List(
129 //ML try_rules lhs: Appl(List(Constant("\<^const>Product_Type.Pair"), Variable("x"), Variable("y")))
130 //ML try_rules rhs: Appl(List(Constant("_tuple"), Variable("x"), Appl(List(Constant("_tuple_arg"), Variable("y")))))
131 //rule for the last element
132 (Appl(List(Constant("Product_Type.Pair"), Variable("x"), Variable("y"))),
133 Appl(List(Constant("_tuple"), Variable("x"), Appl(List(Constant("_tuple_arg"), Variable("y"))))) )
135 "" -> List( //called by Ast.try_headless_rules
136 //ML try_rules lhs: Appl(List(Constant("_tuple"), Variable("x"), Appl(List(Constant("_tuple_arg"), Appl(List(Constant("_tuple"), Variable("y"), Variable("z")))))))
137 //ML try_rules rhs: Appl(List(Constant("_tuple"), Variable("x"), Appl(List(Constant("_tuple_args"), Variable("y"), Variable("z")))))
138 (Appl(List(Constant("_tuple"), Variable("x"), Appl(List(Constant("_tuple_arg"), Appl(List(Constant("_tuple"), Variable("y"), Variable("z"))))))),
139 Appl(List(Constant("_tuple"), Variable("x"), Appl(List(Constant("_tuple_args"), Variable("y"), Variable("z"))))) ) )
142 def print_rules (key: String): List[Tuple2[Ast, Ast]] =
143 if (symtab.contains(key)) symtab(key) else List()