Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apex-parser

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apex-parser - npm Package Compare versions

Comparing version 2.15.0 to 2.16.0

lib/__tests__/SOSLParserTest.d.ts

141

lib/__tests__/ApexParserTest.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ApexLexer_1 = require("../ApexLexer");
const ApexParser_1 = require("../ApexParser");
const CaseInsensitiveInputStream_1 = require("../CaseInsensitiveInputStream");
const antlr4ts_1 = require("antlr4ts");
const ThrowingErrorListener_1 = require("../ThrowingErrorListener");
const SyntaxErrorCounter_1 = require("./SyntaxErrorCounter");
test('Boolean Literal', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", "true"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", "true");
const context = parser.literal();
expect(errorCounter.getNumErrors()).toEqual(0);
expect(context).toBeInstanceOf(ApexParser_1.LiteralContext);

@@ -18,6 +15,5 @@ expect(context.BooleanLiteral()).toBeTruthy();

test('Expression', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", "a * 5"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", "a * 5");
const context = parser.expression();
expect(errorCounter.getNumErrors()).toEqual(0);
expect(context).toBeInstanceOf(ApexParser_1.Arth1ExpressionContext);

@@ -28,17 +24,15 @@ const arthExpression = context;

test('Compilation Unit', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", "public class Hello {}"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", "public class Hello {}");
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (case insensitive)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", "Public CLASS Hello {}"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", "Public CLASS Hello {}");
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (bug test)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", `public class Hello {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", `public class Hello {
public testMethod void func() {

@@ -48,23 +42,19 @@ System.runAs(u) {

}
}`));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
}`);
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (inline SOQL)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", `public class Hello {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", `public class Hello {
public void func() {
List<Account> accounts = [Select Id from Accounts];
}
}`));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
}`);
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (throwing errors)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.cls", "public class Hello {"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.cls", "public class Hello {");
parser.removeErrorListeners();

@@ -81,57 +71,78 @@ parser.addErrorListener(new ThrowingErrorListener_1.ThrowingErrorListener());

