import SimpleTypeManifest from '@cafetextual/util/dist/src/manifest/SimpleTypeManifest'; import { TS_MANIFEST } from './../serialize/MetaGrammarManifest'; import SourceLocation from "@cafetextual/util/dist/src/source/SourceLocation"; import { ITypeManifest, Assert } from '@cafetextual/util'; import BreakExpression from '../parsertooling/breakpoint/BreakExpression'; import AAnnotation from '../parser/annotator/annotations/AAnnotation'; import { int } from '@cafetextual/nlist/dist/src/ntree/types'; export default class ParseResult { ok:boolean // -- data?:any ast:any // <-- which may be annotated /w gramamr references // -- optional properties grammarURI:string // <-- in which case we need a references to the grammar ruleName:string // <--- src:Array // <-- optionally annotate the source // -- errMessage:string verboseErr:string errLocation:SourceLocation annotations:Array> // <-- errors not included in annotations for the moment static createSuccess(data:any, ast:any):ParseResult { var out:ParseResult = new ParseResult() out.ok = true out.data = data; out.ast = ast; return out; } static createErr(loc:SourceLocation , msg:string, verboseMsg:string):ParseResult { var out:ParseResult = new ParseResult() out.ok = false out.errLocation = loc out.errMessage = msg out.verboseErr = verboseMsg; return out; } static err(type:string, src:Array, info:string) { var out = new ParseResult() out.errLocation = ParseResult.toFistLineLoc(src) out.ok = false switch (type) { case 'no-rule': out.errMessage = "could not rsolve " + ( info ? ('rule: "' + info + '"') : "default rule" ) break; case 'invalid-rule': out.errMessage = 'invalid rule ' + ( + info ? ('rule: "' + info + '"' ) : "default rule" ) break case 'map-err': out.errMessage = "fatal during mapping \n" +info break; default: Assert.fail() } return out } private static toFistLineLoc(src:Array):SourceLocation { var len:int = src[0].length -1 return SourceLocation.create(0,0,0,len) } toSerializeable():any { var o:any = { __cls:'ParseResult', ok:this.ok, ast:this.ast, data:this.data, // TODO - error messages as annotations } if (this.errMessage) { var errLoc:SourceLocation = this.errLocation || new SourceLocation() o.annotations = [new AAnnotation(errLoc, this.errMessage)] } } }