A templating language that looks like Lisp and compiles to HTML
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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. }