import { Token } from '../Lexer' ; import { alt } from './AlternativeParser' ; import { Parser , ParserOutput } from './ParserInterface' ; import { nil } from './TokenParser' ; export function opt < TKind , TResult > ( p ) { return alt ( p , nil < TKind > ( ) ) ; } export function opt_sc < TKind , TResult > ( p ) { return { parse ( token ) { const output = p . parse ( token ) ; if ( output . successful ) { return output ; } else { return { candidates : [ { firstToken : token , nextToken : token , result : undefined } ] , successful : true , error : output . error } ; } } } ; }