@@ -25,8 +25,8 @@ tokens and end with *close* tokens. These tokens must always be paired.
25
25
26
26
The different types of tokens are represented as a Token ` enum ` within the code.
27
27
The available cases are: ` syntax ` , ` break ` , ` open ` , ` close ` , ` newlines ` ,
28
- ` comment ` , and ` reset ` . The behavior of each of them is described below with
29
- pseudocode examples.
28
+ ` comment ` , ` reset ` , and ` verbatim ` . The behavior of each of them is described
29
+ below with pseudocode examples.
30
30
31
31
See: [ ` Token.swift ` ] ( ../Sources/SwiftFormatPrettyPrint/Token.swift )
32
32
@@ -239,6 +239,38 @@ Tokens = [block(" Block comment\n Second Line ")]
239
239
Tokens = [docBlock(" Doc Block comment\n * Second line *")]
240
240
```
241
241
242
+ #### Verbatim
243
+
244
+ Verbatim tokens are used to print text verbatim without any formatting apart
245
+ from applying a global indentation. They have a length set to the maximum line
246
+ width. They are typically used to handle syntax types that are classed as
247
+ "unknown" by SwiftSyntax. In these cases, we don't have access to the
248
+ substructure of the syntax node a manner useful for formatting, so we print them
249
+ verbatim. The indentation for verbatim tokens is applied to the first line of
250
+ the text. The relative indentation of subsequent lines is preserved unless they
251
+ have less indentation than the first line, in which case we set the indentation
252
+ of those lines equal to the first.
253
+
254
+ ```
255
+ // Consider "ifnt", an unknown syntax structure:
256
+
257
+ if someCondition {
258
+ ifnt anotherCondition {
259
+ let a = 123
260
+ let b = 456
261
+ }
262
+ }
263
+
264
+ // The pretty-printer will transform this into:
265
+
266
+ if someCondition {
267
+ ifnt anotherCondition {
268
+ let a = 123
269
+ let b = 456
270
+ }
271
+ }
272
+ ```
273
+
242
274
### Token Generation
243
275
244
276
Token generation begins with the abstract syntax tree (AST) of the Swift source
0 commit comments