Skip to content

Commit 6c5c082

Browse files
authored
Merge pull request #350 from apple/amartini/docs_91301229
Revise doc comments for API reference style.
2 parents 435090d + ac618f6 commit 6c5c082

27 files changed

+268
-161
lines changed

Sources/RegexBuilder/CharacterClass.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extension RegexComponent where Self == CharacterClass {
100100
members: s.map { .atom(.char($0)) }))
101101
}
102102

103-
/// Returns a character class that matches any unicode scalar in the given
103+
/// Returns a character class that matches any Unicode scalar in the given
104104
/// sequence.
105105
public static func anyOf<S: Sequence>(_ s: S) -> CharacterClass
106106
where S.Element == UnicodeScalar
@@ -118,15 +118,15 @@ extension CharacterClass {
118118
}
119119
}
120120

121-
/// Range syntax for characters in `CharacterClass`es.
121+
/// Returns a character class that includes the characters in the given range.
122122
@available(SwiftStdlib 5.7, *)
123123
public func ...(lhs: Character, rhs: Character) -> CharacterClass {
124124
let range: DSLTree.CustomCharacterClass.Member = .range(.char(lhs), .char(rhs))
125125
let ccc = DSLTree.CustomCharacterClass(members: [range], isInverted: false)
126126
return CharacterClass(ccc)
127127
}
128128

