mirror of
https://github.com/HigherOrderCO/Kind.git
synced 2024-09-11 16:46:06 +03:00
26 lines
1.2 KiB
Plaintext
26 lines
1.2 KiB
Plaintext
Parser.test
|
|
: ∀(test: String)
|
|
(Parser Bool)
|
|
= λtest λcode
|
|
// Gets the first expected character.
|
|
let P = λx ∀(code: String) (Parser.Result Bool)
|
|
let cons = λtest.head λtest.tail λcode
|
|
// Gets the first detected character.
|
|
let P = λx (Parser.Result Bool)
|
|
let cons = λcode.head λcode.tail
|
|
// Checks if expected == detected.
|
|
let P = λx ∀(code.head: Char) ∀(code.tail: String) (Parser.Result Bool)
|
|
let true = λcode.head λcode.tail
|
|
// If so, parses the next character and reconstructs the original code.
|
|
let P = λx(Parser.Result Bool)
|
|
let done = λcode λvalue (Parser.Result.done Bool (String.cons code.head code) value)
|
|
let fail = λerror (Parser.Result.fail Bool error)
|
|
(~(Parser.test test.tail code.tail) P done fail)
|
|
let false = λcode.head λcode.tail
|
|
// Otherwise, returns false and reconstructs the original code.
|
|
(Parser.Result.done Bool (String.cons code.head code.tail) Bool.false)
|
|
((~(Char.equal test.head code.head) P true false) code.head code.tail)
|
|
let nil = (Parser.Result.done Bool String.nil Bool.false)
|
|
(~code P cons nil)
|
|
let nil = λcode (Parser.Result.done Bool code Bool.true)
|
|
(~test P cons nil code) |