src/Pure/Isar/token.ML
changeset 55708 f4b114070675
parent 55111 5792f5106c40
child 55709 4e5a83a46ded
equal deleted inserted replaced
55706:064c7c249f55 55708:f4b114070675
    14   datatype value =
    14   datatype value =
    15     Text of string | Typ of typ | Term of term | Fact of thm list |
    15     Text of string | Typ of typ | Term of term | Fact of thm list |
    16     Attribute of morphism -> attribute | Files of file Exn.result list
    16     Attribute of morphism -> attribute | Files of file Exn.result list
    17   type T
    17   type T
    18   val str_of_kind: kind -> string
    18   val str_of_kind: kind -> string
    19   val position_of: T -> Position.T
    19   val pos_of: T -> Position.T
    20   val end_position_of: T -> Position.T
       
    21   val position_range_of: T list -> Position.range
    20   val position_range_of: T list -> Position.range
    22   val pos_of: T -> string
       
    23   val eof: T
    21   val eof: T
    24   val is_eof: T -> bool
    22   val is_eof: T -> bool
    25   val not_eof: T -> bool
    23   val not_eof: T -> bool
    26   val not_sync: T -> bool
    24   val not_sync: T -> bool
    27   val stopper: T Scan.stopper
    25   val stopper: T Scan.stopper
   128   | EOF => "end-of-input";
   126   | EOF => "end-of-input";
   129 
   127 
   130 
   128 
   131 (* position *)
   129 (* position *)
   132 
   130 
   133 fun position_of (Token ((_, (pos, _)), _, _)) = pos;
   131 fun pos_of (Token ((_, (pos, _)), _, _)) = pos;
   134 fun end_position_of (Token ((_, (_, pos)), _, _)) = pos;
   132 fun end_pos_of (Token ((_, (_, pos)), _, _)) = pos;
   135 
   133 
   136 fun position_range_of [] = Position.no_range
   134 fun position_range_of [] = Position.no_range
   137   | position_range_of toks = (position_of (hd toks), end_position_of (List.last toks));
   135   | position_range_of toks = (pos_of (hd toks), end_pos_of (List.last toks));
   138 
       
   139 val pos_of = Position.here o position_of;
       
   140 
   136 
   141 
   137 
   142 (* control tokens *)
   138 (* control tokens *)
   143 
   139 
   144 fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
   140 fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
   151 
   147 
   152 fun not_sync (Token (_, (Sync, _), _)) = false
   148 fun not_sync (Token (_, (Sync, _), _)) = false
   153   | not_sync _ = true;
   149   | not_sync _ = true;
   154 
   150 
   155 val stopper =
   151 val stopper =
   156   Scan.stopper (fn [] => eof | toks => mk_eof (end_position_of (List.last toks))) is_eof;
   152   Scan.stopper (fn [] => eof | toks => mk_eof (end_pos_of (List.last toks))) is_eof;
   157 
   153 
   158 
   154 
   159 (* kind of token *)
   155 (* kind of token *)
   160 
   156 
   161 fun kind_of (Token (_, (k, _), _)) = k;
   157 fun kind_of (Token (_, (k, _), _)) = k;
   249 fun get_files (Token (_, _, Value (SOME (Files files)))) = files
   245 fun get_files (Token (_, _, Value (SOME (Files files)))) = files
   250   | get_files _ = [];
   246   | get_files _ = [];
   251 
   247 
   252 fun put_files [] tok = tok
   248 fun put_files [] tok = tok
   253   | put_files files (Token (x, y, Slot)) = Token (x, y, Value (SOME (Files files)))
   249   | put_files files (Token (x, y, Slot)) = Token (x, y, Value (SOME (Files files)))
   254   | put_files _ tok =
   250   | put_files _ tok = raise Fail ("Cannot put inlined files here" ^ Position.here (pos_of tok));
   255       raise Fail ("Cannot put inlined files here" ^ Position.here (position_of tok));
       
   256 
   251 
   257 
   252 
   258 (* access values *)
   253 (* access values *)
   259 
   254 
   260 fun get_value (Token (_, _, Value v)) = v
   255 fun get_value (Token (_, _, Value v)) = v