# 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

    224x
    224x

    19165x
    4526x
    224x

    224x

     // @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 + 1];
      const last = () => tokens[length - 1];

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