1 (* Copyright (C) 2017 Matthew Fluet.
2 * Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 functor Longid (S: LONGID_STRUCTS): LONGID =
15 datatype node = T of {strids: Strid.t list,
19 structure Wrap = Region.Wrap
26 val T {strids, id, ...} = node id
34 val T {strids=ss, id=i} = node id
35 val T {strids=ss', id=i'} = node id'
37 List.equals (ss, ss', Strid.equals) andalso Id.equals (i, i')
40 fun long (strids, id) =
41 makeRegion (T {strids = strids, id = id},
44 | s :: _ => Region.append (Strid.region s, Id.region id))
46 fun short id = long ([], id)
50 val T {strids, id} = node id
55 | _ => seq [seq (separate (List.map (strids, Strid.layout), ".")),
60 val toString = Layout.toString o layout
62 fun fromSymbols (ss: Symbol.t list, region: Region.t): t =
65 case Region.left region of
66 NONE => List.map (ss, fn s => (s, region))
69 val file = SourcePos.file p
70 val line = SourcePos.line p
73 ((ss, SourcePos.column p),
76 val cr = cl + String.length (Symbol.toString s) - 1
80 {left = SourcePos.make {column = cl,
83 right = SourcePos.make {column = cr,
90 val (strids, id) = List.splitLast srs
92 makeRegion (T {strids = List.map (strids, Strid.fromSymbol),
93 id = Id.fromSymbol id},