forked from percolate/charlatan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathellipsis.go
37 lines (28 loc) · 791 Bytes
/
ellipsis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import "fmt"
// Ellipsis is the built-in vararg type
type Ellipsis struct {
subType Type
parameterFormat string
fieldFormat string
}
// ParameterFormat returns syntax for a parameter declaration
func (t *Ellipsis) ParameterFormat() string {
if t.parameterFormat != "" {
return t.parameterFormat
}
t.parameterFormat = fmt.Sprintf("...%s", t.subType.ParameterFormat())
return t.parameterFormat
}
// ReferenceFormat returns the syntax for a reference
func (t *Ellipsis) ReferenceFormat() string {
return "..."
}
// FieldFormat returns the syntax for a field declaration
func (t *Ellipsis) FieldFormat() string {
if t.fieldFormat != "" {
return t.fieldFormat
}
t.fieldFormat = fmt.Sprintf("[]%s", t.subType.FieldFormat())
return t.fieldFormat
}