lexValue lexes a value at the end of a statement
(l *lexer)
| 286 | |
| 287 | // lexValue lexes a value at the end of a statement |
| 288 | func lexValue(l *lexer) lexFn { |
| 289 | l.acceptRun(" ") |
| 290 | l.ignore() |
| 291 | |
| 292 | if l.accept("=") { |
| 293 | l.emit(typEquals) |
| 294 | } else { |
| 295 | return nil |
| 296 | } |
| 297 | l.acceptRun(" ") |
| 298 | l.ignore() |
| 299 | |
| 300 | switch { |
| 301 | |
| 302 | case l.accept(`"`): |
| 303 | l.acceptUntilUnescaped(`"`) |
| 304 | l.accept(`"`) |
| 305 | l.emit(typString) |
| 306 | |
| 307 | case l.accept("t"): |
| 308 | l.acceptRun("rue") |
| 309 | l.emit(typTrue) |
| 310 | |
| 311 | case l.accept("f"): |
| 312 | l.acceptRun("alse") |
| 313 | l.emit(typFalse) |
| 314 | |
| 315 | case l.accept("n"): |
| 316 | l.acceptRun("ul") |
| 317 | l.emit(typNull) |
| 318 | |
| 319 | case l.accept("["): |
| 320 | l.accept("]") |
| 321 | l.emit(typEmptyArray) |
| 322 | |
| 323 | case l.accept("{"): |
| 324 | l.accept("}") |
| 325 | l.emit(typEmptyObject) |
| 326 | |
| 327 | default: |
| 328 | // Assume number |
| 329 | l.acceptUntil(";") |
| 330 | l.emit(typNumber) |
| 331 | } |
| 332 | |
| 333 | l.acceptRun(" ") |
| 334 | l.ignore() |
| 335 | |
| 336 | if l.accept(";") { |
| 337 | l.emit(typSemi) |
| 338 | } |
| 339 | |
| 340 | // The value should always be the last thing |
| 341 | // in the statement |
| 342 | return nil |
| 343 | } |
| 344 | |
| 345 | // lexIgnore accepts runes until the end of the input |
nothing calls this directly
no test coverage detected