import BaseSimpleParser from "../simpletemplate/BaseSimpleParser";
import IParserDebug from "../parsertooling/IParserDebug";
import GRule from "./grammar/GRule";
import RuleState from "../parsertooling/RuleState";
import { PRuleResult } from "./PObjectMap";
import ParserState from "../parsertooling/ParserState";
/**
* Parses text from a SeepGrammar
*
*
Suffers from a rather awkward refactoring from a simple recursive algorith to faciliate asynchronous * execution
** * Notes: * - form is a bit awkward, reflecting the process by which it was incrementally refactored from a simpler recursive mechanism to one * capable of asynchronousexecution. * * - may executed either through synchronous recursion, or asynchronously and non-recusively (where an injected IParseDebug controls and may decorate execution ) * * - entire stack is encapsulate in state objects, therefore uses neither closures not call stack state (as a typical recursive algorithm would) * * - by convention a method name with an underscore may be called asynchronously, and may contain other asynchronous points. * * Some debugging heuristics therefore: * o only an async method (ie rule_iterate, element_iterate) may call another async method * o no code may follow an async method ie must be immediately followed by a return. (this is because the method itself may have engaged an asynchronous break). * o conversely, any return statement in a method wih underscores must be preceeded by a method w underscores * *
*/ export default class SeepParser extends BaseSimpleParser { /** * @private */ static STRESS_TEST_DEBUGGER: IParserDebug; constructor(); /** * Here to prevent regressions breaking. */ autoObjectMap: boolean; debugger: IParserDebug; static registerStressTestParse: Function; /** * attempt to match a rule on a single line. * *Also a rule on a portion of a line is asChild is true.
called recursively after matching a line
* * @param state the state of the parent rule. */ private line_iterate(state); /** * TODO - see if this can't be gotten rid of. Most of the functionality is moved to element_process. * Called on the parent rule state of a child line rule * @return false if the the line hasn't been processed - ie it has failed but was optional. */ private lineProcess(state); private rule_fail(state); /** * Helper that maps values to a rule following an output */ private _objectMapper; /** * returns the union of two token vectors */ private tempMergeTokens(v1, v2); /** * Iterates on a single element */ private element_iterate(state); private elementMatchLeaf(state); private elementMatchPrefix(state); private element_child_rule_process(state); private elementSuccess(state); private ___deprecated___createElementResult(errCode, state, element, valid?, err?, childResult?); /** * Formalised consumption for a state. ie when an element - or even an indentation is matched, call this * to ensure that if the next element fails, it won't backtrack */ private advanceRuleConsmeToPosX(state); private advanceLineRuleX(state); /** * reset position when an entire line has failed (ie line rule fails) */ private resetRuleToLine0(state); /** * when an element has failed */ private resetElementToPos0(state); private resetRuleToPosX(state); private _state; private paused; private localPause; debug(state: ParserState, done: Function, breakpoint: number): boolean; private resumeLocal(); resume(state: ParserState): void; }