-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotes.txt
87 lines (77 loc) · 2.55 KB
/
notes.txt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Parser Combinators Talk
1. Intro
- so you need to write a parser?
- primitive string operations
- regexs
- lex, yacc, JavaCC etc
- simple idea from functional programming
2. What is the simplest parser we can think of?
- dot
- implement first with bool result
- write test
- discuss lack of information in bool result
- discuss need for remaining string for combining parsers
- refactor result type to including remaining input on Ok
3. More interesting parsers
- string() amd integer()
- quotedString()
- test
4. Take stock
- what have we so far?
- lots of repetition in result types
- add Parser<T> type aliases
- refactor
5. Combining Parsers
- what does it mean to combine parsers?
- discuss semantics of sequence
- what would a function that combines two parsers look like?
- start with signature
- note that params and return are all functions
- implement unrolled version
- add tests
- discuss patterns in unrolled code
- factor out inner `when` to ParseResult.map()
- note that Result is acting as a Functor
- factor out outer `when` to Result.flatMap()
- note that ParseResult is acting as a Monad
- discuss naming of flatMap()
- rerun tests
6. Choice
- the other main combinator is choice
- both branches must yield the same type
- implement and add positive tests
- note that return values are the same for both branches
- discuss adding result data to `string()`
- add `Parser.means()`
- discuss extension on function type
- modify test to use `means()`
- add a failing test case with 'a or b' expect message
- implement and use `mapExpected`
7. Take advantage of Kotlin
- `seq` can become infix `then`
- `choice` can be come infix `or`
8. Other combinators
- before
- then
- between
- many
- sepBy
- whitespace
9. Parsing JSON
- add JSON model
- add test case
- trivial cases: null, true, false, int, string
- start on array
- stub array item to start with; focus on sepBy, between
- we need the "full" json parser for items
- seems like a disaster but there's a simple fix in `LazyParser<T>`
- object parser is similar
- finally add the full JSON parser
- remember to set ref
10. Conclusion
- parsers are just functions
- with a few rules they are easy to combine
- separating lex and grammar stages
- error messages and source positions
- you can't debug this by stepping through
- debug by breaking down problems