<commit_before>import { LookaheadMismatchError , UnexpectedEndOfFileError } from '../error' ;
import _parse_lazy from './_parse_lazy' ;

/**
 * Get next child of table-driven predictive lazy parsing.
 *
 * @param grammar
 * @param table
 * @param tape
 * @param token
 * @returns {Array}
 */
export default async function _children_next_lazy ( eof, grammar , table , tape , expected ) {

	const lookahead = await tape.read( ) ;

	if ( expected.type === 'leaf' ) {
		if ( lookahead === tape.eof ) {
			if ( expected.terminal === eof ) return expected ;
			else throw new UnexpectedEndOfFileError( [expected.terminal] ) ;
		}
		else if ( lookahead.terminal === expected.terminal ) return lookahead ;
		else throw new LookaheadMismatchError(lookahead, [expected.terminal]) ;
	}

	tape.unread(lookahead);

	const router = table.get(expected.nonterminal);

	const next = router.get(lookahead === tape.eof ? eof : lookahead.terminal) ;

	if ( next === undefined ) throw new LookaheadMismatchError(lookahead, [...router.keys()]) ;

	else return _parse_lazy(eof, grammar, table, grammar.get(expected.nonterminal).get(next), tape , expected.nonterminal , next);

}<commit_msg>better error for eof with nonterminal lookahead<commit_after>import { LookaheadMismatchError , UnexpectedEndOfFileError } from '../error' ;
import _parse_lazy from './_parse_lazy' ;

/**
 * Get next child of table-driven predictive lazy parsing.
 *
 * @param grammar
 * @param table
 * @param tape
 * @param token
 * @returns {Array}
 */
export default async function _children_next_lazy ( eof, grammar , table , tape , expected ) {

	const lookahead = await tape.read( ) ;

	if ( expected.type === 'leaf' ) {
		if ( lookahead === tape.eof ) {
			if ( expected.terminal === eof ) return expected ;
			else throw new UnexpectedEndOfFileError( [expected.terminal] ) ;
		}
		else if ( lookahead.terminal === expected.terminal ) return lookahead ;
		else throw new LookaheadMismatchError(lookahead, [expected.terminal]) ;
	}

	tape.unread(lookahead);

	const router = table.get(expected.nonterminal);

	const next = router.get(lookahead === tape.eof ? eof : lookahead.terminal) ;

	if ( next === undefined ) {
		if ( lookahead === tape.eof ) throw new UnexpectedEndOfFileError( [...router.keys()] ) ;
		else throw new LookaheadMismatchError(lookahead, [...router.keys()]) ;
	}

	else return _parse_lazy(eof, grammar, table, grammar.get(expected.nonterminal).get(next), tape , expected.nonterminal , next);

}
{'fraction_non_alphanumeric': 0.13152569809793604, 'fraction_numerical': 0.0, 'mean_word_length': 4.237288135593221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4644878', 'n_tokens_mistral': 843, 'n_tokens_neox': 755, 'n_words': 202}