src/Pure/Syntax/syntax.ML
changeset 35111 18cd034922ba
parent 33957 e9afca2118d4
child 35130 0991c84e8dcf
equal deleted inserted replaced
35110:dc4f61a7918a 35111:18cd034922ba
    52   datatype 'a trrule =
    52   datatype 'a trrule =
    53     ParseRule of 'a * 'a |
    53     ParseRule of 'a * 'a |
    54     PrintRule of 'a * 'a |
    54     PrintRule of 'a * 'a |
    55     ParsePrintRule of 'a * 'a
    55     ParsePrintRule of 'a * 'a
    56   val map_trrule: ('a -> 'b) -> 'a trrule -> 'b trrule
    56   val map_trrule: ('a -> 'b) -> 'a trrule -> 'b trrule
       
    57   val is_const: syntax -> string -> bool
    57   val standard_unparse_term: (string -> xstring) ->
    58   val standard_unparse_term: (string -> xstring) ->
    58     Proof.context -> syntax -> bool -> term -> Pretty.T
    59     Proof.context -> syntax -> bool -> term -> Pretty.T
    59   val standard_unparse_typ: Proof.context -> syntax -> typ -> Pretty.T
    60   val standard_unparse_typ: Proof.context -> syntax -> typ -> Pretty.T
    60   val standard_unparse_sort: Proof.context -> syntax -> sort -> Pretty.T
    61   val standard_unparse_sort: Proof.context -> syntax -> sort -> Pretty.T
    61   val update_type_gram: (string * int * mixfix) list -> syntax -> syntax
    62   val update_type_gram: (string * int * mixfix) list -> syntax -> syntax
   590 fun print_rule (ParseRule _) = NONE
   591 fun print_rule (ParseRule _) = NONE
   591   | print_rule (PrintRule pats) = SOME (swap pats)
   592   | print_rule (PrintRule pats) = SOME (swap pats)
   592   | print_rule (ParsePrintRule pats) = SOME (swap pats);
   593   | print_rule (ParsePrintRule pats) = SOME (swap pats);
   593 
   594 
   594 
   595 
       
   596 fun is_const (Syntax ({consts, ...}, _)) c = member (op =) consts c;
       
   597 
   595 local
   598 local
   596 
   599 
   597 fun check_rule (rule as (lhs, rhs)) =
   600 fun check_rule (rule as (lhs, rhs)) =
   598   (case Ast.rule_error rule of
   601   (case Ast.rule_error rule of
   599     SOME msg =>
   602     SOME msg =>
   601         Ast.str_of_ast lhs ^ "  ->  " ^ Ast.str_of_ast rhs)
   604         Ast.str_of_ast lhs ^ "  ->  " ^ Ast.str_of_ast rhs)
   602   | NONE => rule);
   605   | NONE => rule);
   603 
   606 
   604 fun read_pattern ctxt is_logtype syn (root, str) =
   607 fun read_pattern ctxt is_logtype syn (root, str) =
   605   let
   608   let
   606     val Syntax ({consts, ...}, _) = syn;
       
   607 
       
   608     fun constify (ast as Ast.Constant _) = ast
   609     fun constify (ast as Ast.Constant _) = ast
   609       | constify (ast as Ast.Variable x) =
   610       | constify (ast as Ast.Variable x) =
   610           if member (op =) consts x orelse Long_Name.is_qualified x then Ast.Constant x
   611           if is_const syn x orelse Long_Name.is_qualified x then Ast.Constant x
   611           else ast
   612           else ast
   612       | constify (Ast.Appl asts) = Ast.Appl (map constify asts);
   613       | constify (Ast.Appl asts) = Ast.Appl (map constify asts);
   613 
   614 
   614     val (syms, pos) = read_token str;
   615     val (syms, pos) = read_token str;
   615   in
   616   in