import NSourceList from '@cafetextual/nlist/dist/src/nsource/NSourceList'; import SourceNListWrapper from '@cafetextual/nlist/dist/src/nsource/SourceNListWrapper'; import PObjectMap, { PRuleResult } from './../org/subalternproductions/seepResource/dsl/parser/PObjectMap'; import { ISourceList, SimpleTextContent } from '@cafetextual/util'; import SeepGrammar from '../org/subalternproductions/seepResource/dsl/parser/SeepGrammar'; import GRule from '../org/subalternproductions/seepResource/dsl/parser/grammar/GRule'; import { int } from '@cafetextual/nlist/dist/src/ntree/types'; import { fixNL } from './parse-util'; import BreakExpression from '../org/subalternproductions/seepResource/dsl/parsertooling/breakpoint/BreakExpression'; export default class ParseModel { constructor(content:SourceNListWrapper, result:PRuleResult, grammarOrRule:SeepGrammar | GRule, ruleName:string, breakExp:BreakExpression, enableDebug:boolean) { this.result = result; var grammar:SeepGrammar = grammarOrRule as SeepGrammar var rule:GRule = grammarOrRule as GRule this._status = ParseModel.OK; if (!rule && !grammar ){ // || !result <--- only need result for debugger this._status = "no gsaammar"; return; } // if (!result.data == grammar) { // Assert.fail(); // assuming that this is where grammar comes from otherwise our map is invalid // // } if (rule == null) { if ( !grammar.isValid()) { this._status = "grammar not valid"; return; } if ( (!ruleName || !grammar.getRule(ruleName))) { this._status = "no rule: " + ruleName; return; } } if (!(content.length() > 0)) { this._status = "no content" } this.ruleName = ruleName; if (rule) { this.rule = rule } else { this.rule = grammar.getRule(ruleName); } if (result) { this.map = result.map; } this.content = content; this.breakExp = breakExp; this.enableDebug = enableDebug } result:PRuleResult grammar:SeepGrammar; ruleName:string; map:PObjectMap content:SourceNListWrapper rule:GRule; breakExp:BreakExpression; enableDebug:boolean; public static OK:string = "ok"; _status:string = ParseModel.OK; replaceContent(content:SourceNListWrapper):void { this.content = content; } status():string { return this._status; } isValid():boolean { return this.status() == ParseModel.OK; } show():string { var out:string = "isValid: " + this.isValid() + "\n" if (!this.isValid()) { out += "status: " + this._status + "\n" } out += "rule: " if (this.rule) { out += this.rule.name + " rule valid: + " + this.rule.isValid() } else { out += " " } out += "\n ---- content ---- \n" if (this.content) { var count:int = 0 this.content.eachi(function(i:int, v:any):void { if (count < 5) { // <--- just show the first few lines out += v + "/n" } count++ }) } else { out += " "; } return out; } clone():ParseModel { var out:ParseModel = new ParseModel(this.content, this.result, this.grammar, this.ruleName, this.breakExp, this.enableDebug); return out; } /* newText(v:string):ParseModel { var newContent:SimpleTextContent = new SimpleTextContent; var txt:string = fixNL(v); // replace "\r" with "\n" newContent.init(txt); var out:ParseModel = new ParseModel(newContent, this.result, this.grammar, this.ruleName, this.breakExp, this.enableDebug); return out; } */ } // class