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
*
* 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)[...]
* 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.
*
*
*
*
*