import { IPResult, PElementResult, PRuleResult } from './PObjectMap'; import G from '@cafetextual/util/dist/src/type/G'; /** * Records an error that does not directly relate to the parser grammar. * *

This includes errors in object mapping, and errors added not non-grammar validation

*/ export default class PValidationError { static OBJECT_MAPPING:string = 'object'; static PARSER_VALIDATION:string = 'parse'; static DUPLICATE_TYPE:string = "dupliate type"; constructor(type:string, result:IPResult, message:string, localType:string = null ) { this.type = type; this.localType = localType; this.message = message; this.element = G.aas(result, PElementResult); this.rule = G.aas(result, PRuleResult); } // PValidationError /** * error type, used for filering and to distinguise errors object mapping, to external client errors */ type:string; localType:string; element:PElementResult; rule:PRuleResult; message:string; /** * convenience method to get the (start) line of the element */ get line():number { if (!this.element && !this.rule) { return -1; } return this.element ? this.element.startLineIndex : this.rule.startIndex; } get result():IPResult { return this.element ? this.element : this.rule; } /** * Convenience method to get index */ get index():number { return this.element ? this.element.startIndex : -1 } // index } // class