import { ParseData } from '../parser/parser' ; import { ParserGeneralResult , ParserResult } from '../parser/parser.result' ; import { ParserError } from '../error' ; import { Packer } from '../packer' ; import { TreeBuilderBase } from '../tree/tree.base' ; import { BuilderInterface } from './builder.interface' ; import { GeneralError } from '../error.value' ; export class BuilderBase < T > implements BuilderInterface < T > { public constructor ( protected treeBuilder ) { } build ( data ) { return this . try ( ( ) => this . doBuild ( data ) ) ; } public parse ( data ) { return this . try ( ( ) => this . doParse ( data ) ) ; } public unparse ( data ) { return this . try ( ( ) => this . doUnparse ( data ) ) ; } protected handleError ( error ) { return Packer . makeError ( error ) ; } protected try < K extends ParserGeneralResult > ( tryFunc ) { try { return tryFunc ( ) ; } catch ( error ) { return < K > this . handleError ( error ) ; } } protected doBuild ( data ) { throw new ParserError ( GeneralError . methodNotImplemented ) ; } protected doParse ( data ) { throw new ParserError ( GeneralError . methodNotImplemented ) ; } protected doUnparse ( data ) { throw new ParserError ( GeneralError . methodNotImplemented ) ; } }