import { Token } from '../Lexer' ; import { Parser , ParserOutput , unableToConsumeToken } from './ParserInterface' ; export function nil < T > ( ) { return { parse ( token ) { return { candidates : [ { firstToken : token , nextToken : token , result : undefined } ] , successful : true , error : undefined } ; } } ; } export function str < T > ( toMatch ) { return { parse ( token ) { if ( token === undefined || token . text !== toMatch ) { return { successful : false , error : unableToConsumeToken ( token ) } ; } return { candidates : [ { firstToken : token , nextToken : token . next , result : token } ] , successful : true , error : undefined } ; } } ; } export function tok < T > ( toMatch ) { return { parse ( token ) { if ( token === undefined || token . kind !== toMatch ) { return { successful : false , error : unableToConsumeToken ( token ) } ; } return { candidates : [ { firstToken : token , nextToken : token . next , result : token } ] , successful : true , error : undefined } ; } } ; }