summaryrefslogtreecommitdiff
path: root/stream.sml
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-04-04 18:24:46 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-04-04 18:24:46 +0200
commit7b29b31648fd737e7bbc007f480b799add91bc6b (patch)
treee724c15c959d98ece73c186b82a61100f4e8d06a /stream.sml
parentd7d4830443f1e385af862462f976553c8a9033e1 (diff)
Beginning of the preprocessor
Diffstat (limited to 'stream.sml')
-rw-r--r--stream.sml20
1 files changed, 13 insertions, 7 deletions
diff --git a/stream.sml b/stream.sml
index 1755817..bc9048b 100644
--- a/stream.sml
+++ b/stream.sml
@@ -6,6 +6,7 @@ structure Stream :> STREAM = struct
type fileInfo = fileId * string * string
exception UngetcError
+ exception InvalidFileInfo
fun ppos2str (pos, line, col) =
let
@@ -56,12 +57,17 @@ structure Stream :> STREAM = struct
fun getPosAfterCharRead (fid, _, off, _) = (fid, off - 1)
- fun pos2ppos (_, pos) (_, fname, _, contents) =
- let
- val (line, col) = calcFilePos contents pos
- in
- (fname, line, SOME col)
- end
+ fun pos2pposWithFI (id, pos) (id', fname, contents) =
+ if id <> id' then
+ raise InvalidFileInfo
+ else
+ let
+ val (line, col) = calcFilePos contents pos
+ in
+ (fname, line, SOME col)
+ end
+
+ fun pos2ppos pos stream = pos2pposWithFI pos (convert stream)
fun pposWithoutCol (fname, line, SOME _) = (fname, line, NONE)
| pposWithoutCol (_, _, NONE) = raise Unreachable
@@ -71,7 +77,7 @@ structure Stream :> STREAM = struct
fun getSubstr startOff endOff (_, _, _, contents) =
String.substring (contents, startOff, endOff - startOff)
- fun streamInit fname =
+ fun create fname =
let
open TextIO