-
Notifications
You must be signed in to change notification settings - Fork 1
/
type.go
32 lines (30 loc) · 812 Bytes
/
type.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
package asttest
import (
"github.com/akm/tparser/ast"
"github.com/akm/tparser/ast/astcore"
"github.com/pkg/errors"
)
func NewTypeId(unitIdOrIdent interface{}, args ...interface{}) *ast.TypeId {
var ref *astcore.Decl
if len(args) > 0 {
if v, ok := args[len(args)-1].(*astcore.Decl); ok {
ref = v
args = args[:len(args)-1]
}
}
if len(args) == 0 {
callArgs := []interface{}{}
if ref != nil {
callArgs = append(callArgs, ref)
}
return ast.NewTypeId(NewIdent(unitIdOrIdent), callArgs...)
} else if len(args) == 1 {
callArgs := []interface{}{*NewIdent(args[0])}
if ref != nil {
callArgs = append(callArgs, ref)
}
return ast.NewTypeId(NewUnitId(unitIdOrIdent), callArgs...)
} else {
panic(errors.Errorf("too many arguments for NewTypeId: %v, %v", unitIdOrIdent, args))
}
}