|
1 | 1 | import Lox from './Lox' |
| 2 | +import ReservedWords from './ReservedWords' |
2 | 3 | import Token from './Token' |
3 | 4 | import TokenType from './TokenType' |
4 | | -import ReservedWords from './ReservedWords' |
5 | 5 |
|
6 | 6 | export default class Scanner { |
7 | 7 | /** Publicly available list of tokens, generated on construction of the class. */ |
8 | 8 | public tokens: Token[] = [] |
9 | 9 |
|
10 | 10 | /** Source program stream to parse into tokens. */ |
11 | 11 | private source: string |
12 | | - |
| 12 | + |
13 | 13 | /** Start location of the current token in `this.source`. */ |
14 | 14 | private start = 0 |
15 | 15 |
|
16 | | - /** Location in `this.stream` currently being examined. */ |
| 16 | + /** Location in `this.stream` currently being examined. */ |
17 | 17 | private current = 0 |
18 | 18 |
|
19 | 19 | /** Current line in `this.source`. Advanced each time `\n` is encountered. */ |
@@ -43,7 +43,7 @@ export default class Scanner { |
43 | 43 | private isAlpha = (c: string) => ( |
44 | 44 | (c >= 'a' && c <= 'z') || |
45 | 45 | (c >= 'A' && c <= 'Z') || |
46 | | - c == '_' |
| 46 | + c === '_' |
47 | 47 | ) |
48 | 48 |
|
49 | 49 | /** Check if a character is alpha, numeric, or an underscore. */ |
@@ -132,7 +132,7 @@ export default class Scanner { |
132 | 132 | /** |
133 | 133 | * Checks if the next character in the stream is a specific character. If it is, advance the stream |
134 | 134 | * by one character. |
135 | | - * @param expected - A character to match next in the stream. |
| 135 | + * @param expected - A character to match next in the stream. |
136 | 136 | * @returns true if the next character is expected, false otherwise. |
137 | 137 | */ |
138 | 138 | private match(expected: string): boolean { |
@@ -181,11 +181,11 @@ export default class Scanner { |
181 | 181 | } |
182 | 182 |
|
183 | 183 | /** Parse an identifier from the current position and add it to `this.tokens`. */ |
184 | | - private identifier() { |
185 | | - while (this.isAlphaNumeric(this.peek())) this.advance(); |
| 184 | + private identifier() { |
| 185 | + while (this.isAlphaNumeric(this.peek())) this.advance() |
186 | 186 |
|
187 | 187 | const { source, start, current } = this |
188 | 188 | const text: string = source.substring(start, current) |
189 | | - this.addToken(ReservedWords[text] || TokenType.IDENTIFIER); |
190 | | - } |
| 189 | + this.addToken(ReservedWords[text] || TokenType.IDENTIFIER) |
| 190 | + } |
191 | 191 | } |
0 commit comments