()
| 237 | } |
| 238 | |
| 239 | private parseIdentifier(): any { |
| 240 | const start = this.index; |
| 241 | // An identifier can start with a letter, underscore, or dollar sign. |
| 242 | const firstChar = this.currentChar(); |
| 243 | if (!/[a-zA-Z$_]/.test(firstChar)) { |
| 244 | throw this.error(`Unexpected token '${firstChar}'`); |
| 245 | } |
| 246 | this.index++; |
| 247 | while (!this.isAtEnd()) { |
| 248 | const ch = this.currentChar(); |
| 249 | if (!/[a-zA-Z0-9$_]/.test(ch)) break; |
| 250 | this.index++; |
| 251 | } |
| 252 | const token = this.text.slice(start, this.index); |
| 253 | // Recognize standard literals. |
| 254 | if (token === 'true') return true; |
| 255 | if (token === 'false') return false; |
| 256 | if (token === 'null') return null; |
| 257 | if (token === 'Infinity') return Infinity; |
| 258 | if (token === 'NaN') return NaN; |
| 259 | return token; |
| 260 | } |
| 261 | |
| 262 | skipWhitespace(): void { |
| 263 | while (!this.isAtEnd()) { |
no test coverage detected