You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+10-8
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Contributing
2
2
3
+
This document contains notes about development and testing of swift-syntax, the [Contributor Documentation](Contributor%20Documentation) folder has some more in-depth documents.
4
+
3
5
## Building & Testing
4
6
5
7
swift-syntax is a SwiftPM package, so you can build and test it using anything that supports packages - opening in Xcode, Visual Studio Code with [Swift for Visual Studio Code](https://github.com/swift-server/vscode-swift) installed, or through the command line using `swift build` and `swift test`.
@@ -13,7 +15,7 @@ swift-syntax is a SwiftPM package, so you can build and test it using anything t
13
15
> - On the command line: Set the `SKIP_LONG_TESTS` environment variable to `1` when running tests, e.g by running `SKIP_LONG_TESTS=1 swift test`
14
16
15
17
> [!NOTE]
16
-
> If you are only modifying the `SwiftParser` module, you can run only the parser tests by selecting the `SwiftParserTest` target.
18
+
> If you are only modifying the `SwiftParser` module, you can run only the parser tests by selecting the `SwiftParserTest` target.
17
19
> - In Xcode: Select the `SwiftParserTest` scheme. If you can’t find it in your Schemes, you need to manually add it using Product -> Scheme -> New Scheme…
18
20
> - On the command line: Run `swift test --test-product SwiftParserTests`
19
21
@@ -30,7 +32,7 @@ It will build a local copy of swift-format from the `main` branch and format the
30
32
Generated source code is not formatted to make it easier to spot changes when re-running code generation.
31
33
32
34
> [!NOTE]
33
-
> You can add a git hook to ensure all commits to the swift-syntax repository are correctly formatted.
35
+
> You can add a git hook to ensure all commits to the swift-syntax repository are correctly formatted.
34
36
> 1. Save the following contents to `swift-syntax/.git/hooks/pre-commit`
35
37
> ```bash
36
38
>#!/usr/bin/env bash
@@ -39,7 +41,7 @@ Generated source code is not formatted to make it easier to spot changes when re
39
41
> swift "$SOURCE_DIR/swift-syntax-dev-utils" format --lint
40
42
>```
41
43
> 2. Mark the file as executable: `chmod a+x swift-syntax/.git/hooks/pre-commit`
42
-
> 3. If you have global git hooks installed, be sure to call them at the end of the script with `path/to/global/hooks/pre-commit "$@"`
44
+
> 3. If you have global git hooks installed, be sure to call them at the end of the script with `path/to/global/hooks/pre-commit "$@"`
43
45
44
46
45
47
## Generating Source Code
@@ -54,7 +56,7 @@ Alternatively, you can generate the files from the command line by running the f
54
56
55
57
## Running Pre-PR Checks Script
56
58
57
-
To ensure that your changes to the project are implemented correctly and do not introduce issues across the repository, a script has been provided to automate the necessary pre-PR checks.
59
+
To ensure that your changes to the project are implemented correctly and do not introduce issues across the repository, a script has been provided to automate the necessary pre-PR checks.
58
60
59
61
```bash
60
62
./swift-syntax-dev-utils local-pr-precheck
@@ -69,7 +71,7 @@ Prefer to squash the commits of your PR (*pull request*) and avoid adding commit
69
71
70
72
We prefer to not squash commits when merging a PR because, especially for larger PRs, it sometimes makes sense to split the PR into multiple self-contained chunks of changes. For example, a PR might do a refactoring first before adding a new feature or fixing a bug. This separation is useful for two reasons:
71
73
- During review, the commits can be reviewed individually, making each review chunk smaller
72
-
- In case this PR introduced a bug that is identified later, it is possible to check if it resulted from the refactoring or the actual change, thereby making it easier find the lines that introduce the issue.
74
+
- In case this PR introduced a bug that is identified later, it is possible to check if it resulted from the refactoring or the actual change, thereby making it easier find the lines that introduce the issue.
73
75
74
76
## Opening a PR
75
77
@@ -92,17 +94,17 @@ See the [dedicated section][section] on the Swift project website.
92
94
93
95
After you opened your PR, a maintainer will review it and test your changes in CI (*Continuous Integration*) by adding a `@swift-ci Please test` comment on the pull request. Once your PR is approved and CI has passed, the maintainer will merge your pull request.
94
96
95
-
Only contributors with [commit access](https://www.swift.org/contributing/#commit-access) are able to approve pull requests and trigger CI.
97
+
Only contributors with [commit access](https://www.swift.org/contributing/#commit-access) are able to approve pull requests and trigger CI.
96
98
97
99
## Additional Verification
98
100
99
101
swift-syntax has additional verification methods (see the sections below) that provide more extensive validation. They have a significant runtime impact on swift-syntax and are thus not enabled by default when building swift-syntax, but are enabled in CI. If CI fails and you are unable to reproduce the failure locally, make sure that `SKIP_LONG_TESTS` is not set and try enabling these validations.
100
102
101
103
### RawSyntax Validation
102
104
103
-
When the `SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION` environment variable is set while building swift-syntax, SwiftSyntax will perform additional validation that the layout of the syntax tree is correct. It validates that
105
+
When the `SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION` environment variable is set while building swift-syntax, SwiftSyntax will perform additional validation that the layout of the syntax tree is correct. It validates that
104
106
1. every child of a syntax node has the correct kind, which should be guaranteed by the Swift type system in most cases
105
-
2. each token only has one of the token kinds that is specified in the syntax tree layout of the `CodeGeneration` package.
107
+
2. each token only has one of the token kinds that is specified in the syntax tree layout of the `CodeGeneration` package.
106
108
107
109
If this validation hits an assertion failure that a token is not accepted at a certain position in the syntax tree, double-check if the token kind that is being stored in the syntax tree actually makes sense here. If it does not, check if there is a parser bug or whether you need to remap the token kind. If it does make sense, add the token kind to `.token(choices:)` of the syntax node in CodeGeneration, re-generate that source code and run tests again.
The following environment variables can be used to control some behavior in swift-syntax.
4
+
5
+
## Build time
6
+
7
+
-`SWIFT_BUILD_SCRIPT_ENVIRONMENT`: Enable assertions in release builds and remove the dependency of swift-syntax on os_log.
8
+
-`SWIFTCI_USE_LOCAL_DEPS`: Assume that all of SourceKit-LSP’s dependencies are checked out next to it and use those instead of cloning the repositories. Primarily intended for CI environments that check out related branches.
9
+
-`SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION`: Mutate the input of `assertParse` test cases. See [CONTRIBUTING](../CONTRIBUTING.md) for more information.
10
+
-`SWIFTSYNTAX_BUILD_DYNAMIC_LIBRARIES`: Build all libraries as *dynamic* instead of *automatic*. This allows us to build swift-syntax as dynamic libraries, which in turn allows us to build SourceKit-LSP using SwiftPM on Windows. Linking swift-syntax statically into sourcekit-lsp exceeds the maximum number of exported symbols on Windows.
11
+
-`SWIFTSYNTAX_ENABLE_RAWSYNTAX_VALIDATION`: Check that the layout of the syntax tree is correct when creating or modifying nodes. See [CONTRIBUTING](../CONTRIBUTING.md) for more information.
12
+
13
+
## Testing
14
+
15
+
-`SKIP_LONG_TESTS`: Skip tests that typically take more than 1s to execute.
Copy file name to clipboardExpand all lines: Sources/SwiftParser/SwiftParser.docc/SwiftParser.md
+1-6
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ A parser for the Swift programming language.
4
4
5
5
## Overview
6
6
7
-
The `SwiftParser` framework implements a parser that accepts Swift source text as input and produces a SwiftSyntax syntax tree.
7
+
The `SwiftParser` framework implements a parser that accepts Swift source text as input and produces a SwiftSyntax syntax tree.
8
8
9
9
## Quickstart
10
10
@@ -49,8 +49,3 @@ There are several design principles that govern the parser:
49
49
-**Source-preserving**: SwiftSyntax is designed to maintain all “trivia” (including whitespace, comments, etc.) precisely as it occurs in the source text, so that a syntax tree can be rendered back into text that is byte-for-byte identical to the original source. The parser must maintain this property, regardless of whether the input text was well-formed Swift code.
50
50
-**Minimal context**: The parser requires minimal context to parse Swift code, which consists of only those things required to handle a suitable Swift dialect, e.g., whether [regex literals](https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md) are supported. The parser can be invoked on any input source code, starting at any major production in the grammar (e.g., full source file, an individual type, an individual expression).
51
51
-**Incremental**: A parse tree produced for a source file can be incrementally updated for a new version of that source file, reusing syntax nodes where possible to reduce computation overhead and memory.
0 commit comments