Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

[pull] master from nawforce:master #21

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
23d80ac
Merge changes for adt parser
nawforce Nov 14, 2022
b51a35b
Add basic build actions
nawforce Nov 14, 2022
dd4bcfe
Fix sed handling in portable way
nawforce Nov 14, 2022
5661ff7
Merge pull request #29 from nawforce/28-update-for-internal-changes
nawforce Nov 14, 2022
e392bbd
Match other ApexDoc cases.
aaronhurst-google Nov 19, 2022
ae9adf2
Merge pull request #31 from aaronhurst-google/master
nawforce Nov 20, 2022
27e269e
Update build actions
nawforce Nov 20, 2022
9db59df
Use copyfiles to remove cp use in run script
nawforce Nov 20, 2022
94323da
Fix copyfiles
nawforce Nov 20, 2022
d35dd94
Add missing npm ci
nawforce Nov 20, 2022
071fecb
Remove more sh from npm scripts
nawforce Nov 20, 2022
36f184a
Add npm ci to build instructions
nawforce Nov 20, 2022
2aa5955
Merge pull request #33 from nawforce/32-windows-build-action
nawforce Nov 20, 2022
b55e711
Merge SOQL & void.class fixes
nawforce Nov 26, 2022
342c46b
Up rev to 2.16.0
nawforce Nov 26, 2022
a5adae8
Merge pull request #35 from nawforce/34-publish-latest-maven-artifact…
nawforce Nov 26, 2022
80b958b
Bump json5 from 2.2.1 to 2.2.3 in /npm
dependabot[bot] Jan 8, 2023
84f603d
Update grammar to include access-level syntax in SOQL and DML.
aaronhurst-google Jan 16, 2023
e0368e4
Merge pull request #37 from aaronhurst-google/new-with-clauses
nawforce Jan 23, 2023
75d375d
Add user/system mode tests for JS
nawforce Jan 23, 2023
8a7b179
Merge pull request #38 from nawforce/js-mode-test
nawforce Jan 23, 2023
0d37f6b
Up rev 2.17.0
nawforce Feb 5, 2023
2897ff2
Add TYPEOF to Subquery
cwarden Nov 29, 2023
7614e8f
Merge pull request #36 from nawforce/dependabot/npm_and_yarn/npm/json…
nawforce Dec 22, 2023
78557d6
Bump tough-cookie from 4.0.0 to 4.1.3 in /npm
dependabot[bot] Dec 22, 2023
c3b235e
Bump @babel/traverse from 7.17.9 to 7.23.6 in /npm
dependabot[bot] Dec 22, 2023
a325617
Merge pull request #42 from nawforce/dependabot/npm_and_yarn/npm/toug…
nawforce Dec 22, 2023
b499122
Merge pull request #43 from nawforce/dependabot/npm_and_yarn/npm/babe…
nawforce Dec 22, 2023
da2e247
Merge pull request #39 from cwarden/subselect-typeof
nawforce Dec 22, 2023
021dcc5
Add triggerUnit2 for trigger parsing fixes
nawforce Dec 23, 2023
160f3ff
Merge pull request #44 from nawforce/41-member-declarations-missing-f…
nawforce Dec 24, 2023
6f18ab0
Update README.md - Add archive note
adangel Mar 1, 2024
3db92d8
Merge pull request #47 from adangel/patch-1
nawforce Mar 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/Build-Base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linux Java8/Node14 Build

on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node 14
uses: actions/setup-node@v3
with:
node-version: 14

- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
cache: 'maven'

- name: Build & Test
run: |
npm ci
npm run build
33 changes: 33 additions & 0 deletions .github/workflows/Build-Next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linux Java11/Node18 Build

on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: 18

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
cache: 'maven'

- name: Build & Test
run: |
npm ci
npm run build
33 changes: 33 additions & 0 deletions .github/workflows/Build-Windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Windows Build

on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]
workflow_dispatch:

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node 14
uses: actions/setup-node@v3
with:
node-version: 14

- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
cache: 'maven'

- name: Build & Test
run: |
npm ci
npm run build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
48 changes: 30 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
apex-parser
===========
> This repository has been **archived**. The new home for the Apex Parser is https://github.com/apex-dev-tools/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.
-----

# 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.

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):

let lexer = new ApexLexer(new CaseInsensitiveInputStream("public class Hello {}"))
Expand All @@ -20,46 +24,54 @@ To parse a class file (NPM version):

The 'context' is a CompilationUnitContext object which is the root of the parsed representation of the class. You can access the parse tree via functions on it.

### antlr4ts versions
## Unicode handling

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.

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.
## 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";

### SOSL FIND quoting
## 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
## Packages

Maven

<dependency>
<groupId>com.github.nawforce</groupId>
<artifactId>apex-parser</artifactId>
<version>2.15.0</version>
<version>2.17.0</version>
</dependency>

NPM

"apex-parser": "^2.15.0"
"apex-parser": "^2.17.0"

## Building

