fun initialize {lines} = let val lastLine = ref (~1,"","","")
val chars = let fun saveLast line = let valref (n,_,l2,l3) = lastLine val () = lastLine := (n + 1, l2, l3, line) in String.explode line end in
Stream.memoize (Stream.map saveLast lines) end
fun parseErrorLocation () = let valref (n,l1,l2,l3) = lastLine in
(if n <= 0 then"at start" else"around line " ^ Int.toString n) ^
chomp (":\n" ^ l1 ^ l2 ^ l3) end in
{chars = chars,
parseErrorLocation = parseErrorLocation} end;
fun exactChar (c : char) = some (equal c) >> K ();
fun exactCharList cs = case cs of
[] => nothing
| c :: cs => (exactChar c ++ exactCharList cs) >> snd;
fun exactString s = exactCharList (String.explode s);
fun escapeString {escape} = let fun isEscape c = mem c escape
fun isNormal c = case c of
#"\\" => false
| #"\n" => false
| #"\t" => false
| _ => not (isEscape c)
val escapeParser =
(exactChar #"\\" >> K #"\\") ||
(exactChar #"n" >> K #"\n") ||
(exactChar #"t" >> K #"\t") ||
some isEscape
val charParser =
((exactChar #"\\" ++ escapeParser) >> snd) ||
some isNormal in
many charParser >> String.implode end;
local val isSpace = Char.isSpace;
val space = some isSpace; in val manySpace = many space >> K ();
val atLeastOneSpace = atLeastOne space >> K (); end;
fun fromString parser s = fromList parser (String.explode s);
fun parseLayeredInfixes {tokens,assoc} mk tokParser subParser = let fun layerTokParser inp = let val tok_rest as (tok,_) = tokParser inp in if StringSet.member tok tokens then tok_rest elseraise NoParse end
fun layerMk (x,txs) = case assoc of Print.LeftAssoc => let fun inc ((t,y),z) = mk (t,z,y) in List.foldl inc x txs end
| Print.NonAssoc =>
(case txs of
[] => x
| [(t,y)] => mk (t,x,y)
| _ => raise NoParse)
| Print.RightAssoc =>
(caseList.rev txs of
[] => x
| tx :: txs => let fun inc ((t,y),(u,z)) = (t, mk (u,y,z))
val (t,y) = List.foldl inc tx txs in
mk (t,x,y) end)
val layerParser = subParser ++ many (layerTokParser ++ subParser) in
layerParser >> layerMk end;
fun parseInfixes ops = let val layeredOps = Print.layerInfixes ops
val iparsers = List.map parseLayeredInfixes layeredOps in
fn mk => fn tokParser => fn subParser => List.foldr (fn (p,sp) => p mk tokParser sp) subParser iparsers end;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.