129-
/// Range syntax for unicode scalars in `CharacterClass`es.
129+
/// Returns a character class that includes the Unicode scalars in the given range.
130130
@_disfavoredOverload
131131
@available(SwiftStdlib 5.7, *)
132132
public func ...(lhs: UnicodeScalar, rhs: UnicodeScalar) -> CharacterClass {

Sources/RegexBuilder/DSL.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ extension UnicodeScalar: RegexComponent {
9595
// Note: Quantifiers are currently gyb'd.
9696

9797
extension DSLTree.Node {
98-
/// Generates a DSLTree node for a repeated range of the given DSLTree node.
99-
/// Individual public API functions are in the generated Variadics.swift file.
98+
// Individual public API functions are in the generated Variadics.swift file.
99+
/// Generates a DSL tree node for a repeated range of the given node.
100100
@available(SwiftStdlib 5.7, *)
101101
static func repeating(
102102
_ range: Range<Int>,
@@ -251,8 +251,10 @@ public struct TryCapture<Output>: _BuiltinRegexComponent {
251251

252252
// MARK: - Groups
253253

254-
/// An atomic group, i.e. opens a local backtracking scope which, upon successful exit,
255-
/// discards any remaining backtracking points from within the scope
254+
/// An atomic group.
255+
///
256+
/// This group opens a local backtracking scope which, upon successful exit,
257+
/// discards any remaining backtracking points from within the scope.
256258
@available(SwiftStdlib 5.7, *)
257259
public struct Local<Output>: _BuiltinRegexComponent {
258260
public var regex: Regex<Output>
@@ -265,6 +267,7 @@ public struct Local<Output>: _BuiltinRegexComponent {
265267
// MARK: - Backreference
266268

267269
@available(SwiftStdlib 5.7, *)
270+
/// A backreference.
268271
public struct Reference<Capture>: RegexComponent {
269272
let id = ReferenceID()
270273

Sources/_RegexParser/Regex/AST/AST.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
/// A regex abstract syntax tree. This is a top-level type that stores the root
13-
/// node.
12+
/// A regex abstract syntax tree.
13+
///
14+
/// This is a top-level type that stores the root node.
1415
public struct AST: Hashable {
1516
public var root: AST.Node
1617
public var globalOptions: GlobalMatchingOptionSequence?
@@ -22,7 +23,7 @@ public struct AST: Hashable {
2223
}
2324

2425
extension AST {
25-
/// Whether this AST tree has nested somewhere inside it a capture.
26+
/// Whether this AST tree contains at least one capture nested inside of it.
2627
public var hasCapture: Bool { root.hasCapture }
2728

2829
/// The capture structure of this AST tree.
@@ -94,7 +95,9 @@ extension AST.Node {
9495
_associatedValue as? T
9596
}
9697

97-
/// If this node is a parent node, access its children
98+
/// The child nodes of this node.
99+
///
100+
/// If the node isn't a parent node, this value is `nil`.
98101
public var children: [AST.Node]? {
99102
return (_associatedValue as? _ASTParent)?.children
100103
}
@@ -103,15 +106,15 @@ extension AST.Node {
103106
_associatedValue.location
104107
}
105108

106-
/// Whether this node is "trivia" or non-semantic, like comments
109+
/// Whether this node is trivia or non-semantic, like comments.
107110
public var isTrivia: Bool {
108111
switch self {
109112
case .trivia: return true
110113
default: return false
111114
}
112115
}
113116

114-
/// Whether this node has nested somewhere inside it a capture
117+
/// Whether this node contains at least one capture nested inside of it.
115118
public var hasCapture: Bool {
116119
switch self {
117120
case .group(let g) where g.kind.value.isCapturing:
@@ -122,7 +125,7 @@ extension AST.Node {
122125
return self.children?.any(\.hasCapture) ?? false
123126
}
124127

125-
/// Whether this AST node may be used as the operand of a quantifier such as
128+
/// Whether this node may be used as the operand of a quantifier such as
126129
/// `?`, `+` or `*`.
127130
public var isQuantifiable: Bool {
128131
switch self {
@@ -203,7 +206,9 @@ extension AST {
203206
}
204207
}
205208

206-
/// An Oniguruma absent function. This is used to model a pattern which should
209+
/// An Oniguruma absent function.
210+
///
211+
/// This is used to model a pattern which should
207212
/// not be matched against across varying scopes.
208213
public struct AbsentFunction: Hashable, _ASTNode {
209214
public enum Start: Hashable {

Sources/_RegexParser/Regex/AST/Atom.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ extension AST.Atom.CharacterProperty {
415415
}
416416

417417
extension AST.Atom {
418-
/// Anchors and other built-in zero-width assertions
418+
/// Anchors and other built-in zero-width assertions.
419419
@frozen
420420
public enum AssertionKind: String {
421421
/// \A
@@ -574,7 +574,7 @@ extension AST.Atom {
574574
}
575575

576576
extension AST.Atom.Callout {
577-
/// A tag specifier `[...]` which may appear in an Oniguruma callout.
577+
/// A tag specifier `[...]` that can appear in an Oniguruma callout.
578578
public struct OnigurumaTag: Hashable {
579579
public var leftBracket: SourceLocation
580580
public var name: AST.Located<String>
@@ -668,8 +668,10 @@ extension AST.Atom.EscapedBuiltin {
668668
}
669669

670670
extension AST.Atom {
671-
/// Retrieve the character value of the atom if it represents a literal
672-
/// character or unicode scalar, nil otherwise.
671+
/// Retrieves the character value of the atom.
672+
///
673+
/// If the atom doesn't represent a literal character or a Unicode scalar,
674+
/// this value is `nil`.
673675
public var literalCharacterValue: Character? {
674676
switch kind {
675677
case .char(let c):
@@ -711,9 +713,9 @@ extension AST.Atom {
711713
}
712714
}
713715

714-
/// Produce a string literal representation of the atom, if possible
716+
/// A string literal representation of the atom, if possible.
715717
///
716-
/// Individual characters will be returned, Unicode scalars will be
718+
/// Individual characters are returned as-is, and Unicode scalars are
717719
/// presented using "\u{nnnn}" syntax.
718720
public var literalStringValue: String? {
719721
switch kind {

Sources/_RegexParser/Regex/AST/CustomCharClass.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ extension CustomCC.Member {
104104
}
105105

106106
extension AST.CustomCharacterClass {
107-
/// Strip trivia from the character class members. This does not recurse into
108-
/// nested custom character classes.
107+
/// Strips trivia from the character class members.
108+
///
109+
/// This method doesn't recurse into nested custom character classes.
109110
public var strippingTriviaShallow: Self {
110111
var copy = self
111112
copy.members = copy.members.filter(\.isSemantic)

Sources/_RegexParser/Regex/AST/Group.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ extension AST {
7878
}
7979

8080
extension AST.Group.Kind {
81+
/// Whether the group is a capturing group.
8182
public var isCapturing: Bool {
8283
switch self {
8384
case .capture, .namedCapture, .balancedCapture: return true
8485
default: return false
8586
}
8687
}
8788

88-
/// If this is a named group, its name, `nil` otherwise.
89+
/// The name of the group.
90+
///
91+
/// If the group doesn't have a name, this value is `nil`.
8992
public var name: String? {
9093
switch self {
9194
case .namedCapture(let name): return name.value
@@ -96,9 +99,11 @@ extension AST.Group.Kind {
9699
}
97100

98101
extension AST.Group.Kind {
99-
/// If this group is a lookaround assertion, return its direction
100-
/// and whether it is positive or negative. Otherwise returns
101-
/// `nil`.
102+
/// The direction of a lookaround assertion
103+
/// and an indication of whether the assertion is positive or negative.
104+
///
105+
/// If the group isn't a lookaheand or lookbehind assertion,
106+
/// this value is `nil`.
102107
public var lookaroundKind: (forwards: Bool, positive: Bool)? {
103108
switch self {
104109
case .lookahead: return (true, true)

Sources/_RegexParser/Regex/AST/MatchingOptions.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
extension AST {
13-
/// An option written in source that changes matching semantics.
13+
/// An option, written in source, that changes matching semantics.
1414
public struct MatchingOption: Hashable {
1515
public enum Kind {
1616
// PCRE options
@@ -83,7 +83,7 @@ extension AST {
8383
}
8484
}
8585

86-
/// A sequence of matching options written in source.
86+
/// A sequence of matching options, written in source.
8787
public struct MatchingOptionSequence: Hashable {
8888
/// If the sequence starts with a caret '^', its source location, or nil
8989
/// otherwise. If this is set, it indicates that all the matching options
@@ -138,8 +138,11 @@ extension AST.MatchingOptionSequence: _ASTPrintable {
138138
}
139139

140140
extension AST {
141-
/// Global matching option specifiers. Unlike `MatchingOptionSequence`,
142-
/// these must appear at the start of the pattern, and apply globally.
141+
/// Global matching option specifiers.
142+
///
143+
/// Unlike `MatchingOptionSequence`,
144+
/// these options must appear at the start of the pattern,
145+
/// and they apply to the entire pattern.
143146
public struct GlobalMatchingOption: _ASTNode, Hashable {
144147
/// Determines the definition of a newline for the '.' character class and
145148
/// when parsing end-of-line comments.

Sources/_RegexParser/Regex/AST/Quantification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension AST {
5959
/// MARK: - Semantic API
6060

6161
extension AST.Quantification.Amount {
62-
/// Get the bounds
62+
/// The bounds.
6363
public var bounds: (atLeast: Int, atMost: Int?) {
6464
switch self {
6565
case .zeroOrMore: return (0, nil)

Sources/_RegexParser/Regex/Parse/CaptureStructure.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,11 @@ extension CaptureStructure {
286286
MemoryLayout<SerializationVersion>.stride + inputUTF8CodeUnitCount + 1
287287
}
288288

289-
/// Encode the capture structure to the given buffer as a serialized
289+
/// Encodes the capture structure to the given buffer as a serialized
290290
/// representation.
291291
///
292292
/// The encoding rules are as follows:
293+
///
293294
/// ```
294295
/// encode(〚`T`〛) ==> <version>, 〚`T`〛, .end
295296
/// 〚`T` (atom)〛 ==> .atom

Sources/_RegexParser/Regex/Parse/Parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ fileprivate func defaultSyntaxOptions(
577577
}
578578
}
579579

580-
/// Parse a given regex string with delimiters, inferring the syntax options
581-
/// from the delimiter used.
580+
/// Parses a given regex string with delimiters, inferring the syntax options
581+
/// from the delimiters used.
582582
public func parseWithDelimiters<S: StringProtocol>(
583583
_ regex: S
584584
) throws -> AST where S.SubSequence == Substring {

Sources/_RegexParser/Regex/Parse/Source.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
/// The source given to a parser. This can be bytes in memory, a file on disk,
13-
/// something streamed over a network connection, etc.
12+
// For now, we use String as the source while prototyping...
13+
14+
/// The source of text being given to a parser.
1415
///
15-
/// For now, we use String...
16+
/// This can be bytes in memory, a file on disk,
17+
/// something streamed over a network connection, and so on.
1618
///
1719
public struct Source {
1820
var input: Input
@@ -37,7 +39,7 @@ extension Source {
3739
public typealias Input = String // for wrapper...
3840
public typealias Char = Character // for wrapper...
3941

40-
/// A precise point in the input, commonly used for bounded ranges
42+
/// A precise point in the input, commonly used for bounded ranges.
4143
public typealias Position = String.Index
4244
}
4345

Sources/_RegexParser/Regex/Parse/SourceLocation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public protocol LocatedErrorProtocol: Error {
6262
}
6363

6464
extension Source {
65-
/// An error with source location info
65+
/// An error that includes information about the location in source code.
6666
public struct LocatedError<E: Error>: Error, LocatedErrorProtocol {
6767
public let error: E
6868
public let location: SourceLocation
@@ -77,10 +77,10 @@ extension Source {
7777
}
7878
}
7979

80-
/// Located value: a value wrapped with a source range
80+
/// A value wrapped with a source range.
8181
///
82-
/// Note: source location is part of value identity, so that the same
83-
/// e.g. `Character` appearing twice can be stored in a data structure
82+
/// Note: Source location is part of value identity so that, for example, the
83+
/// same `Character` value appearing twice can be stored in a data structure
8484
/// distinctly. To ignore source locations, use `.value` directly.
8585
public struct Located<T> {
8686
public var value: T

Sources/_RegexParser/Regex/Parse/SyntaxOptions.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,31 @@ public struct SyntaxOptions: OptionSet {
3131
[.endOfLineComments, .nonSemanticWhitespace]
3232
}
3333

34+
// NOTE: Currently, this means we have raw quotes.
35+
// Better would be to have real Swift string delimiter parsing logic.
36+
3437
/// `'a "." b' == '/a\Q.\Eb/'`
35-
///
36-
/// NOTE: Currently, this means we have raw quotes.
37-
/// Better would be to have real Swift string delimiter parsing logic.
3838
public static var experimentalQuotes: Self { Self(1 << 2) }
3939

40+
// NOTE: traditional comments are not nested. Currently, we are neither.
41+
// Traditional comments can't have `)`, not even escaped in them either, we
42+
// can. Traditional comments can have `*/` in them, we can't without
43+
// escaping. We don't currently do escaping.
44+
4045
/// `'a /* comment */ b' == '/a(?#. comment )b/'`
41-
///
42-
/// NOTE: traditional comments are not nested. Currently, we are neither.
43-
/// Traditional comments can't have `)`, not even escaped in them either, we
44-
/// can. Traditional comments can have `*/` in them, we can't without
45-
/// escaping. We don't currently do escaping.
4646
public static var experimentalComments: Self { Self(1 << 3) }
4747

4848
/// ```
49-
/// 'a{n...m}' == '/a{n,m}/'
50-
/// 'a{n..<m}' == '/a{n,m-1}/'
51-
/// 'a{n...}' == '/a{n,}/'
52-
/// 'a{...m}' == '/a{,m}/'
53-
/// 'a{..<m}' == '/a{,m-1}/'
49+
/// 'a{n...m}' == '/a{n,m}/'
50+
/// 'a{n..<m}' == '/a{n,m-1}/'
51+
/// 'a{n...}' == '/a{n,}/'
52+
/// 'a{...m}' == '/a{,m}/'
53+
/// 'a{..<m}' == '/a{,m-1}/'
5454
/// ```
5555
public static var experimentalRanges: Self { Self(1 << 4) }
5656

5757
/// `(name: .*)` == `(?<name>.*)`
58-
/// `(_: .*)` == `(?:.*)`
58+
/// `(_: .*)` == `(?:.*)`
5959
public static var experimentalCaptures: Self { Self(1 << 5) }
6060

6161
/// The default syntax for a multi-line regex literal.

Sources/_RegexParser/Regex/Printing/DumpAST.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
/// AST entities can be pretty-printed or dumped
12+
/// AST entities that can be pretty-printed or dumped.
1313
///
14-
/// Alternative: just use `description` for pretty-print
15-
/// and `debugDescription` for dump
14+
/// As an alternative to this protocol,
15+
/// you can also use the `description` to pretty-print an AST,
16+
/// and `debugDescription` for to dump a debugging representation.
1617
public protocol _ASTPrintable:
1718
CustomStringConvertible,
1819
CustomDebugStringConvertible

0 commit comments

Comments
 (0)