import ParserState from "./ParserState"; import IRuleState from "./IRuleState"; import { PRuleResult, PElementResult } from "../parser/PObjectMap"; import GRule, { GElement } from "../parser/grammar/GRule"; /** * Persists a stack element while parsing. *

* A note on line rule results: * a) A line rule result is seperately persistsed as a line rule result * b) However, the 0th element is appended to the parent rule. * * This reflects the way child rules are mapped to objects - a child rule is seen as an element appended to to the rule's elements. * */ export default class RuleState extends ParserState implements IRuleState { isElementState(): boolean; ruleInit(currentLineIndex: number): void; clone(fromCurrentElementState?: any, fromChildRuleState?: any, fromParentRuleState?: any, fromParentElementState?: any, stack?: Array): ParserState; parentElementState: any; rule: GRule; indent: string; asChild: boolean; /** * line1 is the startLineIndex after secondary grammar's preResults (is secondary grammar) - will differ from line0 only * for a parent line preceeded by ws/ comments / whatever the secondary grammar allows. * * * ie * line0, pos0 - is the absolute first line when rule begics * line1 - is the start after possible secondary grammar extracted for a top rule only * (remove this once top rule concept deprecated, line1 reverts to line0) * lineX, posX - confirmed consumed position. updated once an element has matched, or line has matched * * */ line1: number; lineRuleLine0: number; lineRuleLineX: number; lastElementMatchedWS: boolean; elementIndex: number; elementCollectionIndex: number; /** * Refers to the index in the result */ parentLineCollectionIndex: number; element: GElement; /** * Append a simple element */ appendPreResult(elementResult: PElementResult): void; _lastSecondaryResult: PRuleResult; getLastSecondaryResult(): PRuleResult; appendLineSecondaryResult(elementResult: PElementResult): void; /** * Wrap an element result from a secondary grammar in a rule result with appropriate indexing * * @param elementResult raw element result * @param secondaryResultIndex index of number of lines of secondary grammar matched (ie between primary grammar rules) */ private secondaryElementResultToRuleResult(elementResult, secondaryResultIndex); private unappendCompositeResult(ruleResult, elementResult); /** * Append an element result for an element /w multiplicity ie ":my-rule*" */ private appendCompositeResult(ruleResult, elementResult); isFirst(): boolean; unappendCompositeLineResult(lineRuleResult: PRuleResult): void; /** * Append a line result /w multiplicity ie -->* X :: [etc] * * Note * - we're assuming that the the form of the line rule result to have a single element, possibly with a child rule, * ie "-->* TOP_ELEMENT_TOKEN(vars) :: child rule here". * * - A single PRuleResult will be added to the parent line rule's lineChildren. * * - The individual line results will be in that PRuleResult's results. * */ appendCompositeLineResult(lineRuleResult: PRuleResult): void; unappendElementResult(elementResult: PElementResult): void; appendElementResult(elementResult: PElementResult): void; elementMatchIsZeroLength: boolean; incrementPending: boolean; consumeUntilEOF: boolean; /** * index of the line rule in the parent rule (this is the index of the rule in the grammar, not the results) * */ lineRuleIndex: number; lineIncrementNotPending(): boolean; currentLineIndent: string; currentLineRule: GRule; lineAllowMany: boolean; lineAllowNone: boolean; lineRuleResult: PRuleResult; compositeLineRuleResult: PRuleResult; foundOneLineRule: boolean; lineMatchFailed: boolean; /** * */ lineCompositeResults: PElementResult; parentToAddResultTo: PRuleResult; currentElementState: any; currentLineRuleState: RuleState; elementResult: PElementResult; compositeResult: PElementResult; posX: number; lineX: number; /** * when iterating on a line rule (as opposed to a a child element rule), parentRuleState is the parent */ parentRuleState: RuleState; asLineRule: boolean; setButDontAppendRuleError(errCode: number, state: ParserState, element: GElement, valid?: boolean, err?: string, childResult?: PRuleResult): void; /** * Append an error on a rule. Only call this if the rule errors out encountering an actual element */ appendError(errCode: number, state: RuleState, element: GElement, valid?: boolean, err?: string, childResult?: PRuleResult): void; ruleResult: PRuleResult; appendLine(lineRuleResult: PRuleResult): void; unappendLine(lineRuleResult: PRuleResult): void; unappendLine_low(lineRuleResult: PRuleResult, many: boolean): void; upappendLineChild(lineRuleResult: PRuleResult): void; appendLineChild(lineRuleResult: PRuleResult): void; private unappendResult(e); private addResult(e); /** * true if this rule has previously hit a cutpoint. * * Should be called only when an element has failed */ cutpointHit(): boolean; private getCutpointElement(); markAsCutpointInvalid(): void; incrementElement(): void; foundAtLeastOneValidElement(): boolean; incrementLineRule(): void; static createCompositeResult(element: GElement, state: RuleState): PElementResult; hasResult(): boolean; static createFromParentElement(p: any): RuleState; static create(p: any, rule: GRule, asChild: boolean, indent: string, asLineRule: boolean): RuleState; static createForLineRuleFromParent(parentState: RuleState, lineRule: GRule): RuleState; /** * Call this on the state of a child line rule, to exactly which PElementResult to add the PRuleResult to. * *

* * This is a bit awkward:
* If the parent is the line elenet ie from "rule: e1 e2 ..." then child result is simply appended to the results * However, if the parent is another line rule, then we want to append it the the results of the implicit child * this allows nesting of variables in child line rules of names child rules * ie rule0 X: e1 e2 ... e(n)
* --> (var1) :: ee1 ... (var2) // (var1)[...] is appended, effectively as e(n+1)
* --> (var3) :: eee1 // (var3) is a child of (var1)[...]
*

* *

*/ private getParentToAppendLineResultTo(state); eq(s: RuleState): boolean; hasLineRules(): boolean; currentLineIsOptional(): boolean; toTraceString(): string; /** * Trim is called on upon an incremental invalidation to remove all items after a particular line * * @param invalidatedLine The invalidate line, all results on this and subsequent lines are to be trimmed */ trim(invalidatedLine: number): void; private removeLineChild(removed); parent(): ParserState; showItem(): string; }