import { BigNumber } from 'bignumber.js'; export declare module XPathModels { interface HashtagConfig { /** * @param namespace - the namespace used in hashtag * @return truthy value */ isValidNamespace: (namespace: string) => boolean; /** * @param hashtagExpr string representation of hashtag ex. #form/question * @return the XPath or falsy value if no corresponding XPath found */ hashtagToXPath: (hashtagExpr: string) => string | null; /** * @param xpath - XPath object (can be any of the objects defined in xpm * @returns text representation of XPath in hashtag format (default implementation is to just return the XPath) or null if no mapping exist */ toHashtag: (xpath: IXPathExpression) => string | null; } let DefaultHashtagConfig: HashtagConfig; let CurrentHashtagConfig: HashtagConfig; let isDebugging: boolean; type ErrorHash = { text: string; token: string; line: number; loc: { first_line: number | undefined; last_line: number | undefined; first_column: number | undefined; last_column: number | undefined; range: [number, number] | undefined; } | undefined; expected: string | undefined; }; function debugLog(...args: string[]): void; function testAxisName(name: string): string; class ParseError { message: string; hash: ErrorHash; constructor(message: string, hash: ErrorHash); } function parseError(str: string, hash: ErrorHash): void; enum XPathInitialContextEnum { HASHTAG = "hashtag", ROOT = "abs", RELATIVE = "rel", EXPR = "expr" } enum XPathAxisEnum { CHILD = "child", DESCENDANT = "descendant", PARENT = "parent", ANCESTOR = "ancestor", FOLLOWING_SIBLING = "following-sibling", PRECEDING_SIBLING = "preceding-sibling", FOLLOWING = "following", PRECEDING = "preceding", ATTRIBUTE = "attribute", NAMESPACE = "namespace", SELF = "self", DESCENDANT_OR_SELF = "descendant-or-self", ANCESTOR_OR_SELF = "ancestor-or-self" } enum XPathTestEnum { NAME = "name", NAME_WILDCARD = "*", NAMESPACE_WILDCARD = ":*", TYPE_NODE = "node()", TYPE_TEXT = "text()", TYPE_COMMENT = "comment()", TYPE_FUNCTION = "function()", TYPE_PROCESSING_INSTRUCTION = "processing-instruction" } type XPathToken = ({ text: string; } & ({ expression: XPathStep; type: 'attribute.sigil'; } | { expression: IXPathExpression; type: 'bracket.left' | 'bracket.right'; } | { expression: XPathFuncExpr | XPathStep; type: 'function.name'; } | { expression: IXPathExpression; type: 'function.separator'; } | { expression: XPathStep | XPathHashtagExpression; type: 'namespace'; } | { expression: XPathNumNegExpr; type: 'negation'; } | { expression: XPathStep; type: 'node.name'; } | { expression: XPathNumericLiteral; type: 'numeric'; } | { expression: IXPathExpression; type: 'operator'; } | { expression: IXPathExpression; type: 'paren.left'; } | { expression: IXPathExpression; type: 'paren.right'; } | { expression: XPathHashtagExpression; type: 'hashtag'; } | { expression: XPathPathExpr | XPathStep; type: 'path'; } | { expression: XPathStringLiteral; type: 'string.delimiter'; } | { expression: XPathStringLiteral; type: 'string.value'; } | { expression: XPathVariableReference; type: 'variable.sigil'; } | { expression: XPathVariableReference; type: 'variable.value'; } | { expression: IXPathExpression; type: 'whitespace'; })); interface IXPathExpression { toHashtag(): string; toXPath(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } abstract class XPathExpressionBase implements IXPathExpression { parens: boolean; abstract toHashtag(): string; toXPath(): string; abstract toTokens(expandHashtags?: boolean): XPathToken[]; protected parentheses(args: IXPathExpression[], expandHashtags: boolean): XPathToken[]; protected brackets(args: IXPathExpression[], expandHashtags: boolean): XPathToken[]; } type XPathExpression = XPathBaseExpression | XPathOperation | XPathPathExpr | XPathFilterExpr | XPathHashtagExpression; type XPathBaseExpression = XPathFuncExpr | XPathVariableReference | XPathLiteral; class XPathVariableReference extends XPathExpressionBase { value: string; type: 'variable'; constructor(value: string); toString(): string; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } type XPathOperation = XPathBoolExpr | XPathEqExpr | XPathCmpExpr | XPathArithExpr | XPathUnionExpr | XPathNumNegExpr; abstract class XPathOperationBase extends XPathExpressionBase { type: 'operation'; operationType: T; abstract getChildren(): XPathExpression[]; toHashtag(): string; } abstract class XPathOperator extends XPathOperationBase { properties: { type: T; left: XPathExpression; right: XPathExpression; }; parens: boolean; constructor(properties: { type: T; left: XPathExpression; right: XPathExpression; }); private combine; getChildren(): XPathExpression[]; toHashtag(): string; toString(): string; toTokens(expandHashtags?: boolean): XPathToken[]; abstract expressionTypeEnumToXPathLiteral(type: T): string; } type XPathBoolOperator = 'or' | 'and'; type XPathEqOperator = '==' | '!='; type XPathCmpOperator = '<' | '<=' | '>' | '>='; type XPathArithOperator = '+' | '-' | '*' | '/' | '%'; class XPathBoolExpr extends XPathOperator { expressionTypeEnumToXPathLiteral(type: XPathBoolOperator): XPathBoolOperator; } class XPathEqExpr extends XPathOperator { expressionTypeEnumToXPathLiteral(type: XPathEqOperator): "!=" | "="; } class XPathCmpExpr extends XPathOperator { expressionTypeEnumToXPathLiteral(type: XPathCmpOperator): XPathCmpOperator; } class XPathArithExpr extends XPathOperator { expressionTypeEnumToXPathLiteral(type: XPathArithOperator): "+" | "-" | "*" | "mod" | "div"; } class XPathUnionExpr extends XPathOperator<'union'> { expressionTypeEnumToXPathLiteral(type: 'union'): string; } class XPathNumNegExpr extends XPathOperationBase<'num-neg'> { properties: { type: 'num-neg'; value: XPathExpression; }; constructor(properties: { type: 'num-neg'; value: XPathExpression; }); getChildren(): XPathExpression[]; toString(): string; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } /** * Functional call expression. */ class XPathFuncExpr extends XPathExpressionBase { properties: { id: string; args: XPathExpression[] | null; }; type: 'function'; args: XPathExpression[]; constructor(properties: { id: string; args: XPathExpression[] | null; }); private combine; getChildren(): XPathExpression[]; toString(): string; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } class XPathPathExpr extends XPathExpressionBase { private properties; type: 'path'; steps: XPathStep[]; constructor(properties: { initialContext: XPathInitialContextEnum; filter: XPathFilterExpr; steps: XPathStep[] | null; }); private combine; getChildren(): XPathStep[]; toString(): string; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; pathWithoutPredicates(): string; } class XPathStep extends XPathExpressionBase { properties: { axis: XPathAxisEnum; test: XPathTestEnum; name: string; namespace: string; literal: XPathExpression | null; predicates: XPathExpression[] | null; location: ParseLocation; }; type: 'path-step'; predicates: XPathExpression[]; constructor(properties: { axis: XPathAxisEnum; test: XPathTestEnum; name: string; namespace: string; literal: XPathExpression | null; predicates: XPathExpression[] | null; location: ParseLocation; }); private testTokens; private predicateXPath; private combine; getChildren(): XPathExpression[]; mainXPath(expandHashtags: boolean): string; mainTokens(expandHashtags: boolean): XPathToken[]; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; toString(): string; } class XPathFilterExpr extends XPathExpressionBase { private properties; type: 'filter'; predicates: XPathExpression[]; constructor(properties: { expr: XPathBaseExpression; predicates: XPathExpression[] | null; }); private combine; getChildren(): XPathExpression[]; toString(): string; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } class XPathHashtagExpression extends XPathExpressionBase { initialContext: XPathInitialContextEnum; namespace: string; steps: string[]; type: 'hashtag'; constructor(definition: { initialContext: XPathInitialContextEnum; namespace: string; steps: string[] | null; }); toString(): string; toTokens(expandHashtags?: boolean): XPathToken[]; toHashtag(): string; } type XPathLiteral = XPathStringLiteral | XPathNumericLiteral; class XPathStringLiteral extends XPathExpressionBase { location: ParseLocation; type: 'string'; value: string; private stringDelimiter; constructor(value: string, location: ParseLocation); private get valueDisplay(); toString(): string; toHashtag(): string; toXPath(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } class XPathNumericLiteral extends XPathExpressionBase { location: ParseLocation; type: 'numeric'; value: BigNumber; /** * @param value the string representation of the number as found in the XPATH */ constructor(value: string, location: ParseLocation); toString(): string; toHashtag(): string; toTokens(expandHashtags?: boolean): XPathToken[]; } class ParseLocation { /** * One-based character offset */ firstColumn: number; /** * One-based line number */ firstLine: number; /** * One-based last column, inclusive. */ lastColumn: number; /** * One-based last line number, inclusive. */ lastLine: number; constructor(yyloc: { first_column: number; first_line: number; last_column: number; last_line: number; }); } } //# sourceMappingURL=xpath-models.d.ts.map