src/Pure/General/symbol_pos.ML
changeset 55829 b7bdea5336dd
parent 55828 42ac3cfb89f6
child 58047 9f3826352b52
equal deleted inserted replaced
55828:42ac3cfb89f6 55829:b7bdea5336dd
    35   val scan_comment_body: string -> T list -> T list * T list
    35   val scan_comment_body: string -> T list -> T list * T list
    36   val recover_comment: T list -> T list * T list
    36   val recover_comment: T list -> T list * T list
    37   val source: Position.T -> (Symbol.symbol, 'a) Source.source ->
    37   val source: Position.T -> (Symbol.symbol, 'a) Source.source ->
    38     (T, Position.T * (Symbol.symbol, 'a) Source.source) Source.source
    38     (T, Position.T * (Symbol.symbol, 'a) Source.source) Source.source
    39   type text = string
    39   type text = string
    40   type source = {delimited: bool, text: text, pos: Position.T}
       
    41   val implode: T list -> text
    40   val implode: T list -> text
    42   val implode_range: Position.T -> Position.T -> T list -> text * Position.range
    41   val implode_range: Position.T -> Position.T -> T list -> text * Position.range
    43   val explode: text * Position.T -> T list
    42   val explode: text * Position.T -> T list
       
    43   type source = {delimited: bool, text: text, pos: Position.T}
       
    44   val source_content: source -> string * Position.T
    44   val scan_ident: T list -> T list * T list
    45   val scan_ident: T list -> T list * T list
    45   val is_identifier: string -> bool
    46   val is_identifier: string -> bool
    46 end;
    47 end;
    47 
    48 
    48 structure Symbol_Pos: SYMBOL_POS =
    49 structure Symbol_Pos: SYMBOL_POS =
   231 
   232 
   232 
   233 
   233 (* compact representation -- with Symbol.DEL padding *)
   234 (* compact representation -- with Symbol.DEL padding *)
   234 
   235 
   235 type text = string;
   236 type text = string;
   236 type source = {delimited: bool, text: text, pos: Position.T}
       
   237 
   237 
   238 fun pad [] = []
   238 fun pad [] = []
   239   | pad [(s, _)] = [s]
   239   | pad [(s, _)] = [s]
   240   | pad ((s1, pos1) :: (rest as (_, pos2) :: _)) =
   240   | pad ((s1, pos1) :: (rest as (_, pos2) :: _)) =
   241       let
   241       let
   255       fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p))
   255       fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p))
   256         (Symbol.explode str) ([], Position.reset_range pos);
   256         (Symbol.explode str) ([], Position.reset_range pos);
   257   in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end;
   257   in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end;
   258 
   258 
   259 
   259 
       
   260 (* full source information *)
       
   261 
       
   262 type source = {delimited: bool, text: text, pos: Position.T};
       
   263 
       
   264 fun source_content {delimited = _, text, pos} =
       
   265   let val syms = explode (text, pos) in (content syms, pos) end;
       
   266 
       
   267 
   260 (* identifiers *)
   268 (* identifiers *)
   261 
   269 
   262 local
   270 local
   263 
   271 
   264 val letter = Scan.one (symbol #> Symbol.is_letter);
   272 val letter = Scan.one (symbol #> Symbol.is_letter);