@adobe/acc-xtk-parser
Advanced tools
Comparing version 1.0.2 to 1.0.3
import { ATN, CharStream, DFA, Lexer, ParseTreeListener, ParseTreeVisitor, FailedPredicateException, Parser, ParserRuleContext, TerminalNode, TokenStream } from "antlr4"; | ||
export class XtkLexer extends Lexer { | ||
static readonly STRING = 1; | ||
static readonly INT = 2; | ||
static readonly BOOLEAN = 3; | ||
static readonly PAR_OPEN = 4; | ||
static readonly PAR_CLOSE = 5; | ||
static readonly DOUBLE = 6; | ||
static readonly DATE = 7; | ||
static readonly TIME = 8; | ||
static readonly DATETIME = 9; | ||
static readonly NOT_IN = 10; | ||
static readonly NOT = 11; | ||
static readonly IS_NULL = 12; | ||
static readonly IS_NOT_NULL = 13; | ||
static readonly IS = 14; | ||
static readonly IN = 15; | ||
static readonly NULL = 16; | ||
static readonly OR = 17; | ||
static readonly AND = 18; | ||
static readonly AND_NOT = 19; | ||
static readonly LIKE = 20; | ||
static readonly NOT_LIKE = 21; | ||
static readonly CONCAT = 22; | ||
static readonly ATTRIBUTE = 23; | ||
static readonly IDENTIFIER = 24; | ||
static readonly START_VARIABLE = 25; | ||
static readonly LT = 26; | ||
static readonly GT = 27; | ||
static readonly LE = 28; | ||
static readonly GE = 29; | ||
static readonly EQ = 30; | ||
static readonly EQ_2 = 31; | ||
static readonly NEQ = 32; | ||
static readonly NEQ_2 = 33; | ||
static readonly PLUS = 34; | ||
static readonly MINUS = 35; | ||
static readonly TIMES = 36; | ||
static readonly DIV = 37; | ||
static readonly AMP = 38; | ||
static readonly PIPE = 39; | ||
static readonly PERCENT = 40; | ||
static readonly EXCLAMATION = 41; | ||
static readonly COMMA = 42; | ||
static readonly COLON = 43; | ||
static readonly DOT = 44; | ||
static readonly WS = 45; | ||
static readonly BRAC_OPEN = 46; | ||
static readonly X_BRAC_OPEN = 47; | ||
static readonly X_BRAC_CLOSE = 48; | ||
static readonly X_INT = 49; | ||
static readonly X_STRING = 50; | ||
static readonly X_NCNAME = 51; | ||
static readonly X_SEP = 52; | ||
static readonly X_COLON = 53; | ||
static readonly X_PARENT = 54; | ||
static readonly X_CURRENT = 55; | ||
static readonly X_ATTR = 56; | ||
static readonly X_EQ = 57; | ||
static readonly TRUE = 1; | ||
static readonly FALSE = 2; | ||
static readonly STRING = 3; | ||
static readonly INT = 4; | ||
static readonly PAR_OPEN = 5; | ||
static readonly PAR_CLOSE = 6; | ||
static readonly DOUBLE = 7; | ||
static readonly DATE = 8; | ||
static readonly TIME = 9; | ||
static readonly DATETIME = 10; | ||
static readonly NOT_IN = 11; | ||
static readonly NOT = 12; | ||
static readonly IS_NULL = 13; | ||
static readonly IS_NOT_NULL = 14; | ||
static readonly IS = 15; | ||
static readonly IN = 16; | ||
static readonly NULL = 17; | ||
static readonly OR = 18; | ||
static readonly AND = 19; | ||
static readonly AND_NOT = 20; | ||
static readonly LIKE = 21; | ||
static readonly NOT_LIKE = 22; | ||
static readonly CONCAT = 23; | ||
static readonly ATTRIBUTE = 24; | ||
static readonly IDENTIFIER = 25; | ||
static readonly START_VARIABLE = 26; | ||
static readonly LT = 27; | ||
static readonly GT = 28; | ||
static readonly LE = 29; | ||
static readonly GE = 30; | ||
static readonly EQ = 31; | ||
static readonly EQ_2 = 32; | ||
static readonly NEQ = 33; | ||
static readonly NEQ_2 = 34; | ||
static readonly PLUS = 35; | ||
static readonly MINUS = 36; | ||
static readonly TIMES = 37; | ||
static readonly DIV = 38; | ||
static readonly AMP = 39; | ||
static readonly PIPE = 40; | ||
static readonly PERCENT = 41; | ||
static readonly EXCLAMATION = 42; | ||
static readonly COMMA = 43; | ||
static readonly COLON = 44; | ||
static readonly DOT = 45; | ||
static readonly WS = 46; | ||
static readonly BRAC_OPEN = 47; | ||
static readonly X_BRAC_OPEN = 48; | ||
static readonly X_BRAC_CLOSE = 49; | ||
static readonly X_INT = 50; | ||
static readonly X_STRING = 51; | ||
static readonly X_NCNAME = 52; | ||
static readonly X_SEP = 53; | ||
static readonly X_COLON = 54; | ||
static readonly X_PARENT = 55; | ||
static readonly X_CURRENT = 56; | ||
static readonly X_ATTR = 57; | ||
static readonly X_EQ = 58; | ||
static readonly EOF: number; | ||
@@ -105,12 +106,32 @@ static readonly XPATH = 1; | ||
/** | ||
* Enter a parse tree produced by `XtkParser.logicalOperator`. | ||
* Enter a parse tree produced by `XtkParser.orExpression`. | ||
* @param ctx the parse tree | ||
*/ | ||
enterLogicalOperator?: (ctx: LogicalOperatorContext) => void; | ||
enterOrExpression?: (ctx: OrExpressionContext) => void; | ||
/** | ||
* Exit a parse tree produced by `XtkParser.logicalOperator`. | ||
* Exit a parse tree produced by `XtkParser.orExpression`. | ||
* @param ctx the parse tree | ||
*/ | ||
exitLogicalOperator?: (ctx: LogicalOperatorContext) => void; | ||
exitOrExpression?: (ctx: OrExpressionContext) => void; | ||
/** | ||
* Enter a parse tree produced by `XtkParser.andExpression`. | ||
* @param ctx the parse tree | ||
*/ | ||
enterAndExpression?: (ctx: AndExpressionContext) => void; | ||
/** | ||
* Exit a parse tree produced by `XtkParser.andExpression`. | ||
* @param ctx the parse tree | ||
*/ | ||
exitAndExpression?: (ctx: AndExpressionContext) => void; | ||
/** | ||
* Enter a parse tree produced by `XtkParser.andOperator`. | ||
* @param ctx the parse tree | ||
*/ | ||
enterAndOperator?: (ctx: AndOperatorContext) => void; | ||
/** | ||
* Exit a parse tree produced by `XtkParser.andOperator`. | ||
* @param ctx the parse tree | ||
*/ | ||
exitAndOperator?: (ctx: AndOperatorContext) => void; | ||
/** | ||
* Enter a parse tree produced by `XtkParser.functionCall`. | ||
@@ -407,8 +428,20 @@ * @param ctx the parse tree | ||
/** | ||
* Visit a parse tree produced by `XtkParser.logicalOperator`. | ||
* Visit a parse tree produced by `XtkParser.orExpression`. | ||
* @param ctx the parse tree | ||
* @return the visitor result | ||
*/ | ||
visitLogicalOperator?: (ctx: LogicalOperatorContext) => Result; | ||
visitOrExpression?: (ctx: OrExpressionContext) => Result; | ||
/** | ||
* Visit a parse tree produced by `XtkParser.andExpression`. | ||
* @param ctx the parse tree | ||
* @return the visitor result | ||
*/ | ||
visitAndExpression?: (ctx: AndExpressionContext) => Result; | ||
/** | ||
* Visit a parse tree produced by `XtkParser.andOperator`. | ||
* @param ctx the parse tree | ||
* @return the visitor result | ||
*/ | ||
visitAndOperator?: (ctx: AndOperatorContext) => Result; | ||
/** | ||
* Visit a parse tree produced by `XtkParser.functionCall`. | ||
@@ -577,90 +610,93 @@ * @param ctx the parse tree | ||
export class XtkParser extends Parser { | ||
static readonly STRING = 1; | ||
static readonly INT = 2; | ||
static readonly BOOLEAN = 3; | ||
static readonly PAR_OPEN = 4; | ||
static readonly PAR_CLOSE = 5; | ||
static readonly DOUBLE = 6; | ||
static readonly DATE = 7; | ||
static readonly TIME = 8; | ||
static readonly DATETIME = 9; | ||
static readonly NOT_IN = 10; | ||
static readonly NOT = 11; | ||
static readonly IS_NULL = 12; | ||
static readonly IS_NOT_NULL = 13; | ||
static readonly IS = 14; | ||
static readonly IN = 15; | ||
static readonly NULL = 16; | ||
static readonly OR = 17; | ||
static readonly AND = 18; | ||
static readonly AND_NOT = 19; | ||
static readonly LIKE = 20; | ||
static readonly NOT_LIKE = 21; | ||
static readonly CONCAT = 22; | ||
static readonly ATTRIBUTE = 23; | ||
static readonly IDENTIFIER = 24; | ||
static readonly START_VARIABLE = 25; | ||
static readonly LT = 26; | ||
static readonly GT = 27; | ||
static readonly LE = 28; | ||
static readonly GE = 29; | ||
static readonly EQ = 30; | ||
static readonly EQ_2 = 31; | ||
static readonly NEQ = 32; | ||
static readonly NEQ_2 = 33; | ||
static readonly PLUS = 34; | ||
static readonly MINUS = 35; | ||
static readonly TIMES = 36; | ||
static readonly DIV = 37; | ||
static readonly AMP = 38; | ||
static readonly PIPE = 39; | ||
static readonly PERCENT = 40; | ||
static readonly EXCLAMATION = 41; | ||
static readonly COMMA = 42; | ||
static readonly COLON = 43; | ||
static readonly DOT = 44; | ||
static readonly WS = 45; | ||
static readonly BRAC_OPEN = 46; | ||
static readonly X_BRAC_OPEN = 47; | ||
static readonly X_BRAC_CLOSE = 48; | ||
static readonly X_INT = 49; | ||
static readonly X_STRING = 50; | ||
static readonly X_NCNAME = 51; | ||
static readonly X_SEP = 52; | ||
static readonly X_COLON = 53; | ||
static readonly X_PARENT = 54; | ||
static readonly X_CURRENT = 55; | ||
static readonly X_ATTR = 56; | ||
static readonly X_EQ = 57; | ||
static readonly TRUE = 1; | ||
static readonly FALSE = 2; | ||
static readonly STRING = 3; | ||
static readonly INT = 4; | ||
static readonly PAR_OPEN = 5; | ||
static readonly PAR_CLOSE = 6; | ||
static readonly DOUBLE = 7; | ||
static readonly DATE = 8; | ||
static readonly TIME = 9; | ||
static readonly DATETIME = 10; | ||
static readonly NOT_IN = 11; | ||
static readonly NOT = 12; | ||
static readonly IS_NULL = 13; | ||
static readonly IS_NOT_NULL = 14; | ||
static readonly IS = 15; | ||
static readonly IN = 16; | ||
static readonly NULL = 17; | ||
static readonly OR = 18; | ||
static readonly AND = 19; | ||
static readonly AND_NOT = 20; | ||
static readonly LIKE = 21; | ||
static readonly NOT_LIKE = 22; | ||
static readonly CONCAT = 23; | ||
static readonly ATTRIBUTE = 24; | ||
static readonly IDENTIFIER = 25; | ||
static readonly START_VARIABLE = 26; | ||
static readonly LT = 27; | ||
static readonly GT = 28; | ||
static readonly LE = 29; | ||
static readonly GE = 30; | ||
static readonly EQ = 31; | ||
static readonly EQ_2 = 32; | ||
static readonly NEQ = 33; | ||
static readonly NEQ_2 = 34; | ||
static readonly PLUS = 35; | ||
static readonly MINUS = 36; | ||
static readonly TIMES = 37; | ||
static readonly DIV = 38; | ||
static readonly AMP = 39; | ||
static readonly PIPE = 40; | ||
static readonly PERCENT = 41; | ||
static readonly EXCLAMATION = 42; | ||
static readonly COMMA = 43; | ||
static readonly COLON = 44; | ||
static readonly DOT = 45; | ||
static readonly WS = 46; | ||
static readonly BRAC_OPEN = 47; | ||
static readonly X_BRAC_OPEN = 48; | ||
static readonly X_BRAC_CLOSE = 49; | ||
static readonly X_INT = 50; | ||
static readonly X_STRING = 51; | ||
static readonly X_NCNAME = 52; | ||
static readonly X_SEP = 53; | ||
static readonly X_COLON = 54; | ||
static readonly X_PARENT = 55; | ||
static readonly X_CURRENT = 56; | ||
static readonly X_ATTR = 57; | ||
static readonly X_EQ = 58; | ||
static readonly EOF: number; | ||
static readonly RULE_unit = 0; | ||
static readonly RULE_expression = 1; | ||
static readonly RULE_logicalOperator = 2; | ||
static readonly RULE_functionCall = 3; | ||
static readonly RULE_addingExpression = 4; | ||
static readonly RULE_multiplyingExpression = 5; | ||
static readonly RULE_addingOperator = 6; | ||
static readonly RULE_comparisonOperator = 7; | ||
static readonly RULE_multiplyOperator = 8; | ||
static readonly RULE_relationalExpression = 9; | ||
static readonly RULE_unaryOperator = 10; | ||
static readonly RULE_unaryExpression = 11; | ||
static readonly RULE_likeOperator = 12; | ||
static readonly RULE_likeExpression = 13; | ||
static readonly RULE_includedInExpression = 14; | ||
static readonly RULE_xpath = 15; | ||
static readonly RULE_xpath_schema = 16; | ||
static readonly RULE_xpath_locationPath = 17; | ||
static readonly RULE_xpath_step = 18; | ||
static readonly RULE_xpath_qname = 19; | ||
static readonly RULE_xpath_predicate = 20; | ||
static readonly RULE_xpath_expr = 21; | ||
static readonly RULE_list = 22; | ||
static readonly RULE_parameters = 23; | ||
static readonly RULE_variablePath = 24; | ||
static readonly RULE_variableIdentifier = 25; | ||
static readonly RULE_variable = 26; | ||
static readonly RULE_castVariable = 27; | ||
static readonly RULE_literal = 28; | ||
static readonly RULE_computableAtom = 29; | ||
static readonly RULE_orExpression = 2; | ||
static readonly RULE_andExpression = 3; | ||
static readonly RULE_andOperator = 4; | ||
static readonly RULE_functionCall = 5; | ||
static readonly RULE_addingExpression = 6; | ||
static readonly RULE_multiplyingExpression = 7; | ||
static readonly RULE_addingOperator = 8; | ||
static readonly RULE_comparisonOperator = 9; | ||
static readonly RULE_multiplyOperator = 10; | ||
static readonly RULE_relationalExpression = 11; | ||
static readonly RULE_unaryOperator = 12; | ||
static readonly RULE_unaryExpression = 13; | ||
static readonly RULE_likeOperator = 14; | ||
static readonly RULE_likeExpression = 15; | ||
static readonly RULE_includedInExpression = 16; | ||
static readonly RULE_xpath = 17; | ||
static readonly RULE_xpath_schema = 18; | ||
static readonly RULE_xpath_locationPath = 19; | ||
static readonly RULE_xpath_step = 20; | ||
static readonly RULE_xpath_qname = 21; | ||
static readonly RULE_xpath_predicate = 22; | ||
static readonly RULE_xpath_expr = 23; | ||
static readonly RULE_list = 24; | ||
static readonly RULE_parameters = 25; | ||
static readonly RULE_variablePath = 26; | ||
static readonly RULE_variableIdentifier = 27; | ||
static readonly RULE_variable = 28; | ||
static readonly RULE_castVariable = 29; | ||
static readonly RULE_literal = 30; | ||
static readonly RULE_computableAtom = 31; | ||
static readonly literalNames: (string | null)[]; | ||
@@ -678,3 +714,5 @@ static readonly symbolicNames: (string | null)[]; | ||
expression(): ExpressionContext; | ||
logicalOperator(): LogicalOperatorContext; | ||
orExpression(): OrExpressionContext; | ||
andExpression(): AndExpressionContext; | ||
andOperator(): AndOperatorContext; | ||
functionCall(): FunctionCallContext; | ||
@@ -722,6 +760,27 @@ addingExpression(): AddingExpressionContext; | ||
constructor(parser?: XtkParser, parent?: ParserRuleContext, invokingState?: number); | ||
xpath(): XpathContext; | ||
literal(): LiteralContext; | ||
computableAtom(): ComputableAtomContext; | ||
EXCLAMATION(): TerminalNode; | ||
expression(): ExpressionContext; | ||
orExpression(): OrExpressionContext; | ||
addingExpression(): AddingExpressionContext; | ||
PAR_OPEN(): TerminalNode; | ||
PAR_CLOSE(): TerminalNode; | ||
get ruleIndex(): number; | ||
enterRule(listener: XtkParserListener): void; | ||
exitRule(listener: XtkParserListener): void; | ||
accept<Result>(visitor: XtkParserVisitor<Result>): Result; | ||
} | ||
declare class OrExpressionContext extends ParserRuleContext { | ||
constructor(parser?: XtkParser, parent?: ParserRuleContext, invokingState?: number); | ||
andExpression_list(): AndExpressionContext[]; | ||
andExpression(i: number): AndExpressionContext; | ||
OR_list(): TerminalNode[]; | ||
OR(i: number): TerminalNode; | ||
get ruleIndex(): number; | ||
enterRule(listener: XtkParserListener): void; | ||
exitRule(listener: XtkParserListener): void; | ||
accept<Result>(visitor: XtkParserVisitor<Result>): Result; | ||
} | ||
declare class AndExpressionContext extends ParserRuleContext { | ||
constructor(parser?: XtkParser, parent?: ParserRuleContext, invokingState?: number); | ||
computableAtom_list(): ComputableAtomContext[]; | ||
@@ -737,7 +796,10 @@ computableAtom(i: number): ComputableAtomContext; | ||
includedInExpression(i: number): IncludedInExpressionContext; | ||
logicalOperator_list(): LogicalOperatorContext[]; | ||
logicalOperator(i: number): LogicalOperatorContext; | ||
addingExpression(): AddingExpressionContext; | ||
PAR_OPEN(): TerminalNode; | ||
PAR_CLOSE(): TerminalNode; | ||
andOperator_list(): AndOperatorContext[]; | ||
andOperator(i: number): AndOperatorContext; | ||
PAR_OPEN_list(): TerminalNode[]; | ||
PAR_OPEN(i: number): TerminalNode; | ||
orExpression_list(): OrExpressionContext[]; | ||
orExpression(i: number): OrExpressionContext; | ||
PAR_CLOSE_list(): TerminalNode[]; | ||
PAR_CLOSE(i: number): TerminalNode; | ||
get ruleIndex(): number; | ||
@@ -748,5 +810,4 @@ enterRule(listener: XtkParserListener): void; | ||
} | ||
declare class LogicalOperatorContext extends ParserRuleContext { | ||
declare class AndOperatorContext extends ParserRuleContext { | ||
constructor(parser?: XtkParser, parent?: ParserRuleContext, invokingState?: number); | ||
OR(): TerminalNode; | ||
AND(): TerminalNode; | ||
@@ -1049,3 +1110,4 @@ AND_NOT(): TerminalNode; | ||
DOUBLE(): TerminalNode; | ||
BOOLEAN(): TerminalNode; | ||
TRUE(): TerminalNode; | ||
FALSE(): TerminalNode; | ||
DATE(): TerminalNode; | ||
@@ -1075,6 +1137,54 @@ TIME(): TerminalNode; | ||
/** | ||
* Exception raised in case of syntax error | ||
*/ | ||
export class SyntaxErrorException extends Error { | ||
line: number; | ||
column: number; | ||
constructor(l: number, c: number); | ||
} | ||
/** | ||
* Run the XTK parser on the provided expression and returns the parsing tree | ||
* @param expr The expression | ||
* @returns A parsing tree | ||
* @throws {SyntaxErrorException} Raised at the first error of syntax | ||
*/ | ||
export const runXtkParser: (expr: string) => UnitContext; | ||
type Literal = string | number; | ||
type ExecEvaluateXPath = (xpath: string) => Literal; | ||
type ExecEvaluateFunction = (name: string, ...args: any[]) => Literal; | ||
type ExecEvaluateVariable = (name: string) => Literal; | ||
type EvaluatorOptions = { | ||
xpathConverter?: ExecEvaluateXPath; | ||
functionConverter?: ExecEvaluateFunction; | ||
variableConverter?: ExecEvaluateVariable; | ||
}; | ||
/** | ||
* Evaluate the given expression | ||
* @param {string} expr The XTK expression | ||
* @param {EvaluatorOptions} options Evaluator options used to provide external values required for evaluation | ||
* @returns {string} A string | ||
*/ | ||
export function evaluate(expr: string, options?: EvaluatorOptions): Literal; | ||
/** | ||
* The type describing the object returned upon successful matching | ||
*/ | ||
type Matched = Record<string, Literal>; | ||
export class XtkPattern { | ||
context: UnitContext; | ||
constructor(expr: string); | ||
/** | ||
* Match the provided expression against a given pattern | ||
* | ||
* For example: | ||
* pattern: f($(p1))-1 = g($(p2)) | ||
* expr: f(@email)-1 = g(@address) | ||
* returns: {p1: '@email', p2: '@address'} | ||
* | ||
* expr: f(@email)-1 = h(@address) | ||
* returns: undefined | ||
* | ||
* @param {string} expr The expression to match | ||
* @returns {string[]} An array of strings | ||
*/ | ||
match(expr: string): Matched; | ||
} |
{ | ||
"name": "@adobe/acc-xtk-parser", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Adobe Campaign XTK expression parser", | ||
@@ -12,2 +12,3 @@ "source": "src/index.ts", | ||
"test": "jest --config test/jest.config.js", | ||
"test:debug": "node --inspect-brk ./node_modules/.bin/jest --config /Users/sewagner/Documents/DEV/UI/github/acc-xtk-parser/test/jest.config.js", | ||
"clean": "rm -rf lib && rm -rf src/generated", | ||
@@ -14,0 +15,0 @@ "build": "parcel build --no-source-maps --no-cache" |
# Adobe Campaign XTK expression parser | ||
This project is the implementation of a [grammar](./grammar/XtkParser.g4) for Adobe Campaign XTK expressions. It is based on antlr4 syntax. | ||
This project is the implementation of a [grammar](./grammar/XtkParser.g4) for Adobe Campaign XTK expressions. It is based on antlr4 syntax. The documentation of the API provided by this package can be found [here](./doc/doc.md). | ||
@@ -5,0 +5,0 @@ ## Installation |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
493674
22538