-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphpdoc.go
48 lines (38 loc) · 1003 Bytes
/
phpdoc.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
38
39
40
41
42
43
44
45
46
47
48
package phpdoc
import (
"fmt"
"strings"
)
type Type interface {
String() string
}
type PrimitiveTypeName struct {
Name string
}
type TypeName struct {
Parts []string
}
type NullableType struct {
Elem Type
}
type OptionalKeyType struct {
Elem Type
}
type ArrayType struct {
Elem Type
}
type UnionType struct {
X Type
Y Type
}
type IntersectionType struct {
X Type
Y Type
}
func (typ *PrimitiveTypeName) String() string { return typ.Name }
func (typ *TypeName) String() string { return strings.Join(typ.Parts, `\`) }
func (typ *NullableType) String() string { return "?(" + typ.Elem.String() + ")" }
func (typ *OptionalKeyType) String() string { return "(" + typ.Elem.String() + ")?" }
func (typ *ArrayType) String() string { return "(" + typ.Elem.String() + ")[]" }
func (typ *UnionType) String() string { return fmt.Sprintf("(%s)|(%s)", typ.X, typ.Y) }
func (typ *IntersectionType) String() string { return fmt.Sprintf("(%s)&(%s)", typ.X, typ.Y) }