import SourceLocation from '@cafetextual/util/dist/src/source/SourceLocation'; import { TS_MANIFEST } from './../serialize/MetaGrammarManifest'; import { NSourceIncrement } from "@cafetextual/nlist/dist/src/nsource/NSourceIncremet"; import NListOp from "@cafetextual/nlist/dist/src/nsource/NListOp"; import { createInterface } from "readline"; import BreakExpression from "../parsertooling/breakpoint/BreakExpression"; import { ITypeManifest } from '@cafetextual/util'; import SimpleTypeManifest from '@cafetextual/util/dist/src/manifest/SimpleTypeManifest'; import ParseResult from '../testsuite/ParseResult'; import GrammarTest from '../testsuite/GrammarTest'; import GrammarTestSrc from '../testsuite/GrammarTestSrc'; import ParseConfig from './ParseConfig'; import { openSync } from 'fs'; import Breakpoint from '../parsertooling/breakpoint/Breakpoint'; /** * Parse Request, encapsulate request for parsing * * * * op : NSourceIncrement * - incremental operations (NListOp) wrapped in NSourceIncrement to manage versioning * - * * incremental: bookean * * debug? : { * enable:boolean * breakpoints:Array // <--- breakpoints reference a version * * } * * * ParseResponse { * srcVersion:string <--- the version of the source document * * incrementalResult:IncrementalParseResult { * incremental:boolean * complete:boolean * start:int * end:int * annotations:Array<(int, AAnotation )> * } * * result:ParseResult { * * } * * break?: { * stack:Array * * * } * * * * * } * * * * * * */ export type ParseAction = 'parse' | 'parse-incremental' | 'debug-start' | 'debug-cont' | 'debug-disable' | 'debug-step' | 'debug-step-line' /** * * Encapsulates an essentially RESTful api for parse requests * * composes /w NSourceIncrement - which wraps * * */ export default class ParseRequest { constructor(href:string = null, op: NSourceIncrement = null, action:ParseAction = null, config:ParseConfig = null) { this.href = href; this.op = op this.config = config this.action = action } docURI:string // <--- base document href:string // <--- sub-document ref // parent-id/type/child-id // or '#' for entire document //--- specify full src - simpler than op. doesn't bothr with src:Array // <-- raw document source, op versioning // -- request a specific gramamr for parse // Q: how does this interact with the document uri? grammarURI:string ruleName:string op: NSourceIncrement // <---- mechanism to alter text config:ParseConfig // <-- specification on how to parse, debug, incremental, return ast etc action:ParseAction = 'parse' // <--- default to simple parsing } // class // --- convenience methods to create s /** * * Send completely new source * */ export function createReplaceTestSource(gtest:GrammarTest, testSrc:GrammarTestSrc, src:Array):ParseRequest { var out = new ParseRequest(toHRef(gtest, testSrc)) out.src = src; return out; } /** * Create an incremental update action */ export function createIncremental(gtest:GrammarTest, testSrc:GrammarTestSrc, op:NSourceIncrement, config:ParseConfig = null ):ParseRequest { var out = new ParseRequest(toHRef(gtest, testSrc)) out.op = op out.config = config out.action = 'parse-incremental' return out } export function createDebug(gtest:GrammarTest, testSrc:GrammarTestSrc, src:Array | NSourceIncrement , breakpoints:Array ):ParseRequest { var out = new ParseRequest(toHRef(gtest, testSrc)) if (src instanceof Array) { out.src = src as Array } else { out.op = src as NSourceIncrement } var config = new ParseConfig() config.breakpoints = breakpoints config.debugEnable = true out.config = config out.action = 'debug-start' return out } export function toHRef(gtest:GrammarTest, src:GrammarTestSrc):string { return gtest.uid.toString + "/region-source" + src.uid.toString() }