/*---------------------------------------------------------------------------
  Copyright 2020-2021, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

/* Parser combinators
*/
module std/text/parsestd/text/parse

import std/core/undivstd/core/undiv

pub alias parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> = () -> <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V

pubstd/text/parse/parse: (E, V) -> V effect parsestd/text/parse/parse: (E, V) -> V
  fun satisfy( predpred: (sslice) -> maybe<($611, sslice)> : sslicestd/core/sslice/sslice: V -> totalstd/core/types/total: E maybestd/core/types/maybe: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,sslicestd/core/sslice/sslice: V)> ) : maybestd/core/types/maybe: V -> V<aa: V>
  ctl fail(msgmsg: string : stringstd/core/types/string: V) : aa: V
  ctl pick() : boolstd/core/types/bool: V
  fun current-input() : sslicestd/core/sslice/sslice: V

pub fun starts-withstd/text/parse/starts-with: forall<a> (s : string, p : () -> parse a) -> maybe<(a, sslice)>( ss: string : stringstd/core/types/string: V, pp: () -> parse $1683 : () -> parsestd/text/parse/parse: (E, V) -> V aa: V )result: -> total maybe<(1730, sslice)>  : maybestd/core/types/maybe: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,sslicestd/core/sslice/sslice: V)>
  match ss: string.slicestd/core/sslice/slice: (s : string) -> sslice.parsestd/text/parse/parse: (input0 : sslice, p : () -> parse $1683) -> parse-error<$1683>(pp: () -> parse $1683)
    ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(xx: $1683,restrest: sslice) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xx: $1683,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b))
    _               -> Nothingstd/core/types/Nothing: forall<a> maybe<a>


pub type parse-errorstd/text/parse/parse-error: V -> V<aa: V>
  ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>( result: aa: V, reststd/text/parse/parse-error/rest: forall<a> (parse-error<a>) -> sslice : sslicestd/core/sslice/sslice: V )
  ParseErrorstd/text/parse/ParseError: forall<a> (msg : string, rest : sslice) -> parse-error<a>( msg : stringstd/core/types/string: V, rest : sslicestd/core/sslice/sslice: V )

pub fun maybestd/text/parse/maybe: forall<a> (perr : parse-error<a>) -> maybe<a>( perrperr: parse-error<$946> : parse-errorstd/text/parse/parse-error: V -> V<aa: V> )result: -> total maybe<984> : maybestd/core/types/maybe: V -> V<aa: V>
  perrperr: parse-error<$946>.eitherstd/text/parse/either: (perr : parse-error<$946>) -> either<string,$946>.maybestd/core/either/maybe: (e : either<string,$946>) -> maybe<$946>

pub fun eitherstd/text/parse/either: forall<a> (perr : parse-error<a>) -> either<string,a>( perrperr: parse-error<$904> : parse-errorstd/text/parse/parse-error: V -> V<aa: V> )result: -> total either<string,941> : eitherstd/core/types/either: (V, V) -> V<stringstd/core/types/string: V,aa: V>
  match perrperr: parse-error<$904>
    ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(xx: $904,_) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $904)
    ParseErrorstd/text/parse/ParseError: forall<a> (msg : string, rest : sslice) -> parse-error<a>(msgmsg: string,_) -> Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(msgmsg: string)

