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