- The new parser is now linked into the compiler, with additional testing that we can enable for every single compile. There are two kinds of tests at the moment:
- Round-trip testing: this ensures that the syntax nodes produced by the new parser reproduce every byte of the input source correctly, no matter how broken the input source is. This critical testing for the robustness of the parser and syntax nodes.
- Valid-parse testing: this ensures that, if the C++ parser produces no errors when parsing, the new Swift parser also produces a syntax tree that contains no unknown, unexpected, or missing nodes (all of which imply errors). This makes sure that the new parser is covering the full grammar correctly.
- The compiler's full test suite (~15,000 tests) runs with both checked modes above enabled. There are only about two failures, which are intentionally-crafted bad inputs with, e.g., a couple of hundred opening
('s in a row.
- Parser recovery is improved, including handling source files with malformed UTF-8.
- Added support for creating syntax nodes via string interpolation, so one can create a syntax node by interpolating bits of syntax into a string literal, e.g.,
let expr: ExprSyntax = """ \(node.withoutTrivia()).toggle() """
- Added the
SwiftOperatorslibrary, which handles operator precedence results to rewrite a syntax tree for a "sequence" expression such as
x + y * zinto one that shows the order of operations.
swift-format has adopted the new parser and
Thanks to everyone who tried it out, provided feedback, and fixed bugs. Our next big leap forward is bringing up
ASTGen, which will be part of the Swift compiler itself that translates Swift syntax nodes into the C++ AST, and will eventually replace the C++ parser.