summaryrefslogtreecommitdiff
path: root/stream.sml
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2025-05-19 00:22:16 +0200
committerVladimir Azarov <avm@intermediate-node.net>2025-05-19 00:22:16 +0200
commit88378509521b46e615986f8c82d10b9da88830d2 (patch)
tree0480d743fba058f394fe314508a17865853ffdd4 /stream.sml
parentbe407d29db4f2ac1018ab6841c7111f95b977948 (diff)
Better debug info
Diffstat (limited to 'stream.sml')
-rw-r--r--stream.sml24
1 files changed, 16 insertions, 8 deletions
diff --git a/stream.sml b/stream.sml
index 4ea7f08..3e18f2e 100644
--- a/stream.sml
+++ b/stream.sml
@@ -36,14 +36,9 @@ structure Stream :> STREAM = struct
bind A1 p
end z
- fun getcharSure (S as { contents, off, ... }: t) =
- (String.sub (contents, off), updateStream S s#off (off + 1) %)
-
- fun getchar stream =
- (fn (c, s) => (SOME c, s)) $ getcharSure stream handle
- Subscript => (NONE, stream)
-
- fun getcharEx stream = getcharSure stream handle Subscript => raise EOF
+ fun getchar (S as { contents, off, ... }: t) =
+ (SOME $ String.sub (contents, off), updateStream S s#off (off + 1) %)
+ handle Subscript => (NONE, S)
fun ungetc ({ off = 0, ... }: t) =
raise UngetcError
@@ -84,6 +79,19 @@ structure Stream :> STREAM = struct
fun getOffset ({ off, ... }: t) = off
+ fun isFirstOnLine ({ contents, ... }: t) off =
+ let
+ fun check (~1) = true
+ | check off =
+ case String.sub (contents, off) of
+ #"\n" => true
+ | #" " => check (off - 1)
+ | #"\t" => check (off - 1)
+ | _ => false
+ in
+ check (off - 1)
+ end
+
fun getPosRaw off (S as { cache = (prevOff, line, col), fname,
contents, ... }: t) =
let