diff options
Diffstat (limited to 'stream.sml')
-rw-r--r-- | stream.sml | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -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 |