# All files / src/utils token-stream.js

100% Statements 9/9
100% Branches 0/0
100% Functions 4/4
100% Lines 6/6

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21

    103x
    103x

    5110x
    624x
    148x

    103x

     // @flow
    import type { TokenType } from "../flow/types";

    export type TokenStream = {
      next: () => TokenType,
      peek: () => TokenType,
      last: () => TokenType,
      tokens: TokenType[],
    };

    export default function tokenStream(tokens: TokenType[]): TokenStream {
      const length = tokens.length;
      let pos = 0;

      const next = () => tokens[pos++];
      const peek = () => tokens[pos];
      const last = () => tokens[length - 1];

      return { tokens, next, peek, last, length };
    }