1 (* Copyright (C
) 2011,2015 Matthew Fluet
.
2 * Copyright (C
) 1999-2006, 2008 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 structure Source
: SOURCE
=
13 datatype t
= T
of {file
: File
.t ref
,
18 fun getPos (T
{file
, lineNum
, lineStart
, ...}, n
) =
19 SourcePos
.make
{column
= n
- !lineStart
,
23 fun lineStart (s
as T
{lineStart
, ...}) = getPos (s
, !lineStart
)
25 fun lineDirective (T
{file
, lineNum
, lineStart
, origDir
},
27 {lineNum
= n
, lineStart
= s
}) =
28 (Option
.app (f
, fn f
=>
31 if OS
.Path
.isAbsolute f
33 else OS
.Path
.mkCanonical (OS
.Path
.concat (origDir
, f
))
40 fun new file
= T
{file
= ref file
,
42 (* mllex file positions start at zero
, while we report errors
43 * starting
in column
1, so we need to pretend the first line
44 * starts at position ~
1, which will translate position
0 to
48 origDir
= File
.dirOf file
}
50 fun newline (T
{lineStart
, lineNum
, ...}, n
) =
54 fun name (T
{file
, ...}) = !file