diff options
author | Vladimir Azarov <avm@intermediate-node.net> | 2025-05-26 21:06:51 +0200 |
---|---|---|
committer | Vladimir Azarov <avm@intermediate-node.net> | 2025-05-26 21:06:51 +0200 |
commit | 3a32398248e5593b1b536c837478cab276f7aebf (patch) | |
tree | 55ff4004a06278c84908668c26d39d0fc3098a08 /stream.sml | |
parent | 6f3fa80b37ca5f8d992f5d6f66aee77ead303bf4 (diff) |
Simpler tokenizer
Diffstat (limited to 'stream.sml')
-rw-r--r-- | stream.sml | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -37,8 +37,8 @@ structure Stream :> STREAM = struct end z fun getchar (S as { contents, off, ... }: t) = - (SOME $ String.sub (contents, off), updateStream S s#off (off + 1) %) - handle Subscript => (NONE, S) + (String.sub (contents, off), updateStream S s#off (off + 1) %) + handle Subscript => (chr 0, S) fun ungetc ({ off = 0, ... }: t) = raise UngetcError @@ -100,7 +100,7 @@ structure Stream :> STREAM = struct (line, col) else calcPos (curOff + 1) - (if String.sub (contents,curOff) = #"\n" then (line + 1, 1) + (if String.sub (contents, curOff) = #"\n" then (line + 1, 1) else (line, col + 1)) val (line, col) = calcPos prevOff (line, col) in @@ -111,6 +111,8 @@ structure Stream :> STREAM = struct fun getPos (S as { off, ... }: t) = getPosRaw off S + fun getPosDisc s = #1 $ getPos s + fun EOFpos (S as { contents, ... }: t) = getPosRaw (String.size contents) S |