import GRule, { GElement } from "./grammar/GRule"; import IGRuleContext from "./grammar/IGRuleContext"; export default class GrammarCompiler { private static WS; static mergeTokens(existing?: Array, v1?: any, v2?: any): Array; /** * Recursive iteration across rules and elements to calculate next element tokens, ie tokens that cause the parser * to skip to a further rule. * *

* Which, recall, differers from possible next tokens is that it's only valid as the first character of a match * * ie (var1)?, X(var2) // upon hitting (var1), if we encounter an X, skip to X(var2) * * *

* * @param isOR * @param parentTokens * @param asChild * @param parentAllowNone * @param suffixTokens - used only when we have a `(var) construct */ static setUpNextTokens(r: GRule, isOR: boolean, stack: IGRuleContext, parentElementIndex?: number, parentTokens?: Array, asChild?: boolean, parentAllowNone?: boolean, parentAllowMany?: boolean, suffixTokens?: Array, parentIsOptional?: boolean, parentContextTokens?: Array): boolean; static requiresNextTokens(e: GElement): boolean; static getElementTokens(e: GElement, getRule: Function): Array; /** * Calculated the possible next token of a variable. * *

Used when an element's prefix has already been matched. Output is vector of tokens of characters that * indicate the start of a new rule.

* * examples: * * X(var1).[Y | Z] // <-- possible next tokens are [Y, Z, ' ' ]; * PAREN[(var1)] // <-- possible next token with be [')', ' '], as suffix of parent needs to propagate down. * , * *

Differs from nextElementToken in that * a) Used when matching (or attempting to match) a variable within an element (ie after a prefix token, if present has * been matched. Wheras nextElement token is used to detetermin which element to attempt to match by * looking at possible prefix tokens * * b) It therfore pays attention to whitespace, and it's own suffix and prefix tokens, wheras nextElementTtoken * only cares about tokes of possible next prefix (or content) token * *

* * @param parentTokens tokens from subsequent elements (as we iterate backwards) * ie [(var1) | Y]. Z?. Q?. <-- Z and Q will are parent tokens * * @param ixTokens parent prefix and suffix(ie *ix) tokens * ie PAREN[X[(var1) | Y?]*] <--- 'X' is repeated prefix token that needs to propagate down * <--- ')' also needs to propagate * * */ static setPossibleNextTokens(rule: GRule, parentTokens_pnt?: Array, ixTokens?: Array): Array; static isPrefixRepeat(e: GElement): boolean; /** * forward iteration * * Note that this is non-context dependant, so could readily be cached, including on parents if cloned. * * @param stopOnWS whether required ws should halt iteration if it hits ws (ie (var)~ :rule). * (True when calculaating possible next token as opposed to next element token). * * * * @return true if completed (and false if we've hit a token that we ca */ static getDeterminateTokensFromReferencedRule(rule: GRule, out: Array, stopOnWS?: boolean, getRule?: Function): boolean; /** * Context independant forward iteration over tokens. */ static calculateReferencedTokens_low(rule: GRule, out: Array, stopOnWS?: boolean, getRule?: Function): boolean; static cloneTokens(v: Array): Array; /** * recurse through rules and their elements inverting the order of the calculated tokens */ static invertTokenOrders(rule: GRule): void; /** * swaps the order of */ static reverseTokens(v: Array): void; }