Skip to content

Commit e2cb18a

Browse files
authored
Merge pull request #191 from KeenS/1.9-compiler-plugins
6.1 Compiler Plugins
2 parents 7bed58e + 828fb84 commit e2cb18a

File tree

2 files changed

+36
-159
lines changed

2 files changed

+36
-159
lines changed

1.9/ja/book/compiler-plugins.md

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
<!-- A plugin is a dynamic library crate with a designated *registrar* function that -->
1212
<!-- registers extensions with `rustc`. Other crates can load these extensions using -->
1313
<!-- 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 -->
1515
<!-- mechanics of defining and loading a plugin. -->
1616
プラグインとは `rustc` に拡張を登録するための、指定された *登録用* 関数を持った動的ライブラリのクレートです。
1717
他のクレートはこれらのプラグインを `#![plugin(...)]` クレートアトリビュートでロード出来ます。
18-
プラグインの定義、ロードの仕組みについて詳しくは[`rustc_plugin`](../rustc_plugin/index.html)を参照して下さい。
18+
プラグインの定義、ロードの仕組みについて詳しくは `rustc_plugin` を参照して下さい。
1919

2020
<!-- If present, arguments passed as `#![plugin(foo(... args ...))]` are not -->
2121
<!-- 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. -->
2323
`#![plugin(foo(... args ...))]` のように渡された引数があるなら、それらはrustc自身によっては解釈されません。
24-
`Registry`[`args` メソッド](../rustc_plugin/registry/struct.Registry.html#method.args)を通じてプラグインに渡されます
24+
`Registry``args` メソッドを通じてプラグインに渡されます
2525

2626
<!-- In the vast majority of cases, a plugin should *only* be used through -->
2727
<!-- `#![plugin]` and not through an `extern crate` item. Linking a plugin would -->
@@ -44,10 +44,10 @@
4444
<!-- Plugins can extend Rust's syntax in various ways. One kind of syntax extension -->
4545
<!-- is the procedural macro. These are invoked the same way as [ordinary -->
4646
<!-- 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 -->
4848
<!-- compile time. -->
4949
プラグインはRustの構文を様々な方法で拡張出来ます。構文拡張の1つに手続的マクロがあります。
50-
これらは[普通のマクロ](macros.html)と同じように実行されますが展開は任意の[構文木](../syntax/ast/index.html)をコンパイル時に操作するRustのコードが行います
50+
これらは[普通のマクロ](macros.html)と同じように実行されますが展開は任意の構文木をコンパイル時に操作するRustのコードが行います
5151

5252
<!-- Let's write a plugin -->
5353
<!-- [`roman_numerals.rs`](https://github.com/rust-lang/rust/tree/master/src/test/auxiliary/roman_numerals.rs) -->
@@ -144,14 +144,11 @@ fn main() {
144144

145145
<!-- In addition to procedural macros, you can define new -->
146146
<!-- [`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 -->
152149
<!-- [`regex_macros`](https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs). -->
153150
手続き的マクロに加えて[`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` 列挙型を参照して下さい
155152
もっと複雑なマクロの例は[`regex_macros`](https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs)を参照して下さい。
156153

157154
<!-- ## Tips and tricks -->
@@ -160,9 +157,9 @@ fn main() {
160157
<!-- Some of the [macro debugging tips](macros.html#debugging-macro-code) are applicable. -->
161158
[マクロデバッグのヒント](macros.html#debugging-macro-code)のいくつかが使えます。
162159

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 -->
164161
<!-- higher-level syntax elements like expressions: -->
165-
[`syntax::parse`](../syntax/parse/index.html)を使うことでトークン木を式などの高レベルな構文要素に変換出来ます。
162+
`syntax::parse`を使うことでトークン木を式などの高レベルな構文要素に変換出来ます。
166163

167164
```ignore
168165
fn expand_foo(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
@@ -178,37 +175,28 @@ fn expand_foo(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
178175
<!-- will give you a feel for how the parsing infrastructure works. -->
179176
[`libsyntax` のパーサのコード](https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs)を見るとパーサの基盤がどのように機能しているかを感られるでしょう。
180177

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`. -->
206194
<!-- 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` は準クォートマクロを提供しています
212200
ドキュメントがない上に荒削りです。しかしながらその実装は改良版の普通のプラグインライブラリのとっかかりにはほど良いでしょう。
213201

214202
<!-- # Lint plugins -->
@@ -284,18 +272,17 @@ foo.rs:4 fn lintme() { }
284272
<!-- The components of a lint plugin are: -->
285273
構文チェックプラグインのコンポーネントは
286274

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` 構造体が定義されます。
290277

291278
<!-- * a struct holding any state needed by the lint pass (here, none); -->
292279
* 構文チェックパスで必要となる状態を保持する構造体(ここでは何もない)
293280

294-
<!-- * a [`LintPass`](../rustc/lint/trait.LintPass.html) -->
281+
<!-- * a `LintPass` -->
295282
<!-- implementation defining how to check each syntax element. A single -->
296283
<!-- `LintPass` may call `span_lint` for several different `Lint`s, but should -->
297284
<!-- register them all through the `get_lints` method. -->
298-
* それぞれの構文要素をどうやってチェックするかを定めた[`LintPass`](../rustc/lint/trait.LintPass.html)の実装。
285+
* それぞれの構文要素をどうやってチェックするかを定めた `LintPass` の実装。
299286
単一の `LintPass` は複数回 `span_lint` をいくつかの異なる `Lint` に対して呼ぶかもしれませんが、全て `get_lints`を通じて登録すべきです。
300287

301288
<!-- Lint passes are syntax traversals, but they run at a late stage of compilation -->

diff-1.6.0..1.9.0/src/doc/book/compiler-plugins.md

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)