swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request for Documentation on Parsing Rules for Trivia in swift-syntax

omochi opened this issue · comments

Description

I'd like to request documentation on the rules for parsing Trivia.
There used to be documentation explaining the rules for parsing Trivia back when we were using libSyntax,
but it seems to have disappeared since the transition to swift-syntax.

The URL at the time was as follows.
https://github.com/apple/swift/blob/980d40951ff557047dce833d1d092b400bbc20db/lib/Syntax/README.md

Just to be sure, I searched both the repository and the documentation site, but I couldn't find it.

Understanding what constitutes the trailing trivia of a preceding token and
what becomes the leading trivia of a following token
is essential for implementing tools that process code.

It's challenging to deduce this behavior from the actual behavior alone,
so I believe it's necessary to have a document that explains this.

Tracked in Apple’s issue tracker as rdar://125747258

Generally (if you don’t consider multi-line string literals, which have their own rules), all trivia up to a newline is trailing trivia and all trivia after a newline is leading trivia.