MCPcopy Create free account
hub / github.com/aptly-dev/aptly / D

Method D

query/syntax.go:127–170  ·  view source on GitHub ↗

D := | _ _ field := | | $special_field

()

Source from the content-addressed store, hash-verified

125// D := <field> <condition> <arch_condition> | <package>_<version>_<arch>
126// field := <package-name> | <field> | $special_field
127func (p *parser) D() deb.PackageQuery {
128 if p.input.Current().typ != itemString {
129 panic(fmt.Sprintf("unexpected token %s: expecting field or package name", p.input.Current()))
130 }
131
132 field := p.input.Current().val
133 p.input.Consume()
134
135 operator, value := p.Condition()
136
137 r, _ := utf8.DecodeRuneInString(field)
138 if strings.HasPrefix(field, "$") || (unicode.IsUpper(r) && !strings.ContainsRune(field, '_')) {
139 // special field or regular field
140 q := &deb.FieldQuery{Field: field, Relation: operatorToRelation(operator), Value: value}
141 if q.Relation == deb.VersionRegexp {
142 var err error
143 q.Regexp, err = regexp.Compile(q.Value)
144 if err != nil {
145 panic(fmt.Sprintf("regexp compile failed: %s", err))
146 }
147 }
148 return q
149 } else if operator == 0 && value == "" {
150 if pkg, version, arch, ok := parsePackageRef(field); ok {
151 // query for specific package
152 return &deb.PkgQuery{Pkg: pkg, Version: version, Arch: arch}
153 }
154 }
155
156 // regular dependency-like query
157 q := &deb.DependencyQuery{Dep: deb.Dependency{
158 Pkg: field,
159 Relation: operatorToRelation(operator),
160 Version: value,
161 Architecture: p.ArchCondition()}}
162 if q.Dep.Relation == deb.VersionRegexp {
163 var err error
164 q.Dep.Regexp, err = regexp.Compile(q.Dep.Version)
165 if err != nil {
166 panic(fmt.Sprintf("regexp compile failed: %s", err))
167 }
168 }
169 return q
170}
171
172// condition := '(' <operator> value ')' |
173// operator := | << | < | <= | > | >> | >= | = | % | ~

Callers 1

CMethod · 0.95

Calls 7

ConditionMethod · 0.95
ArchConditionMethod · 0.95
operatorToRelationFunction · 0.85
parsePackageRefFunction · 0.85
CurrentMethod · 0.80
ConsumeMethod · 0.80
HasPrefixMethod · 0.65

Tested by

no test coverage detected