-
Notifications
You must be signed in to change notification settings - Fork 2
/
conditional.go
46 lines (40 loc) · 1.09 KB
/
conditional.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
package specfile
import (
"bufio"
"strings"
)
// Conditional the conditionals like "%if 0%{?suse_version} >= 1550\nBuildRequires: xz\n%endif\n"
type Conditional struct {
item
}
// Parse parse the conditional
func (conditional *Conditional) Parse(token *Tokenizer) {
}
// ParseConditional parse conditional from token
func ParseConditional(token, last Tokenizer, macros Macros, spec *Specfile) {
scanner := bufio.NewScanner(strings.NewReader(token.Content))
var conditions []string
var lastIf, secondlastIf, idx int
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "%if") || strings.HasPrefix(line, "%else") {
conditions = append(conditions, line)
if strings.HasPrefix(line, "%if") {
secondlastIf = lastIf
lastIf = idx
}
idx++
continue
}
if strings.HasPrefix(line, "%endif") {
// ["%if 0%{?suse_version} >= 1310", "%if 0%{?suse_version} > 1330"]
conditions = conditions[:lastIf]
lastIf = secondlastIf
secondlastIf = 0
idx -= len(conditions) - lastIf
continue
}
parser, _ := NewParser(strings.NewReader(line))
parser.Parse()
}
}