Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14f282c

Browse files
committed
Translate into japanese(19 Sigils)
1 parent 9dc5b11 commit 14f282c

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

getting_started/19.markdown

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
---
22
layout: getting_started
3-
title: 19 Sigils
3+
title: 19 シギル(印) - Sigils
44
guide: 19
55
---
66

77
# {{ page.title }}
88

99
<div class="toc"></div>
1010

11+
ダブルクォートでくくられた文字列とシングルクォートでくくられた文字のリストをElixirが提供していることはすでに学びましたね.しかしこれはこの言語の文字表現の構造を表面的にカバーしただけです.他の構造物,例えばアトムは,`:atom`という表現で作られます.
12+
1113
We have already learned Elixir provides double-quoted strings and single-quoted char lists. However, this only covers the surface of structures that have textual representation in the language. Atoms are, for example, another structure which are mostly created via the `:atom` representation.
1214

15+
Elixirの目標の一つに拡張性があります: 開発者は目的のドメインに応じて言語を拡張できるべきです.コンピューターサイエンスでは言語のコアとなる部分だけで対処するのは不可能なほど沢山の広い領域を扱います.そこで,最善の策として言語を拡張できるように作りました,開発者や企業やコミュニティは関わっているドメインに応じて言語を拡張できます.
16+
1317
One of Elixir's goals is extensibility: developers should be able to extend the language to particular domains. Computer science has become such a wide field that it is impossible for a language to tackle many fields as part of its core. Our best bet is to rather make the language extensible, so developers, companies and communities can extend the language to their relevant domains.
1418

19+
この章では,言語によって提供されている機能で,文字表現として動作するシギルについて調べていきます.
20+
1521
In the chapter, we are going to explore sigils, which are one of the mechanisms provided by the language for working with textual representations.
1622

