Skip to content

Commit e3d747a

Browse files
committed
update documentation on filters
#docs fix cppalliance#796
1 parent 3630623 commit e3d747a

File tree

1 file changed

+84
-99
lines changed

1 file changed

+84
-99
lines changed

docs/modules/ROOT/pages/config-file.adoc

+84-99
Original file line numberDiff line numberDiff line change
@@ -49,156 +49,141 @@ These definitions are included in all targets of the compilation database.
4949

5050
== Filters
5151

52-
=== Symbol Filters
53-
5452
Not all symbols in a project may be relevant to the documentation.
55-
MrDocs provides a way to filter out symbols based on their names.
53+
MrDocs provides a way to filter out symbols based on their location and names.
5654

57-
[,yaml]
58-
----
59-
filters:
60-
symbols: # <.>
61-
exclude: # <.>
62-
include: # <.>
63-
----
55+
=== File Filters
6456

65-
<.> Optional `symbols` key
66-
<.> Optional `exclude` key
67-
<.> Optional `include` key
57+
Symbols can also be filtered based on the files where they are declared. This can be useful for excluding files that exclusively contain implementation details or test code.
6858

69-
Symbol filter patterns are specified using (optionally) qualified names, and may contain wildcards:
59+
The `input` option is a list of directories to include and a list of file patterns to include. Only symbols in files from these directories will be extracted.
7060

7161
[,yaml]
7262
----
73-
filters:
74-
symbols:
75-
exclude:
76-
- 'A::B'
77-
- 'A::f*'
63+
input:
64+
- ../include
7865
----
7966

80-
If a symbol matches a pattern in the exclude list, that symbol and its members will not be extracted:
67+
The default value for `input` is `"<source-root>/."`, so only symbols defined in your project source directory will be extracted.
68+
69+
The `file-patterns` options allows you to specify a list of glob file patterns to include. Only symbols in files whose filename match these patterns will be extracted.
8170

8271
[,yaml]
8372
----
84-
filters:
85-
symbols:
86-
exclude:
87-
- 'A'
73+
file-patterns:
74+
- '*.hpp'
75+
- '*.h'
8876
----
8977

90-
[,cpp]
91-
----
92-
// ok, does not match any excluded pattern
93-
void f0();
78+
The default value for `file-patterns` include a variety of common C++ header file extensions.
9479

95-
namespace A // matches the pattern 'A', will not be extracted
96-
{
97-
// enclosing namespace matches an excluded pattern:
98-
// the symbol will not be extracted
99-
void f1();
100-
}
101-
----
102-
103-
The `filters.symbols.include` key can be used to override the exclude list for specific symbols.
104-
A symbol which matches an included pattern and an excluded pattern will be extracted.
105-
106-
This permits fine-grained control of extraction for individual members of a class or namespace:
80+
The `exclude` option is a list of subdirectories in `input` we want to exclude. Meanwhile, `exclude-patterns` can use glob patterns to exclude files from the extraction process.
10781

