Commit 6899325
authored
Lexer and parser refactor (#31)
The on-demand lexer is replaced with a standalone lexing pass using the
Logos crate. The lexing code is refactored away from the parser into a
separate data structure. The Parser is refactored and simplified
accordingly.
The new lexer correctly recognizes more syntactic shapes than the
previous one.
The new lexer+parser seems slightly faster (5-6 ms together on the
combined1000.nu benchmark) than the previous version, but the main
benefit is the lexer disentangled from the parser code. It is now
possible to change the lexer more easily, including turning it into an
on-demand lexer again if need be.
The main shortcomings are:
* Difficulty lexing string interpolation, e.g., `$"foo(1 + 2)bar"`. We'd
need to switch to another lexer. It might be easier to use on-demand
lexing for it.
* Unmatched delimiters. If the file ends with an unmatched delimiter, an
extremely unhelpful error is emitted. This should be solvable by using
[callbacks](https://logos.maciej.codes/callbacks.html).
Notable API changes:
* `self.peek()` -> `self.tokens.peek()`
* `self.next()` -> gone, use `self.tokens.advance()` to point at the
next tokens followed by `self.tokens.peek()`.1 parent eba4f27 commit 6899325
File tree
27 files changed
+1476
-1577
lines changed- benches
- nu
- src
- snapshots
- tests
- lex
27 files changed
+1476
-1577
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| |||
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
55 | 66 | | |
56 | | - | |
| 67 | + | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
| |||
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
90 | | - | |
91 | | - | |
| 101 | + | |
| 102 | + | |
92 | 103 | | |
93 | 104 | | |
94 | 105 | | |
| |||
129 | 140 | | |
130 | 141 | | |
131 | 142 | | |
132 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
133 | 151 | | |
134 | 152 | | |
135 | 153 | | |
| |||
176 | 194 | | |
177 | 195 | | |
178 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
179 | 212 | | |
180 | 213 | | |
181 | 214 | | |
182 | 215 | | |
183 | 216 | | |
184 | 217 | | |
185 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
186 | 227 | | |
187 | 228 | | |
188 | 229 | | |
| |||
0 commit comments