-
Notifications
You must be signed in to change notification settings - Fork 1
/
cask.go
45 lines (35 loc) · 1022 Bytes
/
cask.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
package cask
// A Cask represents the cask used in Homebrew-Cask.
type Cask struct {
// Token specifies the cask token.
Token string
// Content specifies the string content of the loaded cask.
Content string
// Variants specifies all cask variants represented as a slice of Variant
// pointers.
Variants []*Variant
// parser specifies the Parser to be used for parsing the cask.
parser *Parser
}
// NewCask creates a new Cask instance and returns its pointer.
func NewCask(content string) *Cask {
c := new(Cask)
c.Content = content
l := NewLexer(c.Content)
c.parser = NewParser(l)
c.parser.cask = c
return c
}
// Parse parses the cask.
func (c *Cask) Parse() error {
return c.parser.ParseCask(c)
}
// AddVariant adds a new Variant pointer to the Cask.Variants slice.
func (c *Cask) AddVariant(variant *Variant) {
c.Variants = append(c.Variants, variant)
}
// String returns a string representation of the Cask struct which is the cask
// Token.
func (c Cask) String() string {
return c.Token
}