/*---------------------------------------------------------------------------
  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

// A function that parses some input into a result `a`.
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

// Management of the branching alternatives for parsing an input string.
pubstd/text/parse/parse: (E, V) -> V effect parsestd/text/parse/parse: (E, V) -> V
  // Advance the input if and only if it currently satisfies `pred`.
  // Further parsers continue with the slice it returns.
  // 
  // See also `satisfy-fail` which invokes `fail` when `pred` returns `Nothing`.
  fun satisfy( predpred: (sslice) -> maybe<($478, 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>
  // Fails the current branch of parsing.
  final ctl fail(msgmsg: string : stringstd/core/types/string: V) : aa: V
  // Pick allows the user to try different parses.
  // Handlers usually resume up to twice with `True` and `False`.
  ctl pick() : boolstd/core/types/bool: V
  // The current position of parse on the input.
  fun current-input() : sslicestd/core/sslice/sslice: V

// Result of a parse
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 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 $1468 : () -> parsestd/text/parse/parse: (E, V) -> V aa: V )result: -> total maybe<(1520, 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 $1468) -> parse-error<$1468>(pp: () -> parse $1468)
    ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(xx: $1468,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: $1468,restrest: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b))
    _               -> Nothingstd/core/types/Nothing: forall<a> maybe<a>

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

pub fun eitherstd/text/parse/either: forall<a> (perr : parse-error<a>) -> either<string,a>( perrperr: parse-error<$944> : parse-errorstd/text/parse/parse-error: V -> V<aa: V> )result: -> total either<string,983> : eitherstd/core/types/either: (V, V) -> V<stringstd/core/types/string: V,aa: V>
  match perrperr: parse-error<$944>
    ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(xx: $944,_) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $944)
    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|$1757> $1756 : () -> <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> 1785 parse-error<1784> : ee: E parse-errorstd/text/parse/parse-error: V -> V<aa: V>
  parsestd/text/parse/parse: (input0 : sslice, p : () -> <parse|$1757> $1756) -> $1757 parse-error<$1756>(inputinput: sslice)
    val xx: $1756 = pp: () -> <parse|$1757> $1756()
    eofstd/text/parse/eof: () -> <parse|$1757> ()()
    xx: $1756

// Parses `input0` with `p`.
//
// This implements the `pick` ctl using a depth-first search,
//   short-circuiting if the `True` branch succeeds.
// If both alternatives of a `pick` invoke `fail`, 
//   the first error will be returned.
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|$1054> $1053 : () -> <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V )result: -> 1461 parse-error<1460> : ee: E parse-errorstd/text/parse/parse-error: V -> V<aa: V>
  var inputinput: local-var<$1064,sslice> := input0input0: sslice
  handlehandler: (() -> <local<$1064>,parse|$1054> $1053) -> <local<$1064>|$1054> parse-error<$1053> pp: () -> <parse|$1054> $1053
    returnreturn: (x : $1053) -> <local<$1064>|_1094> parse-error<$1053>(xx: $1053)
      ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(xx: $1053,inputinput: sslice
?hdiv=iev@1095
?hdiv=iev@1411
) fun current-inputcurrent-input: () -> <local<$1064>|$1054> sslice() inputinput: sslice
?hdiv=iev@1168
final ctl failfail: (msg : string) -> <local<$1064>|$1054> parse-error<$1053>(msgmsg: string) ParseErrorstd/text/parse/ParseError: forall<a> (msg : string, rest : sslice) -> parse-error<a>(msgmsg: string,inputinput: sslice
?hdiv=iev@1213
) fun satisfysatisfy: (pred : (sslice) -> maybe<(_1118, sslice)>) -> <local<$1064>|$1054> maybe<_1118>(predpred: (sslice) -> maybe<(_1118, sslice)>) val inpinp: sslice = inputinput: sslice
?hdiv=iev@1335
val mm: () -> maybe<(_1118, sslice)> = fnfn: () -> maybe<(_1118, sslice)>() : totalstd/core/types/total: E __w-l77-c30: V { predpred: (sslice) -> maybe<(_1118, sslice)>(inpinp: sslice) } match mm: () -> <local<$1064>|$1054> maybe<(_1118, 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: _1118,capcap: sslice)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)) -> { inputinput: local-var<$1064,sslice> :=std/core/types/local-set: (v : local-var<$1064,sslice>, assigned : sslice) -> <local<$1064>|$1054> () capcap: sslice; Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: _1118) } Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a> ctl pickpick: (resume : (bool) -> <local<$1064>|$1054> parse-error<$1053>) -> <local<$1064>|$1054> parse-error<$1053>
() val savesave: sslice = inputinput: sslice
?hdiv=iev@1248
; match resumeresume: (bool) -> <local<$1064>|$1054> parse-error<$1053>(Truestd/core/types/True: bool) ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x1x1: $1053,rest1rest1: sslice) -> ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x1x1: $1053,rest1rest1: sslice) err1err1: parse-error<$1053> -> inputinput: local-var<$1064,sslice> :=std/core/types/local-set: (v : local-var<$1064,sslice>, assigned : sslice) -> <local<$1064>|$1054> () savesave: sslice match resumeresume: (bool) -> <local<$1064>|$1054> parse-error<$1053>(Falsestd/core/types/False: bool) // todo: limit lookahead? ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x2x2: $1053,rest2rest2: sslice) -> ParseOkstd/text/parse/ParseOk: forall<a> (result : a, rest : sslice) -> parse-error<a>(x2x2: $1053,rest2rest2: sslice) _err2 -> err1err1: parse-error<$1053>
// 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<$1526,$1525> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>, p2p2: parser<$1526,$1525> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|1548> 1547 : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V if pickstd/text/parse/pick: () -> <parse|$1526> bool() then p1p1: parser<$1526,$1525>() else p2p2: parser<$1526,$1525>() pub fun optionalstd/text/parse/optional: forall<a,e> (default : a, p : parser<e,a>) -> <parse|e> a( defaultdefault: $1555 : aa: V, pp: parser<$1556,$1555> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|1581> 1580 : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V pp: parser<$1556,$1555> ||std/text/parse/(||): (p1 : parser<$1556,$1555>, p2 : parser<$1556,$1555>) -> <parse|$1556> $1555 (fnfn: () -> <parse|$1556> $1555() defaultdefault: $1555) pub fun choosestd/text/parse/choose: forall<a,e> (ps : list<parser<e,a>>) -> <parse|e> a( psps: list<parser<$1589,$1588>> : liststd/core/types/list: V -> V<parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>> )result: -> <parse|1645> 1644 : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V match psps: list<parser<$1589,$1588>> Nilstd/core/types/Nil: forall<a> list<a> -> failstd/text/parse/fail: (msg : string) -> <parse|$1589> $1588("no further alternatives"literal: string
count= 23
) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(pp: parser<$1589,$1588>,Nilstd/core/types/Nil: forall<a> list<a>) -> pp: parser<$1589,$1588>() Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(pp: parser<$1589,$1588>,pppp: list<parser<$1589,$1588>>) -> if pickstd/text/parse/pick: () -> <parse|$1589> bool() then pp: parser<$1589,$1588>() else choosestd/text/parse/choose: (ps : list<parser<$1589,$1588>>) -> <parse|$1589> $1588(pppp: list<parser<$1589,$1588>>
) 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<($1652, 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 1687 : parsestd/text/parse/parse: (E, V) -> V aa: V match satisfystd/text/parse/satisfy: (pred : (sslice) -> maybe<($1652, sslice)>) -> parse maybe<$1652>(predpred: (sslice) -> maybe<($1652, sslice)>) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> failstd/text/parse/fail: (msg : string) -> parse $1652(msgmsg: string) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1652) -> xx: $1652 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<$2807,$2806> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>, accacc: list<$2806> : liststd/core/types/list: V -> V<aa: V> )result: -> <parse|2866> list<2865> : <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|$2807> list<$2806>() val xx: $2806 = pp: parser<$2807,$2806>() in many-accstd/text/parse/many-acc: (p : parser<$2807,$2806>, acc : list<$2806>) -> <parse|$2807> list<$2806>(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : parser<$2807,$2806>) -> <parse|$2807> parser<$2807,$2806>(pp: parser<$2807,$2806>),Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2806,accacc: list<$2806>))) ||std/text/parse/(||): (p1 : parser<$2807,list<$2806>>, p2 : parser<$2807,list<$2806>>) -> <parse|$2807> list<$2806> (fnfn: () -> <parse|$2807> list<$2806>() accacc: list<$2806>.reversestd/core/list/reverse: (xs : list<$2806>) -> <parse|$2807> list<$2806>) // 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<$2874,$2873> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|2897> list<2896> : <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<$2874,$2873>, acc : list<$2873>) -> <parse|$2874> list<$2873>(pp: parser<$2874,$2873>,[std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>) // The `many1` combinator parses `p` at least once and 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<$2905,$2904> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|2934> list<2933> : <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<$2905,$2904>(), manystd/text/parse/many: (p : parser<$2905,$2904>) -> <parse|$2905> list<$2904>(pp: parser<$2905,$2904>)) // The `sep-by` parses zero or more occurrences of `p`, separated by `sep`. Returns a list of the results of `p`. // The `sep-by` combinator is non-divergent only when `p` always consumes input or `fail`s. pub fun sep-bystd/text/parse/sep-by: forall<a,b,e> (p : parser<e,a>, sep : parser<e,b>) -> <parse|e> list<a>( pp: parser<$3308,$3306> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>, sepsep: parser<$3308,$3307> : parserstd/text/parse/parser: (E, V) -> V<ee: E,bb: V> )result: -> <parse|3349> list<3347> : <parsestd/text/parse/parse: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> liststd/core/types/list: V -> V<aa: V> optionalstd/text/parse/optional: (default : list<$3306>, p : parser<$3308,list<$3306>>) -> <parse|$3308> list<$3306>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>){ sep-by1std/text/parse/sep-by1: (p : parser<$3308,$3306>, sep : parser<$3308,$3307>) -> <parse|$3308> list<$3306>(pp: parser<$3308,$3306>, sepsep: parser<$3308,$3307>) } // The `sep-by1` parses one or more occurrences of `p`, separated by `sep`. Returns a list of the results of `p`. // The `sep-by1` combinator is non-divergent only when `p` always consumes input or `fail`s. pub fun sep-by1std/text/parse/sep-by1: forall<a,b,e> (p : parser<e,a>, sep : parser<e,b>) -> <parse|e> list<a>( pp: parser<$3258,$3256> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V>, sepsep: parser<$3258,$3257> : parserstd/text/parse/parser: (E, V) -> V<ee: E,bb: V> )result: -> <parse|3296> list<3294> : <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<$3258,$3256>(), manystd/text/parse/many: (p : parser<$3258,$3256>) -> <parse|$3258> list<$3256>{ sepsep: parser<$3258,$3257>(); pp: parser<$3258,$3256>(); }) 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<$2941> : liststd/core/types/list: V -> V<aa: V>, pp: parser<$2942,$2941> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|3035> list<3034> : <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|$2942> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then accacc: list<$2941>.reversestd/core/list/reverse: (xs : list<$2941>) -> <parse|$2942> list<$2941> else val xx: $2941 = pp: parser<$2942,$2941>() count-accstd/text/parse/count-acc: (n : int, acc : list<$2941>, p : parser<$2942,$2941>) -> <parse|$2942> list<$2941>(pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> <parse|$2942> int(nn: int -std/core/int/(-): (x : int, y : int) -> <parse|$2942> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
), Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2941,accacc: list<$2941>), pp: parser<$2942,$2941>
) 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<$3043,$3042> : parserstd/text/parse/parser: (E, V) -> V<ee: E,aa: V> )result: -> <parse|3067> list<3066> : <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<$3042>, p : parser<$3043,$3042>) -> <parse|$3043> list<$3042>(nn: int, [std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>, pp: parser<$3043,$3042>) 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) */