pub fun parse-eofstd/text/parse/parse-eof: forall<a,e> (input : sslice, p : () -> <parse|e> a) -> e parse-error<a>( inputinput: sslice : sslicestd/core/sslice/sslice: V, pp: () -> <parse|$1938> $1937 : () -> <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> 1963 parse-error<1962> : ee: E parse-errorstd/text/parse/parse-error: V -> V<aa: V>
  parsestd/text/parse/parse: (input0 : sslice, p : () -> <parse|$1938> $1937) -> $1938 parse-error<$1937>(inputinput: sslice)
    val xx: $1937 = pp: () -> <parse|$1938> $1937()
    eofstd/text/parse/eof: () -> <parse|$1938> ()()
    xx: $1937

pub fun parsestd/text/parse/parse: forall<a,e> (input0 : sslice, p : () -> <parse|e> a) -> e parse-error<a>( input0input0: sslice : sslicestd/core/sslice/sslice: V, pp: () -> <parse|$1005> $1004 : () -> <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V )result: -> 1676 parse-error<1675> : ee: E parse-errorstd/text/parse/parse-error: V -> V<aa: V>
  var inputinput: local-var<$1014,sslice> := input0input0: sslice
  handlehandler: (() -> <parse,local<$1014>|$1005> $1004) -> <local<$1014>|$1005> parse-error<$1004> pp: () -> <parse|$1005> $1004
    returnreturn: (x : $1004) -> <local<$1014>|_1051> parse-error<$1004>(xx: $1004)
      ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(xx: $1004,inputinput: sslice)

    fun current-inputcurrent-input: () -> <local<$1014>|$1005> sslice()
      inputinput: sslice

    brk failfail: (msg : string) -> <local<$1014>|$1005> parse-error<$1004>(msgmsg: string)
      ParseErrorstd/text/parse/ParseError: forall<a> (msg : string, rest : sslice) -> parse-error<a>(msgmsg: string,inputinput: sslice)

    fun satisfysatisfy: (pred : (sslice) -> maybe<(_1066, sslice)>) -> <local<$1014>|$1005> maybe<_1066>(predpred: (sslice) -> maybe<(_1066, sslice)>)
      val inpinp: sslice = inputinput: sslice
      val mm: () -> maybe<(_1066, sslice)>   = fnfn: () -> maybe<(_1066, sslice)>() : totalstd/core/types/total: E __w-l61-c30: V { predpred: (sslice) -> maybe<(_1066, sslice)>(inpinp: sslice) }
      match mm: () -> <local<$1014>|$1005> maybe<(_1066, sslice)>()
        Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xx: _1066,capcap: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) -> { inputinput: local-var<$1014,sslice> :=std/core/types/local-set: (v : local-var<$1014,sslice>, assigned : sslice) -> <local<$1014>|$1005> () capcap: sslice; Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: _1066) }
        Nothingstd/core/types/Nothing: forall<a> maybe<a>       -> Nothingstd/core/types/Nothing: forall<a> maybe<a>

    ctl pickpick: (resume : (bool) -> <local<$1014>|$1005> parse-error<$1004>) -> <local<$1014>|$1005> parse-error<$1004>
