src/Pure/General/symbol_pos.ML
changeset 50239 fb579401dc26
parent 50201 c26369c9eda6
child 50242 56b9c792a98b
equal deleted inserted replaced
50238:98d35a7368bd 50239:fb579401dc26
    35   type text = string
    35   type text = string
    36   val implode: T list -> text
    36   val implode: T list -> text
    37   val range: T list -> Position.range
    37   val range: T list -> Position.range
    38   val implode_range: Position.T -> Position.T -> T list -> text * Position.range
    38   val implode_range: Position.T -> Position.T -> T list -> text * Position.range
    39   val explode: text * Position.T -> T list
    39   val explode: text * Position.T -> T list
       
    40   val scan_ident: T list -> T list * T list
       
    41   val is_ident: T list -> bool
       
    42   val is_identifier: string -> bool
    40 end;
    43 end;
    41 
    44 
    42 structure Symbol_Pos: SYMBOL_POS =
    45 structure Symbol_Pos: SYMBOL_POS =
    43 struct
    46 struct
    44 
    47 
   206     val (res, _) =
   209     val (res, _) =
   207       fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p))
   210       fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p))
   208         (Symbol.explode str) ([], Position.reset_range pos);
   211         (Symbol.explode str) ([], Position.reset_range pos);
   209   in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end;
   212   in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end;
   210 
   213 
       
   214 
       
   215 (* identifiers *)
       
   216 
       
   217 val scan_ident =
       
   218   Scan.one (Symbol.is_letter o symbol) ::: Scan.many (Symbol.is_letdig o symbol);
       
   219 
       
   220 fun is_ident [] = false
       
   221   | is_ident (s :: ss) = Symbol.is_letter (symbol s) andalso forall (Symbol.is_letdig o symbol) ss;
       
   222 
       
   223 fun is_identifier s =
       
   224   Symbol.is_ascii_identifier s orelse is_ident (explode (s, Position.none));
       
   225 
   211 end;
   226 end;
   212 
   227 
   213 structure Basic_Symbol_Pos =   (*not open by default*)
   228 structure Basic_Symbol_Pos =   (*not open by default*)
   214 struct
   229 struct
   215   val $$$ = Symbol_Pos.$$$;
   230   val $$$ = Symbol_Pos.$$$;