@@ -378,10 +378,12 @@ LOG(state)
378
378
379
379
``` text
380
380
const char *state = "reticulating splines";
381
- int state = get_log_state();
382
- if (state > 0) {
383
- printf("log(%d): %s\n", state, state);
384
- }
381
+ {
382
+ int state = get_log_state();
383
+ if (state > 0) {
384
+ printf("log(%d): %s\n", state, state);
385
+ }
386
+ }
385
387
```
386
388
387
389
<!-- The second variable named `state` shadows the first one. This is a problem -->
@@ -437,10 +439,9 @@ fn main() {
437
439
}
438
440
```
439
441
440
- <!-- Instead you need to pass the variable name into the invocation, so it’s tagged -->
441
- <!-- with the right syntax context. -->
442
- 代わりに変数名を呼出時に渡す必要があります、
443
- 呼出時に渡す事で正しい構文コンテキストでタグ付けされます。
442
+ <!-- Instead you need to pass the variable name into the invocation, so that it’s -->
443
+ <!-- tagged with the right syntax context. -->
444
+ 呼出時に渡す事で正しい構文コンテキストでタグ付けされるように、代わりに変数名を呼出時に渡す必要があります。
444
445
445
446
``` rust
446
447
macro_rules! foo {
@@ -613,7 +614,7 @@ Rustはこの曖昧性を判定するために単純なルールを利用しま
613
614
<!-- * `ty`: a type. Examples: `i32`; `Vec<(char, String)>`; `&T`. -->
614
615
<!-- * `pat`: a pattern. Examples: `Some(t)`; `(17, 'a')`; `_`. -->
615
616
<!-- * `stmt`: a single statement. Example: `let x = 3`. -->
616
- <!-- * `block`: a brace-delimited sequence of statements. Example: -->
617
+ <!-- * `block`: a brace-delimited sequence of statements and optionally an expression . Example: -->
617
618
<!-- `{ log(error, "hi"); return 12; }`. -->
618
619
<!-- * `item`: an [item][item]. Examples: `fn foo() { }`; `struct Bar;`. -->
619
620
<!-- * `meta`: a "meta item", as found in attributes. Example: `cfg(target_os = "windows")`. -->
@@ -624,37 +625,37 @@ Rustはこの曖昧性を判定するために単純なルールを利用しま
624
625
* ` ty ` : 型。 例: ` i32 ` ; ` Vec<(char, String)> ` ; ` &T `
625
626
* ` pat ` : パターン。 例: ` Some(t) ` ; ` (17, 'a') ` ; ` _ `
626
627
* ` stmt ` : 単一の文。 例: ` let x = 3 `
627
- * ` block ` : 波括弧で区切られた文のシーケンス 。 例: ` { log(error, "hi"); return 12 } `
628
+ * ` block ` : 波括弧で区切られた文のシーケンスと場合によっては式も付く 。 例: ` { log(error, "hi"); return 12 } `
628
629
* ` item ` : [ アイテム] [ item ] 。 例: ` fn foo() { } ` ; ` struct Bar; `
629
630
* ` meta ` : アトリビュートで見られるような「メタアイテム」。 例: ` cfg(target_os = "windows") `
630
631
* ` tt ` : 単一のトークンの木
631
632
632
633
<!-- There are additional rules regarding the next token after a metavariable: -->
633
634
またメタ変数の次のトークンについて以下のルールが存在します:
634
635
635
- <!-- * `expr` variables may only be followed by one of: `=> , ;` -->
636
- <!-- * `ty` and `path` variables may only be followed by one of: `=> , : = > as ` -->
637
- <!-- * `pat` variables may only be followed by one of: `=> , = if in` -->
636
+ <!-- * `expr` and `stmt` variables may only be followed by one of: `=> , ;` -->
637
+ <!-- * `ty` and `path` variables may only be followed by one of: `=> , = | ; : > [ { as where ` -->
638
+ <!-- * `pat` variables may only be followed by one of: `=> , = | if in` -->
638
639
<!-- * Other variables may be followed by any token. -->
639
- * ` expr ` 変数は ` => , ; ` のどれか一つのみが次に現れます
640
- * ` ty ` と ` path ` 変数は ` => , : = > as ` のどれか一つのみが次に現れます
641
- * ` pat ` 変数は ` => , = if in ` のどれか一つのみが次に現れます
640
+ * ` expr ` 変数と ` stmt ` 変数は ` => , ; ` のどれか一つのみが次に現れます
641
+ * ` ty ` と ` path ` 変数は ` => , = | ; : > [ { as where ` のどれか一つのみが次に現れます
642
+ * ` pat ` 変数は ` => , = | if in ` のどれか一つのみが次に現れます
642
643
* その他の変数は任意のトークンが次に現れます
643
644
644
645
<!-- These rules provide some flexibility for Rust’s syntax to evolve without -->
645
646
<!-- breaking existing macros. -->
646
647
これらのルールは既存のマクロを破壊すること無くRustの構文を拡張するための自由度を与えます。
647
648
648
649
<!-- The macro system does not deal with parse ambiguity at all. For example, the -->
649
- <!-- grammar `$($t:ty )* $e:expr` will always fail to parse, because the parser would -->
650
- <!-- be forced to choose between parsing `$t ` and parsing `$e`. Changing the -->
650
+ <!-- grammar `$($i:ident )* $e:expr` will always fail to parse, because the parser would -->
651
+ <!-- be forced to choose between parsing `$i ` and parsing `$e`. Changing the -->
651
652
<!-- invocation syntax to put a distinctive token in front can solve the problem. In -->
652
- <!-- this case, you can write `$(T $t:ty )* E $e:exp `. -->
653
+ <!-- this case, you can write `$(I $i:ident )* E $e:expr `. -->
653
654
マクロシステムはパースの曖昧さについては何も対処しません。
654
- 例えば、 ` $($t:ty )* $e:expr ` は常にパースが失敗します、
655
- なぜならパーサーは ` $t ` をパースするか、 ` $e ` をパースするかを選ぶことを強制されるためです。
655
+ 例えば、 ` $($i:ident )* $e:expr ` は常にパースが失敗します、
656
+ なぜならパーサーは ` $i ` をパースするか、 ` $e ` をパースするかを選ぶことを強制されるためです。
656
657
呼出構文を変更して識別可能なトークンを先頭につけることでこの問題は回避することができます。
657
- そのようにする場合、例えば ` $(T $t:ty )* E $e:exp ` のように書くことができます。
658
+ そのようにする場合、例えば ` $(I $i:ident )* E $e:expr ` のように書くことができます。
658
659
659
660
[ item ] : ../reference.html#items
660
661
@@ -821,10 +822,9 @@ macro_rules! inc {
821
822
822
823
823
824
<!-- To keep this system simple and correct, `#[macro_use] extern crate ...` may -->
824
- <!-- only appear at the root of your crate, not inside `mod`. This ensures that -->
825
- <!-- `$crate` is a single identifier. -->
825
+ <!-- only appear at the root of your crate, not inside `mod`. -->
826
826
このシステムを簡潔で正しく保つために、 ` #[macro_use] extern crate ... ` はクレートのルートにしか登場せず、
827
- ` mod ` の中には現れません。これは ` $crate ` が単一の識別子を持つことを確実にします。
827
+ ` mod ` の中には現れません。
828
828
829
829
830
830
<!-- # The deep end -->
0 commit comments