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.

* */ rule(r: GRule, asChild?: boolean, indent?: string, asLineRule?: boolean, consumeUntilEOF?: boolean): PRuleResult; private basicRuleInit(state); /** * Mechanism to add a secondary grammar - ie blank lines, or maybe comments. * * May, currently, match one element (per line). To do otherwise would require ansynchronous infrastructure in order to * support debug on element matching. * * * @return true if a line has been matched */ private matchSecondaryGrammar(state, isLine?); /** * Iterate on element of rule, or if complete, then invoke processing for success, fail or recurse */ private rule_iterate(state); private element_continue(state, breakpoint); private _and_element_continue(state); private element_fail(state); private _and_element_fail(state); /** * Decides whether, based on last element match, we need to continue iterating on the rule, or fail. */ private element_done(estate); private checkForTrailingText(state); /** * Called after elements in a rule are successfully, to * * - manage some intracies about whitespace matching requirements * - check for dangling content if we're finished the line * - invoke lineProcess (synchronously) if this is a line rule * (although lineProcess doesn't actually do that much any more) * - increment line if necessary (for line rule or element NL) * - redirect to line_iterate if the rule has child rules. * - otherwise, rule is successful * * Called after a line rule, but *before* child line rules are called. * */ private rule_process(state); private rule_success(state); private _element_child_rule_process(state); /** * process the parentRuleState of the rules state. * */ private doLineProcess(state); /** * rule done, whether it has matched or not. * * @param breakpoint may be RULE_FAIL, LINE_RULE_FAIL , PARENT_LINE_DONE * */ private rule_done(state, breakpoint); top_rule_done(state: RuleState): void; private line_parent_iterate(state); private _and_done(state); /** * Iterate on on the line rules of a given rule. * *

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; }