@@ -9,13 +9,14 @@ use crate::foundations::{
9
9
cast, func, repr, scope, ty, Array , Dict , FromValue , IntoValue , Repr , Str , Value ,
10
10
} ;
11
11
12
- /// Captured arguments to a function.
12
+ /// 関数に渡される引数。
13
13
///
14
- /// # Argument Sinks
15
- /// Like built-in functions, custom functions can also take a variable number of
16
- /// arguments. You can specify an _argument sink_ which collects all excess
17
- /// arguments as `..sink`. The resulting `sink` value is of the `arguments`
18
- /// type. It exposes methods to access the positional and named arguments.
14
+ /// # 引数シンク
15
+ /// 組み込み関数と同様に、カスタム関数も可変個の引数を受け取れます。
16
+ /// 余分にある引数をすべてまとめて受け取る_引数シンク_(キッチンシンクのようにさまざまなも
17
+ /// のが流れ込む先) は、`..sink`の形で指定できます。このとき生成される`sink`の値は
18
+ /// `arguments`型になります。この型は、位置引数と名前付き引数の両方にアクセスするための
19
+ /// メソッドを提供しています。
19
20
///
20
21
/// ```example
21
22
/// #let format(title, ..authors) = {
@@ -29,9 +30,9 @@ use crate::foundations::{
29
30
/// #format("ArtosFlow", "Jane", "Joe")
30
31
/// ```
31
32
///
32
- /// # Spreading
33
- /// Inversely to an argument sink, you can _spread_ arguments, arrays and
34
- /// dictionaries into a function call with the `..spread` operator:
33
+ /// # 引数の展開
34
+ /// 引数シンクとは逆に、`..spread`演算子を使うと、を関数呼び出しにおいて引数や配列、
35
+ /// 辞書を展開して渡すことができます。
35
36
///
36
37
/// ```example
37
38
/// #let array = (2, 3, 5)
@@ -43,15 +44,15 @@ use crate::foundations::{
43
44
#[ derive( Clone , Hash ) ]
44
45
#[ allow( clippy:: derived_hash_with_manual_eq) ]
45
46
pub struct Args {
46
- /// The callsite span for the function. This is not the span of the argument
47
- /// list itself, but of the whole function call.
47
+ /// 関数呼び出し箇所のスパン。これは引数リスト自体のスパンではなく、
48
+ /// 関数呼び出し全体のものです。
48
49
pub span : Span ,
49
50
/// The positional and named arguments.
50
51
pub items : EcoVec < Arg > ,
51
52
}
52
53
53
54
impl Args {
54
- /// Create positional arguments from a span and values.
55
+ /// スパンと値から位置引数を作成します。
55
56
pub fn new < T : IntoValue > ( span : Span , values : impl IntoIterator < Item = T > ) -> Self {
56
57
let items = values
57
58
. into_iter ( )
@@ -64,20 +65,20 @@ impl Args {
64
65
Self { span, items }
65
66
}
66
67
67
- /// Attach a span to these arguments if they don't already have one.
68
+ /// 引数にスパンがアタッチされていない場合はアタッチします。
68
69
pub fn spanned ( mut self , span : Span ) -> Self {
69
70
if self . span . is_detached ( ) {
70
71
self . span = span;
71
72
}
72
73
self
73
74
}
74
75
75
- /// Returns the number of remaining positional arguments.
76
+ /// 残りの位置引数の個数を返します。
76
77
pub fn remaining ( & self ) -> usize {
77
78
self . items . iter ( ) . filter ( |slot| slot. name . is_none ( ) ) . count ( )
78
79
}
79
80
80
- /// Insert a positional argument at a specific index.
81
+ /// 指定したインデックスに一引数を挿入します。
81
82
pub fn insert ( & mut self , index : usize , span : Span , value : Value ) {
82
83
self . items . insert (
83
84
index,
@@ -89,7 +90,7 @@ impl Args {
89
90
)
90
91
}
91
92
92
- /// Push a positional argument.
93
+ /// 位置引数をプッシュします。
93
94
pub fn push ( & mut self , span : Span , value : Value ) {
94
95
self . items . push ( Arg {
95
96
span : self . span ,
@@ -98,7 +99,7 @@ impl Args {
98
99
} )
99
100
}
100
101
101
- /// Consume and cast the first positional argument if there is one.
102
+ /// 最初の位置引数がある場合、それを取り出してキャストします。
102
103
pub fn eat < T > ( & mut self ) -> SourceResult < Option < T > >
103
104
where
104
105
T : FromValue < Spanned < Value > > ,
@@ -113,7 +114,7 @@ impl Args {
113
114
Ok ( None )
114
115
}
115
116
116
- /// Consume n positional arguments if possible.
117
+ /// 可能ならn個数の位置引数を取り出します。
117
118
pub fn consume ( & mut self , n : usize ) -> SourceResult < Vec < Arg > > {
118
119
let mut list = vec ! [ ] ;
119
120
@@ -133,10 +134,9 @@ impl Args {
133
134
Ok ( list)
134
135
}
135
136
136
- /// Consume and cast the first positional argument.
137
+ /// 最初の位置引数を取り出してキャストする。
137
138
///
138
- /// Returns a `missing argument: {what}` error if no positional argument is
139
- /// left.
139
+ /// 位置変数が残っていなければ、`missing argument: {what}`エラーを返します。
140
140
pub fn expect < T > ( & mut self , what : & str ) -> SourceResult < T >
141
141
where
142
142
T : FromValue < Spanned < Value > > ,
@@ -147,7 +147,7 @@ impl Args {
147
147
}
148
148
}
149
149
150
- /// The error message for missing arguments.
150
+ /// 引数が足りない場合のエラーメッセージ。
151
151
fn missing_argument ( & self , what : & str ) -> SourceDiagnostic {
152
152
for item in & self . items {
153
153
let Some ( name) = item. name . as_deref ( ) else { continue } ;
@@ -295,9 +295,9 @@ impl Args {
295
295
296
296
#[ scope]
297
297
impl Args {
298
- /// Construct spreadable arguments in place.
298
+ /// 展開可能な引数をその場で生成します。
299
299
///
300
- /// This function behaves like `{let args(..sink) = sink}`.
300
+ /// この関数は、 `{let args(..sink) = sink}`のように動作します。
301
301
///
302
302
/// ```example
303
303
/// #let args = arguments(stroke: red, inset: 1em, [Body])
@@ -306,27 +306,26 @@ impl Args {
306
306
#[ func( constructor) ]
307
307
pub fn construct (
308
308
args : & mut Args ,
309
- /// The arguments to construct.
309
+ /// 作成する引数。
310
310
#[ external]
311
311
#[ variadic]
312
312
arguments : Vec < Value > ,
313
313
) -> Args {
314
314
args. take ( )
315
315
}
316
316
317
- /// Returns the positional argument at the specified index, or the named
318
- /// argument with the specified name.
317
+ /// 指定したインデックスの位置引数、または指定した名前の名前つき引数を返します。
319
318
///
320
- /// If the key is an [integer ]($int), this is equivalent to first calling
321
- /// [`pos`]($arguments.pos) and then [` array.at`]. If it is a [string ]($str),
322
- /// this is equivalent to first calling [`named`]($arguments.named) and then
323
- /// [`dictionary.at`].
319
+ /// キーが[整数型 ]($int)の場合、それはまず[`pos`]($arguments.pos)メソッドを呼んでから、
320
+ /// 次に[` array.at`]を呼ぶのと同等です。キーが[文字列型 ]($str)である場合、
321
+ /// まず [`named`]($arguments.named)メソッドを呼び、次に[`dictionary.at`]を
322
+ /// 呼ぶのと同等です。
324
323
#[ func]
325
324
pub fn at (
326
325
& self ,
327
- /// The index or name of the argument to get.
326
+ /// 取得する引数のインデックスまたは名前。
328
327
key : ArgumentKey ,
329
- /// A default value to return if the key is invalid.
328
+ /// キーが無効な場合に返すデフォルト値。
330
329
#[ named]
331
330
default : Option < Value > ,
332
331
) -> StrResult < Value > {
@@ -336,7 +335,7 @@ impl Args {
336
335
. ok_or_else ( || missing_key_no_default ( key) )
337
336
}
338
337
339
- /// Returns the captured positional arguments as an array.
338
+ /// 受け取った位置引数を配列の形で返します。
340
339
#[ func( name = "pos" , title = "Positional" ) ]
341
340
pub fn to_pos ( & self ) -> Array {
342
341
self . items
@@ -346,7 +345,7 @@ impl Args {
346
345
. collect ( )
347
346
}
348
347
349
- /// Returns the captured named arguments as a dictionary.
348
+ /// 受け取った名前つき引数を辞書の形で返します。
350
349
#[ func( name = "named" ) ]
351
350
pub fn to_named ( & self ) -> Dict {
352
351
self . items
0 commit comments