10882
[,yaml]
10983
----
110-
filters:
111-
symbols:
112-
exclude:
113-
- 'A'
114-
include:
115-
- 'A::g*'
116-
----
117-
118-
[,cpp]
119-
----
120-
namespace A
121-
{
122-
// enclosing namespace matches an excluded pattern, will not be extracted
123-
void f0();
124-
125-
// ok, matches the pattern 'A::g*' which overrides the exclude list
126-
void g0();
127-
}
84+
input:
85+
- ../include
86+
exclude:
87+
- ../include/detail
88+
exclude-patterns:
89+
- ../include/*/detail/**
90+
- ../include/*/impl/**
12891
----
12992

130-
In order for a filter pattern to match a symbol, it must consist of simple identifiers that match the name as written in its declaration: namespace aliases, typedef-names, and `decltype` specifiers naming the symbol cannot be used.
93+
The glob patterns support the following wildcards:
13194

132-
NOTE: Specifying include patterns is only useful when the pattern would match a subset of symbols matched by an exclude pattern.
133-
An include pattern without a subsuming exclude pattern will be ignored.
95+
* `*` matches all characters except delimiters `/`
96+
* `**` matches all characters
97+
* `?` matches any single character.
98+
* `[<chars>]` matches one character in the bracket.
99+
* `[<char>-<char>]` matches one character in the bracket range.
100+
* `[^<chars>]` or `[!<chars>]` matches one character not in the bracket.
101+
* `{<glob>,...}` matches one of the globs in the list.
102+
* `\` escapes the next character so it is treated as a literal.
134103

135-
=== File Filters
104+
=== Symbol Filters
136105

137-
Symbols can also be filtered based on the files they are declared in.
138-
This can be useful for excluding files that exclusively contain implementation details or test code.
106+
Symbols can also be filtered based on their qualified names. You can use glob patterns to specify which symbols to include or exclude.
139107

140108
[,yaml]
141109
----
142-
input:
143-
include:
144-
- ../include # <.>
145-
file-patterns:
146-
- *.hpp # <.>
110+
include-symbols:
111+
- 'my_library::public_namespace::*'
147112
----
148113

149-
<.> A list of directories to include.
150-
Only symbols defined in these files will be extracted.
151-
<.> A list of file patterns to include.
152-
Only symbols defined in files matching these patterns will be extracted.
114+
By default, all symbols are included by `include-symbols`. The syntax for symbol glob patterns is the same as for file patterns, with the exception that the delimiter `::` is used instead of `/`. So you can match all symbols in a namespace and its subnamespaces with `my_library::public_namespace::**`.
153115

154-
=== Private Symbols
155-
156-
The `implementation-detail` and `see-below` options can be used to designate namespaces as implementation detail namespaces.
116+
The option `exclude-symbols` can be used to exclude symbols from the extraction process.
157117

158118
[,yaml]
159119
----
160-
implementation-detail: 'impl'
161-
see-below: 'see_below'
120+
include-symbols:
121+
- 'my_library::**'
122+
exclude-symbols:
123+
- 'my_library::private_namespace::**'
162124
----
163125

164-
If a namespace is designated as an implementation detail namespace, all symbols within that namespace will be marked as implementation details in the documentation.
165-
166126
[,cpp]
167127
----
168-
namespace impl
128+
// excluded by `include-symbols`
129+
void f0();
130+
131+
// included because it matches the prefix of 'my_library::**' in `include-symbols`
132+
namespace my_library
169133
{
170-
class A {};
171-
}
134+
// included because it matches the pattern 'my_library::**' in `include-symbols`
135+
void f1();
172136
173-
/// @brief A foo function
174-
A foo();
137+
namespace private_namespace
138+
{
139+
// excluded by the pattern 'my_library::private_namespace::**' in `exclude-symbols`
140+
void f2();
141+
}
142+
}
175143
----
176144

177-
The `impl` namespace is designated as an implementation detail namespace, so all symbols within it will be marked as implementation details in the documentation.
178-
This means the symbol `A` would not be documented and the function `foo` could be documented as follows:
145+
=== Private Symbols
146+
147+
The `implementation-detail` and `see-below` options can be used to designate symbols as implementation details or "see below" in the documentation.
179148

180-
[,cpp]
149+
[,yaml]
181150
----
182-
/* implementation detail */ foo();
151+
include-symbols:
152+
- 'my_library::**'
153+
implementation-detail:
154+
- 'my_library::detail::**'
155+
see-below:
156+
- 'my_library::see_below::**'
183157
----
184158

185-
On the other hand, if a namespace is designated as a `see_below` namespace, all symbols within that namespace will be marked as "see below" in the documentation.
159+
Symbols are only checked against the `implementation-detail` and `see-below` options if they match the `include-symbols` option.
186160

187161
[,cpp]
188162
----
189-
namespace see_below
163+
namespace my_library
190164
{
191-
class B {};
165+
namespace detail
166+
{
167+
// There's no documentation page for A
168+
// Any reference to `A` is rendered as `/* implementation detail */`
169+
class A {};
170+
}
171+
172+
namespace see_below
173+
{
174+
// The documentation page for B is marked as "see below" and its members are not extracted.
175+
class B {
176+
// There's no documentation page for iterator
177+
class iterator;
178+
};
179+
}
180+
181+
// This function is documented, but the return type is rendered as `/* implementation detail */`
182+
detail::A
183+
foo();
192184
}
193185
----
194186

195-
In the documentation, the symbol `B` would be marked as "see-below" and could be documented as:
196-
197-
[,cpp]
198-
----
199-
class B { /* see below */ };
200-
----
201-
202187
[#config-options-reference]
203188
== Reference
204189

0 commit comments

Comments
 (0)