() val savesave: sslice = inputinput: sslice; match resumeresume: (bool) -> <local<$1014>|$1005> parse-error<$1004>(Truestd/core/types/True: bool) ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x1x1: $1004,rest1rest1: sslice) -> ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x1x1: $1004,rest1rest1: sslice) err1err1: parse-error<$1004> -> inputinput: local-var<$1014,sslice> :=std/core/types/local-set: (v : local-var<$1014,sslice>, assigned : sslice) -> <local<$1014>|$1005> () savesave: sslice match resumeresume: (bool) -> <local<$1014>|$1005> parse-error<$1004>(Falsestd/core/types/False: bool) // todo: limit lookahead? ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x2x2: $1004,rest2rest2: sslice) -> ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x2x2: $1004,rest2rest2: sslice) _err2 -> err1err1: parse-error<$1004>
// todo: merge or pick closest? pub fun (||)std/text/parse/(||): forall<a,e> (p1 : parser<e,a>, p2 : parser<e,a>) -> <parse|e> a( p1p1: parser<$1736,$1735> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>, p2p2: parser<$1736,$1735> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|1755> 1754 : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V if pickstd/text/parse/pick: () -> <parse|$1736> bool() then p1p1: parser<$1736,$1735>() else p2p2: parser<$1736,$1735>() pub fun optionalstd/text/parse/optional: forall<a,e> (default : a, p : parser<e,a>) -> <parse|e> a( defaultdefault: $1762 : aa: V, pp: parser<$1763,$1762> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|1785> 1784 : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V pp: parser<$1763,$1762> ||std/text/parse/(||): (p1 : parser<$1763,$1762>, p2 : parser<$1763,$1762>) -> <parse|$1763> $1762 (fnfn: () -> <parse|$1763> $1762() defaultdefault: $1762) pub fun choosestd/text/parse/choose: forall<a,e> (ps : list<parser<e,a>>) -> <parse|e> a( psps: list<parser<$1793,$1792>> : liststd/core/types/list: V -> V<parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>> )result: -> <parse|1840> 1839 : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V match psps: list<parser<$1793,$1792>> Nilstd/core/types/Nil: forall<a> list<a> -> failstd/text/parse/fail: (msg : string) -> <parse|$1793> $1792("no further alternatives"literal: string
count= 23
) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(pp: parser<$1793,$1792>,Nilstd/core/types/Nil: forall<a> list<a>) -> pp: parser<$1793,$1792>() Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(pp: parser<$1793,$1792>,pppp: list<parser<$1793,$1792>>) -> if pickstd/text/parse/pick: () -> <parse|$1793> bool() then pp: parser<$1793,$1792>() else choosestd/text/parse/choose: (ps : list<parser<$1793,$1792>>) -> <parse|$1793> $1792(pppp: list<parser<$1793,$1792>>
) pub fun satisfy-failstd/text/parse/satisfy-fail: forall<a> (msg : string, pred : (sslice) -> maybe<(a, sslice)>) -> parse a( msgmsg: string : stringstd/core/types/string: V, predpred: (sslice) -> maybe<($1847, sslice)> : sslicestd/core/sslice/sslice: V -> maybestd/core/types/maybe: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,sslicestd/core/sslice/sslice: V)> )result: -> parse 1878 : parsestd/text/parse/parse: (E, V) -> V aa: V match satisfystd/text/parse/satisfy: (pred : (sslice) -> maybe<($1847, sslice)>) -> parse maybe<$1847>(predpred: (sslice) -> maybe<($1847, sslice)>) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> failstd/text/parse/fail: (msg : string) -> parse $1847(msgmsg: string) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1847) -> xx: $1847 pub fun eofstd/text/parse/eof: () -> parse ()()result: -> parse () : parsestd/text/parse/parse: (E, V) -> V (std/core/types/unit: V)std/core/types/unit: V match satisfystd/text/parse/satisfy: (pred : (sslice) -> maybe<((), sslice)>) -> parse maybe<()>( fnfn: (s : sslice) -> maybe<((), sslice)>(ss: sslice) if ss: sslice.is-emptystd/core/sslice/is-empty: (slice : sslice) -> bool then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)(std/core/types/Unit: ())std/core/types/Unit: (),ss: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) else Nothingstd/core/types/Nothing: forall<a> maybe<a> ) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> failstd/text/parse/fail: (msg : string) -> parse ()("expecting end-of-input"literal: string
count= 22
) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a> -> (std/core/types/Unit: ()
)std/core/types/Unit: () pub fun char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char( msgmsg: string :stringstd/core/types/string: V, predpred: (char) -> bool : charstd/core/types/char: V -> boolstd/core/types/bool: V )result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V satisfy-failstd/text/parse/satisfy-fail: (msg : string, pred : (sslice) -> maybe<(char, sslice)>) -> parse char(msgmsg: string) fnfn: (slice : sslice) -> maybe<(char, sslice)>(sliceslice: sslice) match sliceslice: sslice.nextstd/core/sslice/next: (slice : sslice) -> maybe<(char, sslice)> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)cc: char,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) | predpred: (char) -> bool(cc: char) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)cc: char,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) _ -> Nothingstd/core/types/Nothing: forall<a> maybe<a> fun next-while0std/text/parse/next-while0: (slice : sslice, pred : (char) -> bool, acc : list<char>) -> (list<char>, sslice)( sliceslice: sslice : sslicestd/core/sslice/sslice: V, predpred: (char) -> bool : charstd/core/types/char: V -> boolstd/core/types/bool: V, accacc: list<char> : liststd/core/types/list: V -> V<charstd/core/types/char: V> )result: -> total (list<char>, sslice) : (std/core/types/tuple2: (V, V) -> Vliststd/core/types/list: V -> V<charstd/core/types/char: V>,sslicestd/core/sslice/sslice: V) match sliceslice: sslice.nextstd/core/sslice/next: (slice : sslice) -> maybe<(char, sslice)> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)cc: char,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) | predpred: (char) -> bool(cc: char) -> next-while0std/text/parse/next-while0: (slice : sslice, pred : (char) -> bool, acc : list<char>) -> (list<char>, sslice)(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : sslice) -> sslice(restrest: sslice), predpred: (char) -> bool, Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(cc: char,accacc: list<char>) ) _ -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<char>.reversestd/core/list/reverse: (xs : list<char>) -> list<char>,sliceslice: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) pub fun chars-arestd/text/parse/chars-are: (msg : string, pred : (char) -> bool) -> parse list<char>( msgmsg: string :stringstd/core/types/string: V, predpred: (char) -> bool : charstd/core/types/char: V -> boolstd/core/types/bool: V )result: -> parse list<char> : parsestd/text/parse/parse: (E, V) -> V liststd/core/types/list: V -> V<charstd/core/types/char: V> satisfy-failstd/text/parse/satisfy-fail: (msg : string, pred : (sslice) -> maybe<(list<char>, sslice)>) -> parse list<char>(msgmsg: string) fnfn: (slice : sslice) -> maybe<(list<char>, sslice)>(sliceslice: sslice) match sliceslice: sslice.next-while0std/text/parse/next-while0: (slice : sslice, pred : (char) -> bool, acc : list<char>) -> (list<char>, sslice)(predpred: (char) -> bool,[std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)[std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,_)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) -> Nothingstd/core/types/Nothing: forall<a> maybe<a> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xsxs: list<char>,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xsxs: list<char>,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) fun next-matchstd/text/parse/next-match: (slice : sslice, cs : list<char>) -> maybe<sslice>( sliceslice: sslice : sslicestd/core/sslice/sslice: V, cscs: list<char> : liststd/core/types/list: V -> V<charstd/core/types/char: V> )result: -> total maybe<sslice> : maybestd/core/types/maybe: V -> V<sslicestd/core/sslice/sslice: V> match cscs: list<char> Nilstd/core/types/Nil: forall<a> list<a> -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(sliceslice: sslice) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(cc: char,cccc: list<char>) -> match sliceslice: sslice.nextstd/core/sslice/next: (slice : sslice) -> maybe<(char, sslice)> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)dd: char,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) | cc: char==std/core/char/(==): (char, char) -> booldd: char -> restrest: sslice.next-matchstd/text/parse/next-match: (slice : sslice, cs : list<char>) -> maybe<sslice>( cccc: list<char> ) _ -> Nothingstd/core/types/Nothing: forall<a> maybe<a> pub fun pstringstd/text/parse/pstring: (s : string) -> parse string( ss: string : stringstd/core/types/string: V )result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V satisfy-failstd/text/parse/satisfy-fail: (msg : string, pred : (sslice) -> maybe<(string, sslice)>) -> parse string(ss: string) fnfn: (slice : sslice) -> maybe<(string, sslice)>(sliceslice: sslice) match sliceslice: sslice.next-matchstd/text/parse/next-match: (slice : sslice, cs : list<char>) -> maybe<sslice>(ss: string.liststd/core/string/list: (s : string) -> list<char>) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(restrest: sslice) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)ss: string,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a> pub fun charstd/text/parse/char: (c : char) -> parse char( cc: char : charstd/core/types/char: V )result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char( showstd/core/show/char/show: (c : char) -> parse string(cc: char), fnfn: (c0 : char) -> bool(c0c0: char) cc: char ==std/core/char/(==): (char, char) -> bool c0c0: char ) pub fun no-digitstd/text/parse/no-digit: () -> parse char()result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char("not a digit"literal: string
count= 11
, fnfn: (c : char) -> bool(cc: char) !std/core/types/bool/(!): (b : bool) -> boolcc: char.is-digitstd/core/char/is-digit: (c : char) -> bool
) pub fun digitstd/text/parse/digit: () -> parse int()result: -> parse int : parsestd/text/parse/parse: (E, V) -> V intstd/core/types/int: V val cc: char = char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char("digit"literal: string
count= 5
, is-digitstd/core/char/is-digit: (c : char) -> bool) (cc: char -std/core/char/(-): (c : char, d : char) -> parse char '0'literal: char
unicode= u0030
).intstd/core/char/int: (char) -> parse int
pub fun alphastd/text/parse/alpha: () -> parse char()result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char("alpha"literal: string
count= 5
, is-alphastd/core/char/is-alpha: (c : char) -> bool
) pub fun alpha-numstd/text/parse/alpha-num: () -> parse char()result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char("alpha-num"literal: string
count= 9
, is-alpha-numstd/core/char/is-alpha-num: (c : char) -> bool
) pub fun whitestd/text/parse/white: () -> parse char()result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char(""literal: string
count= 0
, is-whitestd/core/char/is-white: (c : char) -> bool
) pub fun whitespacestd/text/parse/whitespace: () -> parse string()result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V chars-arestd/text/parse/chars-are: (msg : string, pred : (char) -> bool) -> parse list<char>(""literal: string
count= 0
, is-whitestd/core/char/is-white: (c : char) -> bool).stringstd/core/string/listchar/string: (cs : list<char>) -> parse string
pub fun whitespace0std/text/parse/whitespace0: () -> parse string()result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V optionalstd/text/parse/optional: (default : string, p : parser<total,string>) -> parse string(""literal: string
count= 0
, whitespacestd/text/parse/whitespace: () -> parse string
) pub fun digitsstd/text/parse/digits: () -> parse string()result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V chars-arestd/text/parse/chars-are: (msg : string, pred : (char) -> bool) -> parse list<char>("digit"literal: string
count= 5
, is-digitstd/core/char/is-digit: (c : char) -> bool ).stringstd/core/string/listchar/string: (cs : list<char>) -> parse string
pub fun digits0std/text/parse/digits0: () -> parse string()result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V optionalstd/text/parse/optional: (default : string, p : parser<total,string>) -> parse string("0"literal: string
count= 1
, digitsstd/text/parse/digits: () -> parse string
) pub fun signstd/text/parse/sign: () -> parse bool()result: -> parse bool : parsestd/text/parse/parse: (E, V) -> V boolstd/core/types/bool: V val cc: char = one-of-orstd/text/parse/one-of-or: (chars : string, default : char) -> parse char("+-"literal: string
count= 2
, '+'literal: char
unicode= u002B
) (cc: char==std/core/char/(==): (char, char) -> parse bool'-'literal: char
unicode= u002D
) pub fun pnatstd/text/parse/pnat: () -> parse int()result: -> parse int : parsestd/text/parse/parse: (E, V) -> V intstd/core/types/int: V digitsstd/text/parse/digits: () -> parse string().parse-intstd/core/int/parse-int: (s : string, hex : ? bool) -> parse maybe<int>.defaultstd/core/maybe/default: (m : maybe<int>, nothing : int) -> parse int(0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
) pub fun pintstd/text/parse/pint: () -> parse int()result: -> parse int : parsestd/text/parse/parse: (E, V) -> V intstd/core/types/int: V val negneg: bool = signstd/text/parse/sign: () -> parse bool() val ii: int = pnatstd/text/parse/pnat: () -> parse int() if negneg: bool then ~std/core/int/(~): (i : int) -> parse intii: int else ii: int pub fun none-ofstd/text/parse/none-of: (chars : string) -> parse char( charschars: string : stringstd/core/types/string: V )result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char(""literal: string
count= 0
, fnfn: (c : char) -> bool(cc: char) !std/core/types/bool/(!): (b : bool) -> boolcharschars: string.containsstd/core/string/contains: (s : string, sub : string) -> bool(cc: char.stringstd/core/string/char/string: (c : char) -> string)
) pub fun none-of-many1std/text/parse/none-of-many1: (chars : string) -> parse string( charschars: string : stringstd/core/types/string: V )result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V chars-arestd/text/parse/chars-are: (msg : string, pred : (char) -> bool) -> parse list<char>(""literal: string
count= 0
, fnfn: (c : char) -> bool(cc: char) !std/core/types/bool/(!): (b : bool) -> boolcharschars: string.containsstd/core/string/contains: (s : string, sub : string) -> bool(cc: char.stringstd/core/string/char/string: (c : char) -> string)).stringstd/core/string/listchar/string: (cs : list<char>) -> parse string
pub fun one-ofstd/text/parse/one-of: (chars : string) -> parse char( charschars: string : stringstd/core/types/string: V )result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V char-isstd/text/parse/char-is: (msg : string, pred : (char) -> bool) -> parse char(charschars: string, fnfn: (c : char) -> bool(cc: char) charschars: string.containsstd/core/string/contains: (s : string, sub : string) -> bool(cc: char.stringstd/core/string/char/string: (c : char) -> string)) // chars.list.map(fn(c){ (fn(){ char(c) } ) }).choose fun many-accstd/text/parse/many-acc: forall<a,e> (p : parser<e,a>, acc : list<a>) -> <parse|e> list<a>( pp: parser<$2567,$2566> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>, accacc: list<$2566> : liststd/core/types/list: V -> V<aa: V> )result: -> <parse|2618> list<2617> : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> liststd/core/types/list: V -> V<aa: V> (fnfn: () -> <parse|$2567> list<$2566>() val xx: $2566 = pp: parser<$2567,$2566>() in many-accstd/text/parse/many-acc: (p : parser<$2567,$2566>, acc : list<$2566>) -> <parse|$2567> list<$2566>(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : parser<$2567,$2566>) -> <parse|$2567> parser<$2567,$2566>(pp: parser<$2567,$2566>),Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2566,accacc: list<$2566>))) ||std/text/parse/(||): (p1 : parser<$2567,list<$2566>>, p2 : parser<$2567,list<$2566>>) -> <parse|$2567> list<$2566> (fnfn: () -> <parse|$2567> list<$2566>() accacc: list<$2566>.reversestd/core/list/reverse: (xs : list<$2566>) -> <parse|$2567> list<$2566>) // The `many` combinator parses `p` until it fails, returning a list of the results of `p`. // The `many` combinator is non-divergent only when `p` always consumes input or `fail`s. pub fun manystd/text/parse/many: forall<a,e> (p : parser<e,a>) -> <parse|e> list<a>( pp: parser<$2626,$2625> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|2648> list<2647> : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> liststd/core/types/list: V -> V<aa: V> many-accstd/text/parse/many-acc: (p : parser<$2626,$2625>, acc : list<$2625>) -> <parse|$2626> list<$2625>(pp: parser<$2626,$2625>,[std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>) // The `many1` combinator parses `p` at least once an then until it fails, returning a list of the results of `p`. // The `many1` combinator is non-divergent only when `p` always consumes input or `fail`s. pub fun many1std/text/parse/many1: forall<a,e> (p : parser<e,a>) -> <parse|e> list<a>( pp: parser<$2656,$2655> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|2682> list<2681> : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> liststd/core/types/list: V -> V<aa: V> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(pp: parser<$2656,$2655>(), manystd/text/parse/many: (p : parser<$2656,$2655>) -> <parse|$2656> list<$2655>(pp: parser<$2656,$2655>)) fun count-accstd/text/parse/count-acc: forall<a,e> (n : int, acc : list<a>, p : parser<e,a>) -> <parse|e> list<a>( nn: int : intstd/core/types/int: V, accacc: list<$2689> : liststd/core/types/list: V -> V<aa: V>, pp: parser<$2690,$2689> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|2754> list<2753> : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> liststd/core/types/list: V -> V<aa: V> if nn: int <=std/core/int/(<=): (x : int, y : int) -> <parse|$2690> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then accacc: list<$2689>.reversestd/core/list/reverse: (xs : list<$2689>) -> <parse|$2690> list<$2689> else val xx: $2689 = pp: parser<$2690,$2689>() count-accstd/text/parse/count-acc: (n : int, acc : list<$2689>, p : parser<$2690,$2689>) -> <parse|$2690> list<$2689>(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> <parse|$2690> int(nn: int -std/core/int/(-): (x : int, y : int) -> <parse|$2690> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
), Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2689,accacc: list<$2689>), pp: parser<$2690,$2689>
) pub fun countstd/text/parse/count: forall<a,e> (n : int, p : parser<e,a>) -> <parse|e> list<a>( nn: int : intstd/core/types/int: V, pp: parser<$2762,$2761> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|2785> list<2784> : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> liststd/core/types/list: V -> V<aa: V> count-accstd/text/parse/count-acc: (n : int, acc : list<$2761>, p : parser<$2762,$2761>) -> <parse|$2762> list<$2761>(nn: int, [std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>, pp: parser<$2762,$2761>) pub fun one-of-orstd/text/parse/one-of-or: (chars : string, default : char) -> parse char( charschars: string : stringstd/core/types/string: V, defaultdefault: char : charstd/core/types/char: V )result: -> parse char : parsestd/text/parse/parse: (E, V) -> V charstd/core/types/char: V optionalstd/text/parse/optional: (default : char, p : parser<total,char>) -> parse char(defaultdefault: char){ one-ofstd/text/parse/one-of: (chars : string) -> parse char(charschars: string) } //val rx-float = regex(r"^([\-\+])?(\d+(?:\.\d+)?(?:[eE][\-\+]\d+)?)$") //val rx-hexfloat = regex(r"^([\-\+]?0[xX][0-9a-fA-F]+)(?:\.([0-9a-fA-F]+))?(?:[pP]([\-\+]?\d+))?$") pub fun hex-digitsstd/text/parse/hex-digits: () -> parse string()result: -> parse string : parsestd/text/parse/parse: (E, V) -> V stringstd/core/types/string: V chars-arestd/text/parse/chars-are: (msg : string, pred : (char) -> bool) -> parse list<char>("digit"literal: string
count= 5
, is-hex-digitstd/core/char/is-hex-digit: (c : char) -> bool ).stringstd/core/string/listchar/string: (cs : list<char>) -> parse string
/* pub fun test(s : string, x : a, p : () -> parse a ) : a parse-eof(s.slice,p).maybe.default(x) */