Skip to content

Commit ea70e0e

Browse files
authored
Merge pull request #1824 from ahoppen/ahoppen/glosssary
Add a glossary to SwiftSyntax
2 parents d05b578 + 2c7bac3 commit ea70e0e

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
1717
### Articles
1818

1919
- <doc:Working-with-SwiftSyntax>
20+
- <doc:Glossary>
2021

2122
### Tutorials
2223

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Glossary
2+
3+
Glossary of terms and abbreviations used in SwiftSyntax
4+
5+
## Abbreviations and Terms
6+
7+
To avoid ongoing repetition of common long terms, SwiftSyntax uses a couple of abbreviations that are common in compiler projects.
8+
9+
10+
**Arena** See ``SyntaxArena``
11+
12+
**Decl** Abbreviation for *Declaration*
13+
14+
**Expr** Abbreviation for *Expression*
15+
16+
**Layout Node** A layout node has can have an arbitrary number of children and provides structure to the syntax tree. All ``Syntax`` nodes that aren’t ``TokenSyntax`` are layout nodes. For example a ``StructDeclSyntax`` consists of, among others, of the `struct` keyword, the name and the `memberBlock`. The latter is again a layout node that contains multiple children. Layout nodes never represent any source code in the syntax tree by themselves. All source code within the syntax tree is represented by *tokens*.
17+
18+
**Node** A *layout node* or *token*
19+
20+
**RawSyntax** The underlying storage of syntax nodes. These are manually memory managed inside an *arena*. You should not need to interact with them unless contributing to swift-syntax.
21+
22+
**Stmt** Abbreviation for *Statement*
23+
24+
**Token** See ``TokenSyntax``
25+
26+
**Trivia** See ``Trivia``
27+
28+
<!-- IMPORTANT: Please keep the list above alphabetically ordered instead of adding new entries at the bottom -->

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
1717
### Articles
1818

1919
- <doc:Working-with-SwiftSyntax>
20+
- <doc:Glossary>
2021

2122
### Tutorials
2223

Sources/SwiftSyntax/TokenSyntax.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
// MARK: TokenSyntax
1414

1515
/// A Syntax node representing a single token.
16+
///
17+
/// All source code of a syntax tree is represented by tokens – layout nodes
18+
/// never contain any source code by themselves.
19+
///
20+
/// A token consists of leading ``Trivia``, i.e. whitespaces before the actual
21+
/// token contents, the token’s `text` and trailing ``Trivia`` after the token’s
22+
/// content.
1623
public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
1724
/// The ``Syntax`` node that provides the underlying data.
1825
///

Sources/SwiftSyntax/Trivia.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ public enum TriviaPosition {
1515
case trailing
1616
}
1717

18-
/// A collection of leading or trailing trivia. This is the main data structure
19-
/// for thinking about trivia.
18+
/// Trivia represent pieces of the source code that are not relevant to represent
19+
/// its semantic structure.
20+
///
21+
/// The standard examples of trivia are spaces, newlines and comments.
22+
///
23+
/// The SwiftSyntax tree retains trivia to maintain round-tripness of the source
24+
/// code, ensuring that printing the entire syntax tree be rendered back into
25+
/// text that is byte-for-byte identical to the original source.
26+
///
27+
/// Each ``TokenSyntax`` can have multiple ``TriviaPiece``s as either leading or
28+
/// trailing trivia, which occur before or after the token’s content, respectively.
29+
/// ``Trivia`` represents a collection of these ``TriviaPiece``s
2030
public struct Trivia {
2131
/// The pieces this trivia consists of. Each ``TriviaPiece`` can represent
2232
/// multiple characters, such as an entire comment or 4 spaces.

0 commit comments

Comments
 (0)