summaryrefslogtreecommitdiff
path: root/internal/config/dir.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/dir.go')
-rw-r--r--internal/config/dir.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/internal/config/dir.go b/internal/config/dir.go
index 74c538a..461d912 100644
--- a/internal/config/dir.go
+++ b/internal/config/dir.go
@@ -19,9 +19,41 @@ type Dir struct {
PathText string // as written in the file
Settings Settings
Ignore []string // gitignore patterns, in order
+ Excludes []*Exclude
Rules []*Rule
}
+// Exclude is one (exclude COND...) form: a file for which every condition
+// holds is set aside before any rule runs. Forms may repeat, so a file is
+// excluded when any one form matches it.
+type Exclude struct {
+ Pos sexp.Pos
+ Text string // the form as written, whitespace collapsed, for check and explain
+ When []*sexp.Node // the conditions, all of which must hold
+}
+
+// parseExclude reads an (exclude COND...) form from src; nil when it has no
+// usable condition.
+func parseExclude(n *sexp.Node, src []byte, d *diags) *Exclude {
+ conds := n.Args()
+ if len(conds) == 0 {
+ d.at(n, "(exclude) needs a condition, like (exclude (type iso))")
+ return nil
+ }
+ bad := false
+ for _, c := range conds {
+ if c.Kind != sexp.List {
+ d.at(c, "exclude: a condition is a form like (type pdf), not %s", c)
+ bad = true
+ }
+ }
+ if bad {
+ return nil
+ }
+ text := strings.Join(strings.Fields(string(src[n.Pos.Offset:n.End.Offset])), " ")
+ return &Exclude{Pos: n.Pos, Text: text, When: conds}
+}
+
// Rule is a named condition with the actions it performs.
type Rule struct {
Name string
@@ -97,6 +129,10 @@ func ParseDir(name, file string, src []byte) (*Dir, []*Diag) {
}
dir.Ignore = append(dir.Ignore, a.Text)
}
+ case head == "exclude":
+ if x := parseExclude(n, src, d); x != nil {
+ dir.Excludes = append(dir.Excludes, x)
+ }
case head == "rule":
r := parseRule(n, d)
if r == nil {
@@ -111,7 +147,7 @@ func ParseDir(name, file string, src []byte) (*Dir, []*Diag) {
case isSetting(head):
dir.Settings.parse(n, d, seen)
default:
- d.at(n, "unknown form (%s ...); a directory file has path, ignore, rule and settings like (recursive yes)", head)
+ d.at(n, "unknown form (%s ...); a directory file has path, ignore, exclude, rule and settings like (recursive yes)", head)
}
}
if pathNode == nil {