tree-sitter-sfapex
Salesforce grammars for tree-sitter; includes Apex, SOQL, and SOSL languages. Also includes parser for the Salesforce Log files (sflog).
Try it out using our playground
If you are a Neo-vim user, the parsers and syntax highlights are part of nvim-treesitter plugin already, guidance.
Usage
Node
Install
Example
// import libraries
import Parser from "tree-sitter";
import TsSfApex from "tree-sitter-sfapex";
// create a parser instance
const parser = ;
// could be .apex, .soql, or .sosl
parser.;
// we set the language to Apex so lets feed it some apex
const apexTree = parser.;
// just a super simple example of printing the discovered nodes
// to see the anonymous nodes (syntax without formal names) set this to `true`
const includeAnonymousNodes = false;
console.log;
;
// do it with some SOQL this time
parser.;
const soqlTree = parser.;
console.log;
;
Rust
Install
Example
use ;
// just a super simple example of printing the discovered nodes
// to see the anonymous nodes (syntax without formal names) set this to `true`
const INCLUDE_ANONYMOUS_NODES: bool = true;
Status
Most of the parsers are built and tested on large corpus of Apex, I still intend to write automated tests that parse large Apex libraries as part of evaluating the grammar.
Apex
- grammar
- grammar tests
- highlighting queries
- highlighting tests
- tags queries
- tags tests (could use more)
- locals queries
- locals tests (using highlighting)
Anonymous Apex
- grammar
- grammar tests
- highlighting queries
- highlighting tests
- tags queries
- tags tests (could use more)
- locals queries
- locals tests (using highlighting)
SOQL
- grammar
- grammar tests
- highlighting queries
- highlighting tests
SOSL
- grammar
- grammar tests
- highlighting queries
- highlighting tests
SFLOG
Contributed by @finxxi, the sflog parser is very new and still being figured out. Feel free to contribute logs that fail to parse via the issues or by adding a failing test. I expect it to have a lot of development in terms of comprehention of individual log patterns and pulling out the types present there. For now it generally handles the main structure of log entries but doesn't parse the logged details very finely.
- grammar
- grammar tests (wip)
- highlighting queries (wip)
- highlighting tests
Questions/Issues
Please open an issue on this repo and we'll work through it.
Contributing
Still figuring this out. By far the most useful contributions would be tests, if you have a scenario that doesn't work you can just provide the example or open a PR with a new failing test and I can figure out what to do about it.