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