99 lines
1.8 KiB
Go
99 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
type Parser struct {
|
|
Line *Line
|
|
repl *PrefixReplacer
|
|
EmitWarnings bool
|
|
}
|
|
|
|
func NewParser(line *Line, s string, emitWarnings bool) *Parser {
|
|
return &Parser{line, NewPrefixReplacer(s), emitWarnings}
|
|
}
|
|
|
|
func (p *Parser) EOF() bool {
|
|
return p.repl.rest == ""
|
|
}
|
|
|
|
func (p *Parser) Rest() string {
|
|
return p.repl.rest
|
|
}
|
|
|
|
func (p *Parser) PkgbasePattern() (pkgbase string) {
|
|
repl := p.repl
|
|
|
|
for {
|
|
if repl.AdvanceRegexp(`^\$\{\w+\}`) ||
|
|
repl.AdvanceRegexp(`^[\w.*+,{}]+`) ||
|
|
repl.AdvanceRegexp(`^\[[\d-]+\]`) {
|
|
pkgbase += repl.m[0]
|
|
continue
|
|
}
|
|
|
|
mark := repl.Mark()
|
|
if repl.AdvanceStr("-") {
|
|
if repl.AdvanceRegexp(`^\d`) ||
|
|
repl.AdvanceRegexp(`^\$\{\w*VER\w*\}`) ||
|
|
repl.AdvanceStr("[") {
|
|
repl.Reset(mark)
|
|
return
|
|
}
|
|
pkgbase += "-"
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func (p *Parser) Dependency() *DependencyPattern {
|
|
repl := p.repl
|
|
|
|
var dp DependencyPattern
|
|
mark := repl.Mark()
|
|
dp.pkgbase = p.PkgbasePattern()
|
|
if dp.pkgbase == "" {
|
|
return nil
|
|
}
|
|
|
|
mark2 := repl.Mark()
|
|
if repl.AdvanceStr(">=") || repl.AdvanceStr(">") {
|
|
op := repl.s
|
|
if repl.AdvanceRegexp(`^(?:(?:\$\{\w+\})+|\d[\w.]*)`) {
|
|
dp.lowerOp = op
|
|
dp.lower = repl.m[0]
|
|
} else {
|
|
repl.Reset(mark2)
|
|
}
|
|
}
|
|
if repl.AdvanceStr("<=") || repl.AdvanceStr("<") {
|
|
op := repl.s
|
|
if repl.AdvanceRegexp(`^(?:(?:\$\{\w+\})+|\d[\w.]*)`) {
|
|
dp.upperOp = op
|
|
dp.upper = repl.m[0]
|
|
} else {
|
|
repl.Reset(mark2)
|
|
}
|
|
}
|
|
if dp.lowerOp != "" || dp.upperOp != "" {
|
|
return &dp
|
|
}
|
|
if repl.AdvanceStr("-") && repl.rest != "" {
|
|
dp.wildcard = repl.AdvanceRest()
|
|
return &dp
|
|
}
|
|
if hasPrefix(dp.pkgbase, "${") && hasSuffix(dp.pkgbase, "}") {
|
|
return &dp
|
|
}
|
|
if hasSuffix(dp.pkgbase, "-*") {
|
|
dp.pkgbase = strings.TrimSuffix(dp.pkgbase, "-*")
|
|
dp.wildcard = "*"
|
|
return &dp
|
|
}
|
|
|
|
repl.Reset(mark)
|
|
return nil
|
|
}
|