### Building
To build both distributions:

npm ci
npm run build

### History
## History

2.17.0 - Adds user/system mode on DML and within SOQL queries, thanks to Aaron Hurst.
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
2.10.0 - Allow type arguments on Classes (non-standard!)
2.9.2 - Generate .d.ts files
Expand All @@ -78,6 +90,6 @@ To build both distributions:
2.1.0 - Supports trigger parsing and switch statement parsing syntax was corrected
1.0.0 - Initial version

### 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.
19 changes: 16 additions & 3 deletions antlr/ApexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ WITHOUT : 'without';
LIST : 'list';
MAP : 'map';

// DML keywords
SYSTEM : 'system';
USER : 'user';

// Soql specific keywords
SELECT : 'select';
COUNT : 'count';
Expand Down Expand Up @@ -155,13 +159,17 @@ ABOVE : 'above';
BELOW : 'below';
ABOVE_OR_BELOW : 'above_or_below';
SECURITY_ENFORCED : 'security_enforced';
SYSTEM_MODE : 'system_mode';
USER_MODE : 'user_mode';
REFERENCE : 'reference';
CUBE : 'cube';
FORMAT : 'format';
TRACKING : 'tracking';
VIEWSTAT : 'viewstat';
CUSTOM : 'custom';
STANDARD : 'standard';
DISTANCE : 'distance';
GEOLOCATION : 'geolocation';

// SOQL Date functions
CALENDAR_MONTH : 'calendar_month';
Expand Down Expand Up @@ -193,30 +201,37 @@ LAST_90_DAYS : 'last_90_days';
NEXT_90_DAYS : 'next_90_days';
LAST_N_DAYS_N : 'last_n_days';
NEXT_N_DAYS_N : 'next_n_days';
N_DAYS_AGO_N : 'n_days_ago';
NEXT_N_WEEKS_N : 'next_n_weeks';
LAST_N_WEEKS_N : 'last_n_weeks';
N_WEEKS_AGO_N : 'n_weeks_ago';
NEXT_N_MONTHS_N : 'next_n_months';
LAST_N_MONTHS_N : 'last_n_months';
N_MONTHS_AGO_N : 'n_months_ago';
THIS_QUARTER : 'this_quarter';
LAST_QUARTER : 'last_quarter';
NEXT_QUARTER : 'next_quarter';
NEXT_N_QUARTERS_N : 'next_n_quarters';
LAST_N_QUARTERS_N : 'last_n_quarters';
N_QUARTERS_AGO_N : 'n_quarters_ago';
THIS_YEAR : 'this_year';
LAST_YEAR : 'last_year';
NEXT_YEAR : 'next_year';
NEXT_N_YEARS_N : 'next_n_years';
LAST_N_YEARS_N : 'last_n_years';
N_YEARS_AGO_N : 'n_years_ago';
THIS_FISCAL_QUARTER : 'this_fiscal_quarter';
LAST_FISCAL_QUARTER : 'last_fiscal_quarter';
NEXT_FISCAL_QUARTER : 'next_fiscal_quarter';
NEXT_N_FISCAL_QUARTERS_N : 'next_n_fiscal_quarters';
LAST_N_FISCAL_QUARTERS_N : 'last_n_fiscal_quarters';
N_FISCAL_QUARTERS_AGO_N : 'n_fiscal_quarters_ago';
THIS_FISCAL_YEAR : 'this_fiscal_year';
LAST_FISCAL_YEAR : 'last_fiscal_year';
NEXT_FISCAL_YEAR : 'next_fiscal_year';
NEXT_N_FISCAL_YEARS_N : 'next_n_fiscal_years';
LAST_N_FISCAL_YEARS_N : 'last_n_fiscal_years';
N_FISCAL_YEARS_AGO_N : 'n_fiscal_years_ago';

// SOQL Date literal
DateLiteral: Digit Digit Digit Digit '-' Digit Digit '-' Digit Digit;
Expand Down Expand Up @@ -378,7 +393,6 @@ DIV : '/';
BITAND : '&';
BITOR : '|';
CARET : '^';
MOD : '%';
MAPTO : '=>';

ADD_ASSIGN : '+=';
Expand All @@ -388,7 +402,6 @@ DIV_ASSIGN : '/=';
AND_ASSIGN : '&=';
OR_ASSIGN : '|=';
XOR_ASSIGN : '^=';
MOD_ASSIGN : '%=';
LSHIFT_ASSIGN : '<<=';
RSHIFT_ASSIGN : '>>=';
URSHIFT_ASSIGN : '>>>=';
Expand Down Expand Up @@ -434,7 +447,7 @@ WS : [ \t\r\n\u000C]+ -> channel(WHITESPACE_CHANNEL)
;

DOC_COMMENT
: '/**' [\r\n] .*? '*/' -> channel(COMMENT_CHANNEL)
: '/**' .*? '*/' -> channel(COMMENT_CHANNEL)
;

COMMENT
Expand Down
Loading