11
11
<!-- A plugin is a dynamic library crate with a designated *registrar* function that -->
12
12
<!-- registers extensions with `rustc`. Other crates can load these extensions using -->
13
13
<!-- the crate attribute `#![plugin(...)]`. See the -->
14
- <!-- [ `rustc_plugin`](../rustc_plugin/index.html) documentation for more about the -->
14
+ <!-- `rustc_plugin` documentation for more about the -->
15
15
<!-- mechanics of defining and loading a plugin. -->
16
16
プラグインとは ` rustc ` に拡張を登録するための、指定された * 登録用* 関数を持った動的ライブラリのクレートです。
17
17
他のクレートはこれらのプラグインを ` #![plugin(...)] ` クレートアトリビュートでロード出来ます。
18
- プラグインの定義、ロードの仕組みについて詳しくは[ ` rustc_plugin ` ] ( ../rustc_plugin/index.html ) を参照して下さい。
18
+ プラグインの定義、ロードの仕組みについて詳しくは ` rustc_plugin ` を参照して下さい。
19
19
20
20
<!-- If present, arguments passed as `#![plugin(foo(... args ...))]` are not -->
21
21
<!-- interpreted by rustc itself. They are provided to the plugin through the -->
22
- <!-- `Registry`'s [ `args` method](../rustc_plugin/registry/struct.Registry.html#method.args) . -->
22
+ <!-- `Registry`'s `args` method. -->
23
23
` #![plugin(foo(... args ...))] ` のように渡された引数があるなら、それらはrustc自身によっては解釈されません。
24
- ` Registry ` の[ ` args ` メソッド ] ( ../rustc_plugin/registry/struct.Registry.html#method.args ) を通じてプラグインに渡されます 。
24
+ ` Registry ` の` args ` メソッドを通じてプラグインに渡されます 。
25
25
26
26
<!-- In the vast majority of cases, a plugin should *only* be used through -->
27
27
<!-- `#![plugin]` and not through an `extern crate` item. Linking a plugin would -->
44
44
<!-- Plugins can extend Rust's syntax in various ways. One kind of syntax extension -->
45
45
<!-- is the procedural macro. These are invoked the same way as [ordinary -->
46
46
<!-- macros](macros.html), but the expansion is performed by arbitrary Rust -->
47
- <!-- code that manipulates [ syntax trees](../syntax/ast/index.html) at -->
47
+ <!-- code that manipulates syntax trees at -->
48
48
<!-- compile time. -->
49
49
プラグインはRustの構文を様々な方法で拡張出来ます。構文拡張の1つに手続的マクロがあります。
50
- これらは[ 普通のマクロ] ( macros.html ) と同じように実行されますが展開は任意の [ 構文木 ] ( ../syntax/ast/index.html ) をコンパイル時に操作するRustのコードが行います 。
50
+ これらは[ 普通のマクロ] ( macros.html ) と同じように実行されますが展開は任意の構文木をコンパイル時に操作するRustのコードが行います 。
51
51
52
52
<!-- Let's write a plugin -->
53
53
<!-- [`roman_numerals.rs`](https://github.com/rust-lang/rust/tree/master/src/test/auxiliary/roman_numerals.rs) -->
@@ -144,14 +144,11 @@ fn main() {
144
144
145
145
<!-- In addition to procedural macros, you can define new -->
146
146
<!-- [`derive`](../reference.html#derive)-like attributes and other kinds of -->
147
- <!-- extensions. See -->
148
- <!-- [`Registry::register_syntax_extension`](../rustc_plugin/registry/struct.Registry.html#method.register_syntax_extension) -->
149
- <!-- and the [`SyntaxExtension` -->
150
- <!-- enum](https://doc.rust-lang.org/syntax/ext/base/enum.SyntaxExtension.html). For -->
151
- <!-- a more involved macro example, see -->
147
+ <!-- extensions. See `Registry::register_syntax_extension` and the `SyntaxExtension` -->
148
+ <!-- enum. For a more involved macro example, see -->
152
149
<!-- [`regex_macros`](https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs). -->
153
150
手続き的マクロに加えて[ ` derive ` ] ( ../reference.html#derive ) ライクなアトリビュートや他の拡張を書けます。
154
- [ ` Registry::register_syntax_extension ` ] ( ../rustc_plugin/registry/struct.Registry.html#method.register_syntax_extension ) や [ ` SyntaxExtension ` 列挙型 ] ( https://doc.rust-lang.org/syntax/ext/base/enum.SyntaxExtension.html ) を参照して下さい 。
151
+ ` Registry::register_syntax_extension ` や ` SyntaxExtension ` 列挙型を参照して下さい 。
155
152
もっと複雑なマクロの例は[ ` regex_macros ` ] ( https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs ) を参照して下さい。
156
153
157
154
<!-- ## Tips and tricks -->
@@ -160,9 +157,9 @@ fn main() {
160
157
<!-- Some of the [macro debugging tips](macros.html#debugging-macro-code) are applicable. -->
161
158
[ マクロデバッグのヒント] ( macros.html#debugging-macro-code ) のいくつかが使えます。
162
159
163
- <!-- You can use [ `syntax::parse`](../syntax/parse/index.html) to turn token trees into -->
160
+ <!-- You can use `syntax::parse` to turn token trees into -->
164
161
<!-- higher-level syntax elements like expressions: -->
165
- [ ` syntax::parse ` ] ( ../syntax/parse/index.html ) を使うことでトークン木を式などの高レベルな構文要素に変換出来ます。
162
+ ` syntax::parse ` を使うことでトークン木を式などの高レベルな構文要素に変換出来ます。
166
163
167
164
``` ignore
168
165
fn expand_foo(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
@@ -178,37 +175,28 @@ fn expand_foo(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
178
175
<!-- will give you a feel for how the parsing infrastructure works. -->
179
176
[ ` libsyntax ` のパーサのコード] ( https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs ) を見るとパーサの基盤がどのように機能しているかを感られるでしょう。
180
177
181
- <!-- Keep the [`Span`s](../syntax/codemap/struct.Span.html) of -->
182
- <!-- everything you parse, for better error reporting. You can wrap -->
183
- <!-- [`Spanned`](../syntax/codemap/struct.Spanned.html) around -->
184
- <!-- your custom data structures. -->
185
- パースしたものの[ ` Span ` ] ( ../syntax/codemap/struct.Span.html ) は良いエラー報告のために保持しておきましょう。
186
- 自分で作ったデータ構造に対しても[ ` Spanned ` ] ( ../syntax/codemap/struct.Spanned.html ) でラップ出来ます。
187
-
188
- <!-- Calling -->
189
- <!-- [`ExtCtxt::span_fatal`](../syntax/ext/base/struct.ExtCtxt.html#method.span_fatal) -->
190
- <!-- will immediately abort compilation. It's better to instead call -->
191
- <!-- [`ExtCtxt::span_err`](../syntax/ext/base/struct.ExtCtxt.html#method.span_err) -->
192
- <!-- and return -->
193
- <!-- [`DummyResult`](../syntax/ext/base/struct.DummyResult.html), -->
194
- <!-- so that the compiler can continue and find further errors. -->
195
- [ ` ExtCtxt::span_fatal ` ] ( ../syntax/ext/base/struct.ExtCtxt.html#method.span_fatal ) を呼ぶとコンパイルは即座に中断されます。
196
- [ ` ExtCtxt::span_err ` ] ( ../syntax/ext/base/struct.ExtCtxt.html#method.span_err ) を呼んで[ ` DummyResult ` ] ( ../syntax/ext/base/struct.DummyResult.html ) を返せばコンパイラはさらなるエラーを発見できるのでその方が良いでしょう。
197
-
198
- <!-- To print syntax fragments for debugging, you can use -->
199
- <!-- [`span_note`](../syntax/ext/base/struct.ExtCtxt.html#method.span_note) together -->
200
- <!-- with -->
201
- <!-- [`syntax::print::pprust::* _to_string`](https://doc.rust-lang.org/syntax/print/pprust/index.html#functions). -->
202
- 構文の断片を表示するには[ ` span_note ` ] ( ../syntax/ext/base/struct.ExtCtxt.html#method.span_note ) と[ ` syntax::print::pprust::*_to_string ` ] ( https://doc.rust-lang.org/syntax/print/pprust/index.html#functions ) を使えば出来ます。
203
-
204
- <!-- The example above produced an integer literal using -->
205
- <!-- [`AstBuilder::expr_usize`](../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_usize). -->
178
+ <!-- Keep the `Span`s of everything you parse, for better error reporting. You can -->
179
+ <!-- wrap `Spanned` around your custom data structures. -->
180
+ パースしたものの ` Span ` は良いエラー報告のために保持しておきましょう。
181
+ 自分で作ったデータ構造に対しても ` Spanned ` でラップ出来ます。
182
+
183
+ <!-- Calling `ExtCtxt::span_fatal` will immediately abort compilation. It's better to -->
184
+ <!-- instead call `ExtCtxt::span_err` and return `DummyResult` so that the compiler -->
185
+ <!-- can continue and find further errors. -->
186
+ ` ExtCtxt::span_fatal ` を呼ぶとコンパイルは即座に中断されます。
187
+ ` ExtCtxt::span_err ` を呼んで ` DummyResult ` を返せばコンパイラはさらなるエラーを発見できるのでその方が良いでしょう。
188
+
189
+ <!-- To print syntax fragments for debugging, you can use `span_note` together with -->
190
+ <!-- `syntax::print::pprust::*_to_string`. -->
191
+ 構文の断片を表示するには ` span_note ` と ` syntax::print::pprust::*_to_string ` を使えば出来ます。
192
+
193
+ <!-- The example above produced an integer literal using `AstBuilder::expr_usize`. -->
206
194
<!-- As an alternative to the `AstBuilder` trait, `libsyntax` provides a set of -->
207
- <!-- [ quasiquote macros](../syntax/ext/quote/index.html). They are undocumented and -->
208
- <!-- very rough around the edges. However, the implementation may be a good -->
209
- <!-- starting point for an improved quasiquote as an ordinary plugin library. -->
210
- 上記の例では[ ` AstBuilder::expr_usize ` ] ( ../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_usize ) を使って整数リテラルを作りました。
211
- ` AstBuilder ` トレイトの代替として ` libsyntax ` は [ 準クォート ] ( ../syntax/ext/quote/index.html ) マクロを提供しています 。
195
+ <!-- quasiquote macros. They are undocumented and very rough around the edges. -->
196
+ <!-- However, the implementation may be a good starting point for an improved -->
197
+ <!-- quasiquote as an ordinary plugin library. -->
198
+ 上記の例では ` AstBuilder::expr_usize ` を使って整数リテラルを作りました。
199
+ ` AstBuilder ` トレイトの代替として ` libsyntax ` は準クォートマクロを提供しています 。
212
200
ドキュメントがない上に荒削りです。しかしながらその実装は改良版の普通のプラグインライブラリのとっかかりにはほど良いでしょう。
213
201
214
202
<!-- # Lint plugins -->
@@ -284,18 +272,17 @@ foo.rs:4 fn lintme() { }
284
272
<!-- The components of a lint plugin are: -->
285
273
構文チェックプラグインのコンポーネントは
286
274
287
- <!-- * one or more `declare_lint!` invocations, which define static -->
288
- <!-- [`Lint`](../rustc/lint/struct.Lint.html) structs; -->
289
- * 1回以上の ` declare_lint! ` の実行。それによって[ ` Lint ` ] ( ../rustc/lint/struct.Lint.html ) 構造体が定義されます。
275
+ <!-- * one or more `declare_lint!` invocations, which define static `Lint` structs; -->
276
+ * 1回以上の ` declare_lint! ` の実行。それによって ` Lint ` 構造体が定義されます。
290
277
291
278
<!-- * a struct holding any state needed by the lint pass (here, none); -->
292
279
* 構文チェックパスで必要となる状態を保持する構造体(ここでは何もない)
293
280
294
- <!-- * a [ `LintPass`](../rustc/lint/trait.LintPass.html) -->
281
+ <!-- * a `LintPass` -->
295
282
<!-- implementation defining how to check each syntax element. A single -->
296
283
<!-- `LintPass` may call `span_lint` for several different `Lint`s, but should -->
297
284
<!-- register them all through the `get_lints` method. -->
298
- * それぞれの構文要素をどうやってチェックするかを定めた[ ` LintPass ` ] ( ../rustc/lint/trait.LintPass.html ) の実装。
285
+ * それぞれの構文要素をどうやってチェックするかを定めた ` LintPass ` の実装。
299
286
単一の ` LintPass ` は複数回 ` span_lint ` をいくつかの異なる ` Lint ` に対して呼ぶかもしれませんが、全て ` get_lints ` を通じて登録すべきです。
300
287
301
288
<!-- Lint passes are syntax traversals, but they run at a late stage of compilation -->
0 commit comments