src/Pure/Isar/outer_lex.ML
changeset 14991 26fb63c4acb5
parent 14981 e73f8140af78
child 15143 05b5995f214e
equal deleted inserted replaced
14990:582b655da757 14991:26fb63c4acb5
    24   val is_semicolon: token -> bool
    24   val is_semicolon: token -> bool
    25   val is_begin_ignore: token -> bool
    25   val is_begin_ignore: token -> bool
    26   val is_end_ignore: token -> bool
    26   val is_end_ignore: token -> bool
    27   val is_newline: token -> bool
    27   val is_newline: token -> bool
    28   val is_indent: token -> bool
    28   val is_indent: token -> bool
       
    29   val unparse: token -> string
    29   val val_of: token -> string
    30   val val_of: token -> string
    30   val is_sid: string -> bool
    31   val is_sid: string -> bool
    31   val !!! : string -> (Position.T * 'a -> 'b) -> Position.T * 'a -> 'b
    32   val !!! : string -> (Position.T * 'a -> 'b) -> Position.T * 'a -> 'b
    32   val incr_line: ('a -> 'b * 'c) -> Position.T * 'a -> 'b * (Position.T * 'c)
    33   val incr_line: ('a -> 'b * 'c) -> Position.T * 'a -> 'b * (Position.T * 'c)
    33   val keep_line: ('a -> 'b * 'c) -> Position.T * 'a -> 'b * (Position.T * 'c)
    34   val keep_line: ('a -> 'b * 'c) -> Position.T * 'a -> 'b * (Position.T * 'c)
   130 fun is_indent (Token (_, (Space, s))) =
   131 fun is_indent (Token (_, (Space, s))) =
   131       let val n = size s in n > 0 andalso String.substring (s, n - 1, 1) <> "\n" end
   132       let val n = size s in n > 0 andalso String.substring (s, n - 1, 1) <> "\n" end
   132   | is_indent _ = false;
   133   | is_indent _ = false;
   133 
   134 
   134 
   135 
   135 (* name and value of token *)
   136 (* token content *)
   136 
   137 
   137 fun name_of (tok as Token (_, (k, x))) =
   138 fun name_of (tok as Token (_, (k, x))) =
   138   if is_semicolon tok then "terminator"
   139   if is_semicolon tok then "terminator"
   139   else if x = "" then str_of_kind k
   140   else if x = "" then str_of_kind k
   140   else str_of_kind k ^ " " ^ quote x;
   141   else str_of_kind k ^ " " ^ quote x;
       
   142 
       
   143 fun unparse (Token (_, (kind, x))) =
       
   144   (case kind of
       
   145     String => x |> translate_string (fn "\"" => "\\\"" | "\\" => "\\\\" | c => c) |> quote
       
   146   | Verbatim => x |> enclose "{*" "*}"
       
   147   | Comment => x |> enclose "(*" "*)"
       
   148   | _ => x);
   141 
   149 
   142 fun val_of (Token (_, (_, x))) = x;
   150 fun val_of (Token (_, (_, x))) = x;
   143 
   151 
   144 fun token_leq (Token (_, (_, x)), Token (_, (_, x'))) = x <= x';
   152 fun token_leq (Token (_, (_, x)), Token (_, (_, x'))) = x <= x';
   145 
   153