isac-java/src/java/isac/gui/mawen/syntax/syntax_phases.scala
author Walther Neuper <walther.neuper@jku.at>
Fri, 26 Mar 2021 10:45:05 +0100
changeset 5239 b4e3883d7b66
parent 5229 6bf0e95981e3
permissions -rw-r--r--
reset mathematics-engine to Isabelle2015

note: for this version libisabelle was available,
which connects front-end (Java) and back-end (Isabelle/ML)
     1 /*  THIS IS A PARTIAL TRANSLATION FROM Isabelle2016-1 ...
     2     Title:      Pure/Syntax/syntax_phases.ML
     3     Author:     Makarius
     4 
     5 Main phases of inner syntax processing, with standard implementations
     6 of parse/unparse operations.
     7 
     8 CODE OMITTED IN THE TRANSLATION IS INDICATED BY (**) IN ORIGINAL ML.
     9 */
    10 package isac.gui.mawen.syntax
    11 
    12 import isac.gui.mawen.syntax.isabelle.XLibrary
    13 import isac.gui.mawen.syntax.isabelle.XTerm
    14 import edu.tum.cs.isabelle.pure._
    15 
    16 object Syntax_Phases {
    17   
    18   /* translation from Isabelle2016-1 ~~/src/Pure/Syntax/syntax_phases.ML
    19      CODE OMITTED IN THE TRANSLATION IS INDICATED BY (**) IN ORIGINAL ML:
    20   (* simple_ast_of *)
    21   
    22   (* = fn: Proof.context -> term -> Ast.ast*)
    23   fun simple_ast_of (*ctxt*)_ =
    24     let
    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";
    36     in ast_of end;
    37    *
    38    * Constant GETS AN ABBREVIATED STRING PROBABLY USEFUL FOR ast_to_term
    39    */
    40   def simple_ast_of(/* ctxt : ???,*/ t : Term) : Ast.Ast = {
    41     def ast_of(tm : Term) : Ast.Ast =
    42     tm match {
    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))
    46       case App(t1, t2) => {
    47         val (f, args) = XTerm.strip_comb(App(t1, t2))
    48         Ast.mk_appl(ast_of(f), args.map(t => ast_of(t)))
    49       }
    50       case Bound(i) =>
    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")
    53     }
    54     ast_of(t)
    55   }
    56 
    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))
    60   
    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"))
    63 }