From 88378509521b46e615986f8c82d10b9da88830d2 Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Mon, 19 May 2025 00:22:16 +0200 Subject: Better debug info --- stream.sml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'stream.sml') 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 -- cgit v1.2.3