A templating language that looks like Lisp and compiles to HTML
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tokenStream.js 571B

1234567891011121314151617181920212223242526272829303132
  1. const OsloError = require('./osloError')
  2. module.exports = class TokenStream {
  3. constructor() {
  4. this.tokens = []
  5. this.position = 0
  6. }
  7. advance() {
  8. this.position++
  9. }
  10. eat(tokenType) {
  11. let token = this.peek()
  12. if (token && token.type === tokenType) {
  13. this.advance()
  14. return token
  15. }
  16. this.error = new OsloError({
  17. line: token.line,
  18. message: `Encountered an unexpected ${
  19. token.type
  20. } while looking for a ${tokenType}.`,
  21. })
  22. }
  23. peek(step = 0) {
  24. return this.tokens[this.position + step]
  25. }
  26. }