private Token [ ] match ( Token . Kind ... kinds ) { Token [ ] result = new Token [ kinds . length ] ; for ( int i = 0 ; i != result . length ; ++ i ) { checkNotEof ( ) ; Token token = tokens . get ( index ++ ) ; if ( token . kind == kinds [ i ] ) { result [ i ] = token ; } else { syntaxError ( "Expected \"" + kinds [ i ] + "\" here" , token ) ; } } return result ; }
Match a given sequence of tokens whilst moving passed any whitespace encountered inbetween . In the case that meet the end of the stream or we don t match the expected tokens in the expected order then an error is thrown .