1 /* THIS IS A PARTIAL TRANSLATION FROM Isabelle2016-1 ...
2 Title: Pure/Syntax/syntax_phases.ML
5 Main phases of inner syntax processing, with standard implementations
6 of parse/unparse operations.
8 CODE OMITTED IN THE TRANSLATION IS INDICATED BY (**) IN ORIGINAL ML.
10 package isac.gui.mawen.syntax
12 import isac.gui.mawen.syntax.isabelle.XLibrary
13 import isac.gui.mawen.syntax.isabelle.XTerm
14 import edu.tum.cs.isabelle.pure._
16 object Syntax_Phases {
18 /* translation from Isabelle2016-1 ~~/src/Pure/Syntax/syntax_phases.ML
19 CODE OMITTED IN THE TRANSLATION IS INDICATED BY (**) IN ORIGINAL ML:
22 (* = fn: Proof.context -> term -> Ast.ast*)
23 fun simple_ast_of (*ctxt*)_ =
25 (* = fn: string -> string*)
26 (*val tune_var = if Config.get ctxt show_question_marks then I else unprefix "?";*)
27 (* = fn: term -> Ast.ast*)
28 fun ast_of (Const (c, _)) = Ast.Constant c
29 | ast_of (Free (x, _)) = Ast.Variable x
30 | ast_of (Var (xi, _)) = Ast.Variable ((*tune_var*) (Term.string_of_vname xi))
31 | ast_of (t as _ $ _) =
32 let val (f, args) = strip_comb t
33 in Ast.mk_appl (ast_of f) (map ast_of args) end
34 | ast_of (Bound i) = Ast.Appl [Ast.Constant "_loose", Ast.Variable ("B." ^ string_of_int i)]
35 | ast_of (Abs _) = raise Fail "simple_ast_of: Abs";
38 * Constant GETS AN ABBREVIATED STRING PROBABLY USEFUL FOR ast_to_term
40 def simple_ast_of(/* ctxt : ???,*/ t : Term) : Ast.Ast = {
41 def ast_of(tm : Term) : Ast.Ast =
43 case Const(c, _) => Ast.Constant(c)
44 case Free(c, _) => Ast.Variable(c)
45 case Var(xi, _) => Ast.Variable(XTerm.string_of_vname(xi))
47 val (f, args) = XTerm.strip_comb(App(t1, t2))
48 Ast.mk_appl(ast_of(f), args.map(t => ast_of(t)))
51 Ast.Appl(List(Ast.Constant("_loose"), Ast.Variable("B." ++ XLibrary.string_of_int(i.intValue))))
52 case Abs(_, _, _) => throw new AstException("simple_ast_of: Abs")
57 // still NO ast-translations, compare ~~/src/Pure/Syntax/syntax_phases.ML
58 def term_to_ast(tm : Term) : Ast.Ast =
59 Ast.normalize(XSyntax.print_rules, simple_ast_of(tm))
61 // we do NOT submit Term to Isabelle_Isac, only String (and let parse again)
62 def ast_to_term(ast: Ast.Ast) : Term = Const("DUMMY", Type("DUMMY"))