-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.lean
49 lines (37 loc) · 1.66 KB
/
Main.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Straume
open Straume.Chunk in
open Straume in
open Zeptoparsec in
open Straume.Iterator in
def main : IO Unit := do
IO.println "STREAM DEMO 9000! NOW WORKING!"
let file := System.mkFilePath ["./Tests/", "PrideAndPrejudice.txt"]
IO.println "Let's read some Jane Austin!\n"
let (zoink, h₀) ← IO.FS.withFile file (.read)
(fun handle => Straume.MonadEmit.askFrom handle 38)
IO.println s!"{String.fromUTF8Unchecked zoink}\n"
IO.println "Nice! How does that sentence end? Let's find out, with CHUNKS!\n"
let ((zoink1 : Chunk String), (buff₁, h₁)) ← takeN 80 ("", h₀) 200
IO.println s!"CHUNK IS {zoink1}"
IO.println s!"BUFFER IS {buff₁}"
IO.println "\nOh, it's a classic. Let's read the whole Chapter 1!\n"
let ((zoink2 : Chunk String), (buff₂, _)) ← takeN 80000 ("", h₁)
IO.println s!"CHUNK IS {zoink2}"
IO.println s!"BUFFER IS {if buff₂ == "" then "EMPTY" else buff₂}"
IO.println "\nVery cool. Let's go from the top UNTIL we find a PERIOD.\n"
let ((zoink3 : Chunk String), _) ← IO.FS.withFile file (.read)
(fun handle => takeWhile (fun c => c != '.') ("", handle))
IO.println s!"CHUNK IS {zoink3}"
IO.println s!"BTW, CHUNK'S SIZE IS {Aka.chunkLength zoink3}"
-- Example of subsequent Zeptoparsec usage
let sentencesP := attempt $ do
let body ← manyChars (satisfy (fun c => c != '.'))
_ ← pchar '.' *> optionalP ws
pure $ body ++ "."
let sentences :=
match (Zeptoparsec.run (many sentencesP) $ coreturn zoink2) with
| Except.ok res => res
| Except.error _ => default
let small := List.filter (fun s => s.length < 50) $ sentences.toList
IO.println small.length
IO.println small