@@ -8,12 +8,12 @@ extend the compiler's behavior with new syntax extensions, lint checks, etc.
8
8
A plugin is a dynamic library crate with a designated * registrar* function that
9
9
registers extensions with ` rustc ` . Other crates can load these extensions using
10
10
the crate attribute ` #![plugin(...)] ` . See the
11
- [ ` rustc_plugin ` ] ( ../rustc_plugin/index.html ) documentation for more about the
11
+ ` rustc_plugin ` documentation for more about the
12
12
mechanics of defining and loading a plugin.
13
13
14
14
If present, arguments passed as ` #![plugin(foo(... args ...))] ` are not
15
15
interpreted by rustc itself. They are provided to the plugin through the
16
- ` Registry ` 's [ ` args ` method] ( ../rustc_plugin/registry/struct.Registry.html#method.args ) .
16
+ ` Registry ` 's ` args ` method.
17
17
18
18
In the vast majority of cases, a plugin should * only* be used through
19
19
` #![plugin] ` and not through an ` extern crate ` item. Linking a plugin would
@@ -30,7 +30,7 @@ of a library.
30
30
Plugins can extend Rust's syntax in various ways. One kind of syntax extension
31
31
is the procedural macro. These are invoked the same way as [ ordinary
32
32
macros] ( macros.html ) , but the expansion is performed by arbitrary Rust
33
- code that manipulates [ syntax trees] ( ../syntax/ast/index.html ) at
33
+ code that manipulates syntax trees at
34
34
compile time.
35
35
36
36
Let's write a plugin
@@ -120,19 +120,16 @@ The advantages over a simple `fn(&str) -> u32` are:
120
120
121
121
In addition to procedural macros, you can define new
122
122
[ ` derive ` ] ( ../reference.html#derive ) -like attributes and other kinds of
123
- extensions. See
124
- [ ` Registry::register_syntax_extension ` ] ( ../rustc_plugin/registry/struct.Registry.html#method.register_syntax_extension )
125
- and the [ ` SyntaxExtension `
126
- enum] ( https://doc.rust-lang.org/syntax/ext/base/enum.SyntaxExtension.html ) . For
127
- a more involved macro example, see
123
+ extensions. See ` Registry::register_syntax_extension ` and the ` SyntaxExtension `
124
+ enum. For a more involved macro example, see
128
125
[ ` regex_macros ` ] ( https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs ) .
129
126
130
127
131
128
## Tips and tricks
132
129
133
130
Some of the [ macro debugging tips] ( macros.html#debugging-macro-code ) are applicable.
134
131
135
- You can use [ ` syntax::parse ` ] ( ../syntax/parse/index.html ) to turn token trees into
132
+ You can use ` syntax::parse ` to turn token trees into
136
133
higher-level syntax elements like expressions:
137
134
138
135
``` ignore
@@ -148,30 +145,21 @@ Looking through [`libsyntax` parser
148
145
code] ( https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs )
149
146
will give you a feel for how the parsing infrastructure works.
150
147
151
- Keep the [ ` Span ` s] ( ../syntax/codemap/struct.Span.html ) of
152
- everything you parse, for better error reporting. You can wrap
153
- [ ` Spanned ` ] ( ../syntax/codemap/struct.Spanned.html ) around
154
- your custom data structures.
155
-
156
- Calling
157
- [ ` ExtCtxt::span_fatal ` ] ( ../syntax/ext/base/struct.ExtCtxt.html#method.span_fatal )
158
- will immediately abort compilation. It's better to instead call
159
- [ ` ExtCtxt::span_err ` ] ( ../syntax/ext/base/struct.ExtCtxt.html#method.span_err )
160
- and return
161
- [ ` DummyResult ` ] ( ../syntax/ext/base/struct.DummyResult.html ) ,
162
- so that the compiler can continue and find further errors.
163
-
164
- To print syntax fragments for debugging, you can use
165
- [ ` span_note ` ] ( ../syntax/ext/base/struct.ExtCtxt.html#method.span_note ) together
166
- with
167
- [ ` syntax::print::pprust::*_to_string ` ] ( https://doc.rust-lang.org/syntax/print/pprust/index.html#functions ) .
168
-
169
- The example above produced an integer literal using
170
- [ ` AstBuilder::expr_usize ` ] ( ../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_usize ) .
148
+ Keep the ` Span ` s of everything you parse, for better error reporting. You can
149
+ wrap ` Spanned ` around your custom data structures.
150
+
151
+ Calling ` ExtCtxt::span_fatal ` will immediately abort compilation. It's better to
152
+ instead call ` ExtCtxt::span_err ` and return ` DummyResult ` so that the compiler
153
+ can continue and find further errors.
154
+
155
+ To print syntax fragments for debugging, you can use ` span_note ` together with
156
+ ` syntax::print::pprust::*_to_string ` .
157
+
158
+ The example above produced an integer literal using ` AstBuilder::expr_usize ` .
171
159
As an alternative to the ` AstBuilder ` trait, ` libsyntax ` provides a set of
172
- [ quasiquote macros] ( ../syntax/ext/quote/index.html ) . They are undocumented and
173
- very rough around the edges. However, the implementation may be a good
174
- starting point for an improved quasiquote as an ordinary plugin library.
160
+ quasiquote macros. They are undocumented and very rough around the edges.
161
+ However, the implementation may be a good starting point for an improved
162
+ quasiquote as an ordinary plugin library.
175
163
176
164
177
165
# Lint plugins
@@ -239,12 +227,11 @@ foo.rs:4 fn lintme() { }
239
227
240
228
The components of a lint plugin are:
241
229
242
- * one or more ` declare_lint! ` invocations, which define static
243
- [ ` Lint ` ] ( ../rustc/lint/struct.Lint.html ) structs;
230
+ * one or more ` declare_lint! ` invocations, which define static ` Lint ` structs;
244
231
245
232
* a struct holding any state needed by the lint pass (here, none);
246
233
247
- * a [ ` LintPass ` ] ( ../rustc/lint/trait.LintPass.html )
234
+ * a ` LintPass `
248
235
implementation defining how to check each syntax element. A single
249
236
` LintPass ` may call ` span_lint ` for several different ` Lint ` s, but should
250
237
register them all through the ` get_lints ` method.
0 commit comments