Skip to content

Commit 51c5d65

Browse files
Copilotjketema
andcommitted
Sync unified docs with PR #22290 (in-process swift-syntax-rs parsing)
Co-authored-by: jketema <93738568+jketema@users.noreply.github.com>
1 parent 7b3c872 commit 51c5d65

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

unified/AGENTS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ by Apple's swift-syntax rather than by tree-sitter.
88
- To build the extractor, run `scripts/create-extractor-pack.sh`
99

1010
## Swift Parser
11-
- Swift source is parsed by `swift-syntax-parse`, a small Swift/Rust binary in
12-
`swift-syntax-rs` that wraps Apple's swift-syntax and emits the parse tree as
13-
JSON. There is no grammar in this repository to edit.
11+
- Swift source is parsed by the `swift-syntax-rs` crate, which wraps Apple's
12+
swift-syntax. The extractor calls `swift_syntax_rs::parse_to_json` in-process
13+
to obtain the parse tree as JSON — there is no separate parser binary and no
14+
grammar in this repository to edit.
1415

1516
- `extractor/src/languages/swift/adapter.rs` converts that JSON into a yeast AST.
1617

@@ -23,10 +24,9 @@ by Apple's swift-syntax rather than by tree-sitter.
2324
- The mapping from the parse tree to the target AST is found in `extractor/src/languages/swift/swift.rs`
2425

2526
- To run tests for the parser and mapping, run `cargo test` in the `extractor`
26-
directory. The tests need the `swift-syntax-parse` binary: point
27-
`CODEQL_EXTRACTOR_UNIFIED_SWIFT_SYNTAX_PARSE` at it, or put it on `PATH`.
28-
Corpus tests skip themselves when it cannot be found, so check for skips
29-
before concluding a change is clean.
27+
directory. Since the parser is linked in-process, this needs a working Swift
28+
toolchain (so `swift-syntax-rs` can build). The tests can also be run under
29+
Bazel via `bazel test //unified/extractor:all_tests`.
3030

3131
- Extractor test cases are located at `extractor/tests/corpus/swift/*/*.swift`.
3232

unified/swift-syntax-rs/README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,22 @@ The build does not depend on any particular version manager. You need:
132132
(currently `6.3.2`), used to build `swift-syntax` `603.0.2`. Install it any way
133133
you like — [swift.org](https://www.swift.org/install/) or
134134
[swiftly](https://www.swift.org/swiftly/) (which reads `.swift-version`), or a
135-
system package. Just make sure `swift` is on your `PATH` (or point `build.rs`
136-
at it with the `SWIFT` environment variable).
135+
system package. Just make sure `swift` (and `swiftc`) are on your `PATH`
136+
`build.rs` invokes them directly and does not read any environment variable
137+
to locate them.
137138

138139
On Debian/Ubuntu the Swift runtime also needs `libncurses6` (and related libs)
139140
available on the system.
140141

141142
## Building & testing
142143

143-
With `cargo` and `swift` on `PATH`:
144+
With `cargo` and `swift`/`swiftc` on `PATH`:
144145

145146
```sh
146147
cargo build
147148
cargo test
148149
```
149150

150-
If your `swift`/`swiftc` are not on `PATH`, point the build at them explicitly:
151-
152-
```sh
153-
SWIFT=/path/to/swift SWIFTC=/path/to/swiftc cargo build
154-
```
155-
156151
The first build compiles `swift-syntax` and can take several minutes.
157152

158153
## Building with Bazel (CI)
@@ -170,6 +165,10 @@ bazel test //unified/swift-syntax-rs:swift_syntax_rs_test
170165
bazel run //unified/swift-syntax-rs:swift-syntax-parse < some.swift
171166
```
172167

168+
The `swift-syntax-parse` binary is a debugging aid for looking at the raw
169+
swift-syntax JSON for some input; it is not shipped as part of the extractor
170+
pack, which links `swift-syntax-rs` directly instead.
171+
173172
Requirements:
174173

175174
- **`clang`** must be installed on the runner. `rules_swift` requires the Bazel
@@ -221,9 +220,9 @@ echo 'let x = 1' | cargo run --bin swift-syntax-parse
221220
The JSON tree is consumed by the CodeQL extractor, which converts it into a
222221
[`yeast::Ast`](../../shared/yeast) — the in-memory format its rewrite rules
223222
operate on. That adapter is a pure-Rust module living in the extractor
224-
(`unified/extractor/src/languages/swift/adapter.rs`), so the extractor never
225-
needs the Swift toolchain: it consumes the JSON produced out-of-process by this
226-
crate's `parse_to_json` / the `swift-syntax-parse` binary.
223+
(`unified/extractor/src/languages/swift/adapter.rs`). The extractor links
224+
`swift-syntax-rs` directly and consumes the JSON produced in-process by this
225+
crate's `parse_to_json`.
227226

228227
## Layout
229228

0 commit comments

Comments
 (0)