test('Trigger Unit', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.trigger", "trigger test on Account (before update, after update) {}"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.trigger", "trigger test on Account (before update, after update) {}");
const context = parser.triggerUnit();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.TriggerUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('SOQL Query', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.soql", "Select Id from Account"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.soql", "Select Id from Account");
const context = parser.query();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('SOQL Query Using Field function', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.soql", "Select Fields(All) from Account"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.soql", "Select Fields(All) from Account");
const context = parser.query();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('SOSL Query', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.sosl", "[Find {something} RETURNING Account]"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.soslLiteral();
expect(context).toBeTruthy();
});
test('CurrencyLiteral', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.soql", "SELECT Id FROM Account WHERE Amount > USD100.01 AND Amount < USD200"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.soql", "SELECT Id FROM Account WHERE Amount > USD100.01 AND Amount < USD200");
const context = parser.query();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('IdentifiersThatCouldBeCurrencyLiterals', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.apex", "USD100.name = 'name';"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.apex", "USD100.name = 'name';");
const context = parser.statement();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('DateTimeLiteral', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.soql", "SELECT Name, (SELECT Id FROM Account WHERE createdDate > 2020-01-01T12:00:00Z) FROM Opportunity"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.soql", "SELECT Name, (SELECT Id FROM Account WHERE createdDate > 2020-01-01T12:00:00Z) FROM Opportunity");
const context = parser.query();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('testNegativeNumericLiteral', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream("test.soql", "SELECT Name FROM Opportunity WHERE Value = -100.123"));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.soql", "SELECT Name FROM Opportunity WHERE Value = -100.123");
const context = parser.query();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('testLastQuarterKeyword', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.soql", "SELECT Id FROM Account WHERE DueDate = LAST_QUARTER");
const context = parser.query();
expect(context).toBeInstanceOf(ApexParser_1.QueryContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('testSemiAllowedAsWhileBody', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.apex", "while (x++ < 10 && !(y-- < 0));");
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('testSemiAllowedAsForBody', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.apex", "for(x=0; x<10; x++);");
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('testSemiDisallowedAsGeneralStatement', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.apex", "if (x == 3); else { ; }");
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(1);
});
test('testWhenLiteralParens', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("test.apex", `
switch on (x) {
when 1 { return 1; }
when ((2)) { return 2; }
when (3), (4) { return 3; }
}`);
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
//# sourceMappingURL=ApexParserTest.js.map

@@ -25,3 +25,3 @@ "use strict";

let tokens = new antlr4ts_1.CommonTokenStream(lexer);
let parser = new ApexParser_1.ApexParser(tokens);
const parser = new ApexParser_1.ApexParser(tokens);
parser.removeErrorListeners();

@@ -28,0 +28,0 @@ parser.addErrorListener(new ThrowingErrorListener_1.ThrowingErrorListener());

@@ -114,129 +114,137 @@ import { ATN } from "antlr4ts/atn/ATN";

static readonly STANDARD = 108;
static readonly CALENDAR_MONTH = 109;
static readonly CALENDAR_QUARTER = 110;
static readonly CALENDAR_YEAR = 111;
static readonly DAY_IN_MONTH = 112;
static readonly DAY_IN_WEEK = 113;
static readonly DAY_IN_YEAR = 114;
static readonly DAY_ONLY = 115;
static readonly FISCAL_MONTH = 116;
static readonly FISCAL_QUARTER = 117;
static readonly FISCAL_YEAR = 118;
static readonly HOUR_IN_DAY = 119;
static readonly WEEK_IN_MONTH = 120;
static readonly WEEK_IN_YEAR = 121;
static readonly CONVERT_TIMEZONE = 122;
static readonly YESTERDAY = 123;
static readonly TODAY = 124;
static readonly TOMORROW = 125;
static readonly LAST_WEEK = 126;
static readonly THIS_WEEK = 127;
static readonly NEXT_WEEK = 128;
static readonly LAST_MONTH = 129;
static readonly THIS_MONTH = 130;
static readonly NEXT_MONTH = 131;
static readonly LAST_90_DAYS = 132;
static readonly NEXT_90_DAYS = 133;
static readonly LAST_N_DAYS_N = 134;
static readonly NEXT_N_DAYS_N = 135;
static readonly NEXT_N_WEEKS_N = 136;
static readonly LAST_N_WEEKS_N = 137;
static readonly NEXT_N_MONTHS_N = 138;
static readonly LAST_N_MONTHS_N = 139;
static readonly THIS_QUARTER = 140;
static readonly LAST_QUARTER = 141;
static readonly NEXT_QUARTER = 142;
static readonly NEXT_N_QUARTERS_N = 143;
static readonly LAST_N_QUARTERS_N = 144;
static readonly THIS_YEAR = 145;
static readonly LAST_YEAR = 146;
static readonly NEXT_YEAR = 147;
static readonly NEXT_N_YEARS_N = 148;
static readonly LAST_N_YEARS_N = 149;
static readonly THIS_FISCAL_QUARTER = 150;
static readonly LAST_FISCAL_QUARTER = 151;
static readonly NEXT_FISCAL_QUARTER = 152;
static readonly NEXT_N_FISCAL_QUARTERS_N = 153;
static readonly LAST_N_FISCAL_QUARTERS_N = 154;
static readonly THIS_FISCAL_YEAR = 155;
static readonly LAST_FISCAL_YEAR = 156;
static readonly NEXT_FISCAL_YEAR = 157;
static readonly NEXT_N_FISCAL_YEARS_N = 158;
static readonly LAST_N_FISCAL_YEARS_N = 159;
static readonly DateLiteral = 160;
static readonly DateTimeLiteral = 161;
static readonly IntegralCurrencyLiteral = 162;
static readonly FIND = 163;
static readonly EMAIL = 164;
static readonly NAME = 165;
static readonly PHONE = 166;
static readonly SIDEBAR = 167;
static readonly FIELDS = 168;
static readonly METADATA = 169;
static readonly PRICEBOOKID = 170;
static readonly NETWORK = 171;
static readonly SNIPPET = 172;
static readonly TARGET_LENGTH = 173;
static readonly DIVISION = 174;
static readonly RETURNING = 175;
static readonly LISTVIEW = 176;
static readonly FindLiteral = 177;
static readonly IntegerLiteral = 178;
static readonly LongLiteral = 179;
static readonly NumberLiteral = 180;
static readonly BooleanLiteral = 181;
static readonly StringLiteral = 182;
static readonly NullLiteral = 183;
static readonly LPAREN = 184;
static readonly RPAREN = 185;
static readonly LBRACE = 186;
static readonly RBRACE = 187;
static readonly LBRACK = 188;
static readonly RBRACK = 189;
static readonly SEMI = 190;
static readonly COMMA = 191;
static readonly DOT = 192;
static readonly ASSIGN = 193;
static readonly GT = 194;
static readonly LT = 195;
static readonly BANG = 196;
static readonly TILDE = 197;
static readonly QUESTIONDOT = 198;
static readonly QUESTION = 199;
static readonly COLON = 200;
static readonly EQUAL = 201;
static readonly TRIPLEEQUAL = 202;
static readonly NOTEQUAL = 203;
static readonly LESSANDGREATER = 204;
static readonly TRIPLENOTEQUAL = 205;
static readonly AND = 206;
static readonly OR = 207;
static readonly INC = 208;
static readonly DEC = 209;
static readonly ADD = 210;
static readonly SUB = 211;
static readonly MUL = 212;
static readonly DIV = 213;
static readonly BITAND = 214;
static readonly BITOR = 215;
static readonly CARET = 216;
static readonly MOD = 217;
static readonly MAPTO = 218;
static readonly ADD_ASSIGN = 219;
static readonly SUB_ASSIGN = 220;
static readonly MUL_ASSIGN = 221;
static readonly DIV_ASSIGN = 222;
static readonly AND_ASSIGN = 223;
static readonly OR_ASSIGN = 224;
static readonly XOR_ASSIGN = 225;
static readonly MOD_ASSIGN = 226;
static readonly LSHIFT_ASSIGN = 227;
static readonly RSHIFT_ASSIGN = 228;
static readonly URSHIFT_ASSIGN = 229;
static readonly ATSIGN = 230;
static readonly Identifier = 231;
static readonly WS = 232;
static readonly DOC_COMMENT = 233;
static readonly COMMENT = 234;
static readonly LINE_COMMENT = 235;
static readonly DISTANCE = 109;
static readonly GEOLOCATION = 110;
static readonly CALENDAR_MONTH = 111;
static readonly CALENDAR_QUARTER = 112;
static readonly CALENDAR_YEAR = 113;
static readonly DAY_IN_MONTH = 114;
static readonly DAY_IN_WEEK = 115;
static readonly DAY_IN_YEAR = 116;
static readonly DAY_ONLY = 117;
static readonly FISCAL_MONTH = 118;
static readonly FISCAL_QUARTER = 119;
static readonly FISCAL_YEAR = 120;
static readonly HOUR_IN_DAY = 121;
static readonly WEEK_IN_MONTH = 122;
static readonly WEEK_IN_YEAR = 123;
static readonly CONVERT_TIMEZONE = 124;
static readonly YESTERDAY = 125;
static readonly TODAY = 126;
static readonly TOMORROW = 127;
static readonly LAST_WEEK = 128;
static readonly THIS_WEEK = 129;
static readonly NEXT_WEEK = 130;
static readonly LAST_MONTH = 131;
static readonly THIS_MONTH = 132;
static readonly NEXT_MONTH = 133;
static readonly LAST_90_DAYS = 134;
static readonly NEXT_90_DAYS = 135;
static readonly LAST_N_DAYS_N = 136;
static readonly NEXT_N_DAYS_N = 137;
static readonly N_DAYS_AGO_N = 138;
static readonly NEXT_N_WEEKS_N = 139;
static readonly LAST_N_WEEKS_N = 140;
static readonly N_WEEKS_AGO_N = 141;
static readonly NEXT_N_MONTHS_N = 142;
static readonly LAST_N_MONTHS_N = 143;
static readonly N_MONTHS_AGO_N = 144;
static readonly THIS_QUARTER = 145;
static readonly LAST_QUARTER = 146;
static readonly NEXT_QUARTER = 147;
static readonly NEXT_N_QUARTERS_N = 148;
static readonly LAST_N_QUARTERS_N = 149;
static readonly N_QUARTERS_AGO_N = 150;
static readonly THIS_YEAR = 151;
static readonly LAST_YEAR = 152;
static readonly NEXT_YEAR = 153;
static readonly NEXT_N_YEARS_N = 154;
static readonly LAST_N_YEARS_N = 155;
static readonly N_YEARS_AGO_N = 156;
static readonly THIS_FISCAL_QUARTER = 157;
static readonly LAST_FISCAL_QUARTER = 158;
static readonly NEXT_FISCAL_QUARTER = 159;
static readonly NEXT_N_FISCAL_QUARTERS_N = 160;
static readonly LAST_N_FISCAL_QUARTERS_N = 161;
static readonly N_FISCAL_QUARTERS_AGO_N = 162;
static readonly THIS_FISCAL_YEAR = 163;
static readonly LAST_FISCAL_YEAR = 164;
static readonly NEXT_FISCAL_YEAR = 165;
static readonly NEXT_N_FISCAL_YEARS_N = 166;
static readonly LAST_N_FISCAL_YEARS_N = 167;
static readonly N_FISCAL_YEARS_AGO_N = 168;
static readonly DateLiteral = 169;
static readonly DateTimeLiteral = 170;
static readonly IntegralCurrencyLiteral = 171;
static readonly FIND = 172;
static readonly EMAIL = 173;
static readonly NAME = 174;
static readonly PHONE = 175;
static readonly SIDEBAR = 176;
static readonly FIELDS = 177;
static readonly METADATA = 178;
static readonly PRICEBOOKID = 179;
static readonly NETWORK = 180;
static readonly SNIPPET = 181;
static readonly TARGET_LENGTH = 182;
static readonly DIVISION = 183;
static readonly RETURNING = 184;
static readonly LISTVIEW = 185;
static readonly FindLiteral = 186;
static readonly FindLiteralAlt = 187;
static readonly IntegerLiteral = 188;
static readonly LongLiteral = 189;
static readonly NumberLiteral = 190;
static readonly BooleanLiteral = 191;
static readonly StringLiteral = 192;
static readonly NullLiteral = 193;
static readonly LPAREN = 194;
static readonly RPAREN = 195;
static readonly LBRACE = 196;
static readonly RBRACE = 197;
static readonly LBRACK = 198;
static readonly RBRACK = 199;
static readonly SEMI = 200;
static readonly COMMA = 201;
static readonly DOT = 202;
static readonly ASSIGN = 203;
static readonly GT = 204;
static readonly LT = 205;
static readonly BANG = 206;
static readonly TILDE = 207;
static readonly QUESTIONDOT = 208;
static readonly QUESTION = 209;
static readonly COLON = 210;
static readonly EQUAL = 211;
static readonly TRIPLEEQUAL = 212;
static readonly NOTEQUAL = 213;
static readonly LESSANDGREATER = 214;
static readonly TRIPLENOTEQUAL = 215;
static readonly AND = 216;
static readonly OR = 217;
static readonly INC = 218;
static readonly DEC = 219;
static readonly ADD = 220;
static readonly SUB = 221;
static readonly MUL = 222;
static readonly DIV = 223;
static readonly BITAND = 224;
static readonly BITOR = 225;
static readonly CARET = 226;
static readonly MAPTO = 227;
static readonly ADD_ASSIGN = 228;
static readonly SUB_ASSIGN = 229;
static readonly MUL_ASSIGN = 230;
static readonly DIV_ASSIGN = 231;
static readonly AND_ASSIGN = 232;
static readonly OR_ASSIGN = 233;
static readonly XOR_ASSIGN = 234;
static readonly LSHIFT_ASSIGN = 235;
static readonly RSHIFT_ASSIGN = 236;
static readonly URSHIFT_ASSIGN = 237;
static readonly ATSIGN = 238;
static readonly Identifier = 239;
static readonly WS = 240;
static readonly DOC_COMMENT = 241;
static readonly COMMENT = 242;
static readonly LINE_COMMENT = 243;
static readonly WHITESPACE_CHANNEL = 2;

@@ -243,0 +251,0 @@ static readonly COMMENT_CHANNEL = 3;

@@ -6,2 +6,3 @@ import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";

import { TypeRefPrimaryContext } from "./ApexParser";
import { VoidPrimaryContext } from "./ApexParser";
import { IdPrimaryContext } from "./ApexParser";

@@ -131,2 +132,4 @@ import { SoqlPrimaryContext } from "./ApexParser";

import { DateFieldNameContext } from "./ApexParser";
import { LocationValueContext } from "./ApexParser";
import { CoordinateValueContext } from "./ApexParser";
import { TypeOfContext } from "./ApexParser";

@@ -163,2 +166,3 @@ import { WhenClauseContext } from "./ApexParser";

import { SoslLiteralContext } from "./ApexParser";
import { SoslLiteralAltContext } from "./ApexParser";
import { SoslClausesContext } from "./ApexParser";

@@ -212,2 +216,9 @@ import { SearchGroupContext } from "./ApexParser";

/**
* Visit a parse tree produced by the `voidPrimary`
* labeled alternative in `ApexParser.primary`.
* @param ctx the parse tree
* @return the visitor result
*/
visitVoidPrimary?: (ctx: VoidPrimaryContext) => Result;
/**
* Visit a parse tree produced by the `idPrimary`

@@ -983,2 +994,14 @@ * labeled alternative in `ApexParser.primary`.

/**
* Visit a parse tree produced by `ApexParser.locationValue`.
* @param ctx the parse tree
* @return the visitor result
*/
visitLocationValue?: (ctx: LocationValueContext) => Result;
/**
* Visit a parse tree produced by `ApexParser.coordinateValue`.
* @param ctx the parse tree
* @return the visitor result
*/
visitCoordinateValue?: (ctx: CoordinateValueContext) => Result;
/**
* Visit a parse tree produced by `ApexParser.typeOf`.

@@ -1170,2 +1193,8 @@ * @param ctx the parse tree

/**
* Visit a parse tree produced by `ApexParser.soslLiteralAlt`.
* @param ctx the parse tree
* @return the visitor result
*/
visitSoslLiteralAlt?: (ctx: SoslLiteralAltContext) => Result;
/**
* Visit a parse tree produced by `ApexParser.soslClauses`.

@@ -1172,0 +1201,0 @@ * @param ctx the parse tree

{
"name": "apex-parser",
"version": "2.15.0",
"version": "2.16.0",
"author": "Kevin Jones <nawforce@gmail.com> (https://github.com/nawforce)",

@@ -10,8 +10,10 @@ "bugs": "https://github.com/nawforce/apex-parser/issues",

"scripts": {
"build": "npm run antlr4ts && cp ../README.md . && tsc",
"antlr4ts": "npm run antlr-build && npm run antlr-patch",
"antlr-build": "cd antlr && antlr4ts -visitor -o ../src ApexLexer.g4 ApexParser.g4",
"antlr-patch": "node patch",
"build": "npm run antlr4ts && tsc",
"check": "node -e 'require(\"./lib/index.js\").check()'",
"test": "jest --config jestconfig.json lib",
"antlr4ts": "npm run antlr-build && npm run antlr-patch ",
"antlr-build": "(cd antlr; antlr4ts -visitor -o ../src ApexLexer.g4 ApexParser.g4)",
"antlr-patch": "sed -i '' -e 's/public void clearCache() {.*}//g' src/ApexParser.ts && sed -i '' -e 's/public void clearCache() {.*}//g' src/ApexLexer.ts",
"check": "node -e require(\"./lib/index.js\").check()'"
"test-samples": "jest --config sys.jestconfig.json lib",
"test-snapshot": "npm run test-samples -- --updateSnapshot"
},

@@ -34,2 +36,3 @@ "files": [

"jest": "^27.0.6",
"shx": "^0.3.4",
"typescript": "^4.3.5"

@@ -36,0 +39,0 @@ },

@@ -1,13 +0,13 @@

apex-parser
===========
# apex-parser
Parser for Salesforce Apex (including Triggers & inline SOQL/SOQL). This is based on an [ANTLR4](https://www.antlr.org/) grammar, see antlr/ApexParser.g4.
Parser for Salesforce Apex (including Triggers & inline SOQL/SOQL). This is based on an [ANTLR4](https://www.antlr.org/) grammar, see antlr/ApexParser.g4.
There are two builds of the parser available, a NPM module for use with Node and a Maven package for use on JVMs.
These builds just contain the Parser & Lexer and provides no further support for analysing the generated parse trees beyond what is provided by ANTLR4.
These builds just contain the Parser & Lexer and provides no further support for analysing the generated parse trees beyond what is provided by ANTLR4.
As Apex & SOQL/SOQL are case-insenstive languages you need to use the provided CaseInsensitiveInputStream for the parser to function correctly. When parsing Apex, inline SOQL/SOSL is automtaically parsed, but you can also parse SOQL/SOQL directly. You can find some minimal examples in the test classes.
As Apex & SOQL/SOQL are case-insensitive languages you need to use the provided CaseInsensitiveInputStream for the parser to function correctly. When parsing Apex, inline SOQL/SOSL is automatically parsed, but you can also parse SOQL/SOQL directly. You can find some minimal examples in the test classes.
### Example
## Example
To parse a class file (NPM version):

@@ -23,13 +23,23 @@

### antlr4ts versions
## Unicode handling
The npm module uses antlr4ts 0.5.0-alpha.4, this was updated from 0.5.0-alpha.3 in the 2.9.1 version. You should make
sure that if you are using a matching verions of this dependency if you use it directly. To avoid issues you can
import 'CommonTokenStream' & 'ParseTreeWalker' from 'apex-parser' instead of from antlr4ts.
Prior to 2.12.0 the use of ANTLRInputStream for reading data in CaseInsensitiveStream would result character positions being given for UTF-16. The switch to CharStream input in 2.12.0 for JVM and 2.14.0 for node results in character positions reflecting Unicode code points.
## antlr4ts versions
The npm module uses antlr4ts 0.5.0-alpha.4, this was updated from 0.5.0-alpha.3 in the 2.9.1 version. You should make sure that if you are using a matching versions of this dependency if you use it directly. To avoid issues you can import 'CommonTokenStream' & 'ParseTreeWalker' from 'apex-parser' instead of from antlr4ts.
import { CommonTokenStream} from "apex-parser";
import { ParseTreeWalker } from "apex-parser";
### Packages
## SOSL FIND quoting
SOSL FIND uses ' as a quoting character when embedded in Apex, in the API braces are used:
Find {something} RETURNING Account
To parse the API format there is an alternative parser rule, soslLiteralAlt, that you can use instead of soslLiteral. See SOSLParserTest for some examples of how these differ.
## Packages
Maven

@@ -40,3 +50,3 @@

<artifactId>apex-parser</artifactId>
<version>2.15.0</version>
<version>2.16.0</version>
</dependency>

@@ -46,14 +56,18 @@

"apex-parser": "^2.15.0"
"apex-parser": "^2.16.0"
### Building
## Building
To build both distributions:
npm ci
npm run build
### History
## History
2.16.0 - Fixes for empty for & while loops, soql date formulas & distance functions, additional parenthesis on when clauses, SOSL find quoting, modulus support (removed), apexdoc newline handling - thanks to Aaron Hurst for most of these ;-)
2.15.0 - Revert 2.14.0 changes.
2.14.0 - Change npm api to replace ANTLRInputStream with CharStream, for Unicode char positions
2.13.0 - Fixes for negative numerics & Currency literals in SOQL
2.12.0 - Replace deprecated ANTLRINputStream, DateTime & Currency literals fixes (contrib Aaron Hurst)
2.12.0 - Replace deprecated ANTLRInputStream, DateTime & Currency literals fixes (contrib Aaron Hurst)
2.11.0 - Fix for SOQL UPDATE VIEWSTAT/TRACKING & removal of class type arguments

@@ -77,4 +91,4 @@ 2.10.0 - Allow type arguments on Classes (non-standard!)

### Source & Licenses
## Source & Licenses
All the source code included uses a 3-clause BSD license. The only third-party component included is the Apex Antlr4 grammar originally from [Tooling-force.com](https://github.com/neowit/tooling-force.com), although this version used is now markedly different from the original.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc