Skip to content

Instantly share code, notes, and snippets.

@michiakig
Created September 18, 2013 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michiakig/6610073 to your computer and use it in GitHub Desktop.
Save michiakig/6610073 to your computer and use it in GitHub Desktop.
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