17-
## 19.1 Regular expressions
23+
## 19.1 正規表現 - Regular expressions
24+
25+
シギルは波(`~`)文字から始まり次に文字,その次にセパレータと続きます.Elixirで一番よく使われているシギルは[正規表現](https://en.wikipedia.org/wiki/Regular_Expressions)のための`~r`です:
1826

1927
Sigils start with the tilde (`~`) character which is followed by a letter and then a separator. The most common sigil in Elixir is `~r` for [regular expressions](https://en.wikipedia.org/wiki/Regular_Expressions):
2028

@@ -28,6 +36,8 @@ iex> "bat" =~ regex
2836
false
2937
```
3038

39+
Elixirは[PCRE](http://www.pcre.org/)ライブラリで実装されているPerl互換正規表現(regexes)を提供しています.正規表現はモディファイヤもサポートしています.例えば`i`モディファイヤを使うと正規表現の大小文字を区別しません:
40+
3141
Elixir provides Perl-compatible regular expressions (regexes), as implemented by the [PCRE](http://www.pcre.org/) library. Regexes also support modifiers. For example, the `i` modifier makes a regular expression case insensitive:
3242

3343
```iex
@@ -37,8 +47,12 @@ iex> "HELLO" =~ ~r/hello/i
3747
true
3848
```
3949

50+
正規表現でサポートしている他のモディファイアや演算子については[`Regex`モジュール](/docs/stable/elixir/Regex.html)を見てください.
51+
4052
Check out the [`Regex` module](/docs/stable/elixir/Regex.html) for more information on other modifiers and the supported operations with regular expressions.
4153

54+
ここまで,正規表現の全ての例では`/`を区切りとして使っていました.しかしシギルでは8つの別のセパレータをサポートしています:
55+
4256
So far, all examples have used `/` to delimit a regular expression. However sigils support 8 different separators:
4357

4458
```
@@ -52,40 +66,54 @@ So far, all examples have used `/` to delimit a regular expression. However sigi
5266
~r<hello>
5367
```
5468

69+
異なる演算子をサポートした理由は異なるシギルで便利に使えるようにするためです.例えば,正規表現を区切るのに括弧を使うと正規表現の中にある括弧と混じってしまい混乱を招きます.しかし次の章で見るように,括弧は他のシギルにおいては便利です.
70+
5571
The reasoning in supporting different operators is that different separators can be more convenient to different sigils. For example, using parentheses for regular expressions may be a confusing choice as they can get mixed with the parentheses inside the regex. However, parentheses can be handy for other sigils, as we will see in the next section.
5672

57-
## 19.2 Strings, char lists and words sigils
73+
## 19.2 文字列,文字リストして語句のシギル - Strings, char lists and words sigils
74+
75+
正規表現に加えて,Elixirはその他に3つのシギルを提供しています.
5876

5977
Besides regular expressions, Elixir ships with three other sigils.
6078

79+
`~s`シギルは文字列を生成するのに使われ,ダブルクォートするのに似ています:
80+
6181
The `~s` sigil is used to generate strings, similar to double quotes:
6282

6383
```iex
6484
iex> ~s(this is a string with "quotes")
6585
"this is a string with \"quotes\""
6686
```
6787

88+
`~c`シギルは文字リストを生成するのに使われます:
89+
6890
While `~c` is used to generate char lists:
6991

7092
```iex
7193
iex> ~c(this is a string with "quotes")
7294
'this is a string with "quotes"'
7395
```
7496

97+
`~w`シギルはスペースで区切られた語句からリストを生成するのに使われます:
98+
7599
The `~w` sigil is used to generate a list of words separated by white space:
76100

77101
```iex
78102
iex> ~w(foo bar bat)
79103
["foo", "bar", "bat"]
80104
```
81105

106+
`~w`シギルは結果のフォーマットを選ぶのに`c``s``a`モディファイア(それぞれ文字リスト`char list`,文字列`s`,アトム`a`に対応)を受けつけます:
107+
82108
The `~w` sigil also accepts the `c`, `s` and `a` modifiers (for char lists, strings and atoms, respectively) to choose the format of the result:
83109

84110
```iex
85111
iex> ~w(foo bar bat)a
86112
[:foo, :bar, :bat]
87113
```
88114

115+
小文字でのシギルに加えて,Elixirは大文字のシギルにも対応しています.`~s``~S`どちらも文字列を返し,はじめのものはエスケープコードや文字列の挿入ができ,二番目のものはできません:
116+
89117
Besides lowercase sigils, Elixir supports uppercase sigils. While both `~s` and `~S` will return strings, the first one allows escape codes and interpolation while the second does not:
90118

91119
```elixir
@@ -95,8 +123,27 @@ iex> ~S(String without escape codes and without #{interpolation})
95123
"String without escape codes and without \#{interpolation}"
96124
```
97125

126+
以下のエスケープコードは文字列と文字リストで使うことができます:
127+
98128
The following escape codes can be used in strings and char lists:
99129

130+
* `\"` – ダブルクォート
131+
* `\'` – シングルクォート
132+
* `\\` – バックスラッシュ
133+
* `\a` – ベル/アラート
134+
* `\b` – バックスペース
135+
* `\d` - 削除
136+
* `\e` - エスケープ
137+
* `\f` - フォームフィード
138+
* `\n` – 新しいライン
139+
* `\r` – キャリッジリターン
140+
* `\s` – スペース
141+
* `\t` – タブ
142+
* `\v` – 垂直タブ
143+
* `\DDD`, `\DD`, `\D` - 8進数での文字表現 DDD, DD か D (例: `\377`)
144+
* `\xDD` - 16進数での文字表現 DD (例: `\x13`)
145+
* `\x{D...}` - 1から複数桁の16進数での文字表現 (例: `\x{abc13}`)
146+
100147
* `\"` – double quote
101148
* `\'` – single quote
102149
* `\\` – single backslash
@@ -114,6 +161,8 @@ The following escape codes can be used in strings and char lists:
114161
* `\xDD` - character with hexadecimal representation DD (example: `\x13`)
115162
* `\x{D...}` - character with hexadecimal representation with one or more hexadecimal digits (example: `\x{abc13}`)
116163

164+
シギルは3つ連続したダブル/シングルクォートで区切られたヒアドキュメントにも対応しています:
165+
117166
Sigils also support heredocs, which is when triple double- or single-quotes are used as separators:
118167

119168
```iex
@@ -123,6 +172,8 @@ iex> ~s"""
123172
...> """
124173
```
125174

175+
ドキュメントを書くときにシギルのヒアドキュメントが良く使われます.例えばドキュメントの中でエスケープ文字を書きたい場合,いくつかの文字で二重にエスケープが必要になるためミスしやすいです.
176+
126177
The most common case for heredoc sigils is when writing documentation. For example, if you need to write escape characters in your documentation, it can become error prone as we would need to double-escape some characters:
127178

128179
```elixir
@@ -138,6 +189,8 @@ Converts double-quotes to single-quotes.
138189
def convert(...)
139190
```
140191

192+
しかし`~S`を使えば,問題を完全に避けられます:
193+
141194
By using using `~S`, we can avoid this problem altogether:
142195
143196
```elixir
@@ -153,7 +206,9 @@ Converts double-quotes to single-quotes.
153206
def convert(...)
154207
```
155208

156-
## 19.3 Custom sigils
209+
## 19.3 カスタムシギル - Custom sigils
210+
211+
この章の最初に示唆したように,Elixirでのシギルは拡張可能です.実際,シギル`~r/foo/i`は関数`sigil_r`を2つの引数と共に呼び出しているのと同じことをしています:
157212

158213
As hinted at the beginning of this chapter, sigils in Elixir are extensible. In fact, the sigil `~r/foo/i` is equivalent to calling the `sigil_r` function with two arguments:
159214

@@ -162,13 +217,17 @@ iex> sigil_r(<<"foo">>, 'i')
162217
~r"foo"i
163218
```
164219

220+
つまり,`~r`シギルについてのドキュメントは関数`sigil_r`を通じてアクセスすることができます:
221+
165222
That said, we can access the documentation for the `~r` sigil via the `sigil_r` function:
166223

167224
```iex
168225
iex> h sigil_r
169226
...
170227
```
171228

229+
自分達のシギルを特定の関数を実装することで用意できます.例えば数値が返る`~i(13)`シギルを実装してみましょう:
230+
172231
We can also provide our own sigils by simply implementing the proper function. For example, let's implement the `~i(13)` sigil that returns an integer:
173232
174233
```iex
@@ -180,4 +239,6 @@ iex> ~i(13)
180239
13
181240
```
182241
242+
シギルはマクロの助けを借りてコンパイル時に使われることもできます.例えばElixirの正規表現はソースコードのコンパル時に効率のよい形へとコンパイルされます,そうすると動作時にそのステップを省略できます.もしこの内容に興味があるなら,マクロについてもっと知り,`Kernel`モジュールでシギルがどうやって実装されているか調べてみることをおすすめします.
243+
183244
Sigils can also be used to do compile-time work with the help of macros. For example, regular expressions in Elixir are compiled into efficient representation during compilation of the source code, therefore skipping this step at runtime. If you have interest in the subject, we recommend you to learn more about macros and check how those sigils are implemented in the `Kernel` module.

0 commit comments

Comments
 (0)