-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.go
45 lines (41 loc) · 939 Bytes
/
parser.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 specfile
import (
"io"
)
// Parser the specfile parser
type Parser struct {
Tokens Tokenizers
Spec Specfile
}
// NewParser initialize a new specfile parser
func NewParser(rd io.ReaderAt) (Parser, error) {
tokenizers, err := NewTokenizers(rd)
if err != nil {
return Parser{}, err
}
return Parser{tokenizers, Specfile{}}, nil
}
// Parse actually parse the tokens to spec
func (f *Parser) Parse() error {
var last Tokenizer
systemMacros := initSystemMacros()
for _, token := range f.Tokens {
switch token.Type {
case "Conditional":
ParseConditional(token, last, systemMacros, &(f.Spec))
case "Macro":
ParseMacro(token, last, systemMacros, &(f.Spec))
case "Dependency":
ParseDependency(token, last, &(f.Spec))
case "Section":
err := ParseSection(token, last, &(f.Spec))
if err != nil {
return err
}
case "Tag":
ParseTag(token, last, &(f.Spec))
}
last = token
}
return nil
}