Kind/book/String.skip.kind2
Victor Taelin 9c1a3f16a0 checkpoint
2024-02-20 16:50:19 -03:00

47 lines
1.6 KiB
Plaintext

// Skips space characters and comments
String.skip
: ∀(str: String)
String
= λstr
// Pattern-matches str
let P = λx(String)
let cons = λc0 λcs
// If first char is space, skip it
let P = λx ∀(c0: Char) ∀(cs: String) (String)
let true = λc0 λcs (String.skip cs)
let false = λc0 λcs
// If first char is slash, check next char
let P = λx ∀(c0: Char) ∀(cs: String) (String)
let true = λc0 λcs
// Pattern-matches str's tail
let P = λx ∀(c0: Char) (String)
let cons = λc1 λcs λc0
// If second char is slash, skip comment
let P = λx ∀(c0: Char) ∀(c1: Char) ∀(cs: String) (String)
let true = λc0 λc1 λcs (String.skip.comment cs)
let false = λc0 λc1 λcs (String.cons c0 (String.cons c1 cs))
(~(Char.is_slash c1) P true false c0 c1 cs)
let nil = λc0 (String.cons c0 String.nil)
(~cs P cons nil c0)
let false = λc0 λcs (String.cons c0 cs)
(~(Char.is_slash c0) P true false c0 cs)
(~(Char.is_blank c0) P true false c0 cs)
let nil = String.nil
(~str P cons nil)
// Skips all characters until Char.is_newline is true
String.skip.comment
: ∀(str: String)
String
= λstr
// Pattern-matches str
let P = λx(String)
let cons = λc0 λcs
// If first char is not a newline, skip and recurse
let P = λx ∀(c0: Char) ∀(cs: String) (String)
let true = λc0 λcs (String.skip cs)
let false = λc0 λcs (String.skip.comment cs)
(~(Char.is_newline c0) P true false c0 cs)
let nil = String.nil
(~str P cons nil)