This is a CodeQL extractor that maps a language's parse tree onto a shared AST
using the yeast desugaring engine. Swift, the only language so far, is parsed
by Apple's swift-syntax rather than by tree-sitter.
- To build the extractor, run
scripts/create-extractor-pack.sh
-
Swift source is parsed by
swift-syntax-parse, a small Swift/Rust binary inswift-syntax-rsthat wraps Apple's swift-syntax and emits the parse tree as JSON. There is no grammar in this repository to edit. -
extractor/src/languages/swift/adapter.rsconverts that JSON into a yeast AST. -
The raw parse tree's shape is described by
extractor/swift_node_types.yml, which is maintained by hand.
-
The target AST shape is described by
extractor/ast_types.yml. -
The mapping from the parse tree to the target AST is found in
extractor/src/languages/swift/swift.rs -
To run tests for the parser and mapping, run
cargo testin theextractordirectory. The tests need theswift-syntax-parsebinary: pointCODEQL_EXTRACTOR_UNIFIED_SWIFT_SYNTAX_PARSEat it, or put it onPATH. Corpus tests skip themselves when it cannot be found, so check for skips before concluding a change is clean. -
Extractor test cases are located at
extractor/tests/corpus/swift/*/*.swift. -
Each test case has a corresponding
.outputfile containing its generated output along with a copy of the test case itself. -
Check the output files for correctness but do not edit them manually. Regenerate them with
scripts/update-corpus.sh.
-
If you changed the extractor code, always rebuild it before running CodeQL tests.
-
To run all CodeQL tests, run
codeql test run --search-path extractor-pack ql/test -
Do not edit
.expectedfiles manually. To update the expected output, pass--learnto thecodeql test runcommand. -
To run a specific test, pass the specific directory to the
codeql test runcommand instead ofql/test.