Created
September 18, 2013 14:34
-
-
Save michiakig/6610073 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signature POSITIONAL_STREAM = | |
sig | |
type elem | |
type stream | |
val peek : stream -> (elem * stream) option | |
val getPos : stream -> pos | |
end | |
structure SubstringStream : STREAM = | |
struct | |
type elem = char | |
type stream = substring | |
val peek = Substring.getc | |
end | |
structure PositionalSubstringStream : POSITIONAL_STREAM = | |
struct | |
type elem = char | |
type stream = substring * pos | |
fun peek (s, p) = | |
case Substring.getc s of | |
NONE => NONE | |
| SOME (#"\n", s') => SOME (#"\n", (s', incrLine p)) | |
| SOME (x, s') => SOME (x, (s', incrCol p)) | |
fun getPos (_, p) = p | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment