From c5b97739229a007a128b91cba55928ab8e547cf9 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 16 Mar 2019 10:42:54 -0300 Subject: [PATCH] go mod vendor --- vendor/modules.txt | 2 +- vendor/mvdan.cc/sh/interp/builtin.go | 1 + vendor/mvdan.cc/sh/interp/interp.go | 8 ++++++-- vendor/mvdan.cc/sh/syntax/nodes.go | 24 ++++++++++++++++++++---- vendor/mvdan.cc/sh/syntax/parser.go | 19 +++++++++++++++---- vendor/mvdan.cc/sh/syntax/printer.go | 6 ++++-- vendor/mvdan.cc/sh/syntax/walk.go | 4 +++- 7 files changed, 50 insertions(+), 14 deletions(-) diff --git a/vendor/modules.txt b/vendor/modules.txt index 2dea7837..9729cbcf 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -38,7 +38,7 @@ golang.org/x/sys/unix golang.org/x/sys/windows # gopkg.in/yaml.v2 v2.2.1 gopkg.in/yaml.v2 -# mvdan.cc/sh v2.6.4-0.20190222161105-3c71c7be1070+incompatible +# mvdan.cc/sh v2.6.4+incompatible mvdan.cc/sh/expand mvdan.cc/sh/interp mvdan.cc/sh/shell diff --git a/vendor/mvdan.cc/sh/interp/builtin.go b/vendor/mvdan.cc/sh/interp/builtin.go index de7be9fb..f36bfd04 100644 --- a/vendor/mvdan.cc/sh/interp/builtin.go +++ b/vendor/mvdan.cc/sh/interp/builtin.go @@ -70,6 +70,7 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a r.errf("set: %v\n", err) return 2 } + r.updateExpandOpts() case "shift": n := 1 switch len(args) { diff --git a/vendor/mvdan.cc/sh/interp/interp.go b/vendor/mvdan.cc/sh/interp/interp.go index 4a5a8b41..5fd53e86 100644 --- a/vendor/mvdan.cc/sh/interp/interp.go +++ b/vendor/mvdan.cc/sh/interp/interp.go @@ -260,7 +260,6 @@ func Params(args ...string) func(*Runner) error { args = args[1:] } r.Params = args - r.updateExpandOpts() return nil } } @@ -479,6 +478,7 @@ func (r *Runner) Reset() { Exec: r.Exec, Open: r.Open, KillTimeout: r.KillTimeout, + opts: r.opts, // emptied below, to reuse the space Vars: r.Vars, @@ -791,7 +791,11 @@ func (r *Runner) cmd(ctx context.Context, cm syntax.Command) { switch y := x.Loop.(type) { case *syntax.WordIter: name := y.Name.Value - for _, field := range r.fields(y.Items...) { + items := r.Params // for i; do ... + if y.InPos.IsValid() { + items = r.fields(y.Items...) // for i in ...; do ... + } + for _, field := range items { r.setVarString(name, field) if r.loopStmtsBroken(ctx, x.Do) { break diff --git a/vendor/mvdan.cc/sh/syntax/nodes.go b/vendor/mvdan.cc/sh/syntax/nodes.go index 3daf82fb..a4f473c5 100644 --- a/vendor/mvdan.cc/sh/syntax/nodes.go +++ b/vendor/mvdan.cc/sh/syntax/nodes.go @@ -376,14 +376,21 @@ func (*WordIter) loopNode() {} func (*CStyleLoop) loopNode() {} // WordIter represents the iteration of a variable over a series of words in a -// for clause. +// for clause. If InPos is an invalid position, the "in" token was missing, so +// the iteration is over the shell's positional parameters. type WordIter struct { Name *Lit + InPos Pos // position of "in" Items []*Word } func (w *WordIter) Pos() Pos { return w.Name.Pos() } -func (w *WordIter) End() Pos { return posMax(w.Name.End(), wordLastEnd(w.Items)) } +func (w *WordIter) End() Pos { + if len(w.Items) > 0 { + return wordLastEnd(w.Items) + } + return posMax(w.Name.End(), posAddCol(w.InPos, 2)) +} // CStyleLoop represents the behaviour of a for clause similar to the C // language. @@ -781,8 +788,12 @@ func (a *ArrayExpr) Pos() Pos { return a.Lparen } func (a *ArrayExpr) End() Pos { return posAddCol(a.Rparen, 1) } // ArrayElem represents a Bash array element. +// +// Index can be nil; for example, declare -a x=(value). +// Value can be nil; for example, declare -A x=([index]=). +// Finally, neither can be nil; for example, declare -A x=([index]=value) type ArrayElem struct { - Index ArithmExpr // [i]=, ["k"]= + Index ArithmExpr Value *Word Comments []Comment } @@ -793,7 +804,12 @@ func (a *ArrayElem) Pos() Pos { } return a.Value.Pos() } -func (a *ArrayElem) End() Pos { return a.Value.End() } +func (a *ArrayElem) End() Pos { + if a.Value != nil { + return a.Value.End() + } + return posAddCol(a.Index.Pos(), 1) +} // ExtGlob represents a Bash extended globbing expression. Note that these are // parsed independently of whether shopt has been called or not. diff --git a/vendor/mvdan.cc/sh/syntax/parser.go b/vendor/mvdan.cc/sh/syntax/parser.go index bf54d786..1fca3c19 100644 --- a/vendor/mvdan.cc/sh/syntax/parser.go +++ b/vendor/mvdan.cc/sh/syntax/parser.go @@ -1003,6 +1003,11 @@ func (p *Parser) wordPart() WordPart { p.next() cs.StmtList = p.stmtList() + if p.tok == bckQuote && p.lastBquoteEsc < p.openBquotes-1 { + // e.g. found ` before the nested backquote \` was closed. + p.tok = _EOF + p.quoteErr(cs.Pos(), bckQuote) + } p.postNested(old) p.openBquotes-- cs.Right = p.pos @@ -1587,11 +1592,16 @@ func (p *Parser) getAssign(needEqual bool) *Assign { p.follow(left, `"[x]"`, assgn) } if ae.Value = p.getWord(); ae.Value == nil { - if p.tok == leftParen { + switch p.tok { + case leftParen: p.curErr("arrays cannot be nested") + return nil + case _Newl, rightParen, leftBrack: + // TODO: support [index]=[ + default: + p.curErr("array element values must be words") + break } - p.curErr("array element values must be words") - break } if len(p.accComs) > 0 { c := p.accComs[0] @@ -2012,7 +2022,8 @@ func (p *Parser) wordIter(ftok string, fpos Pos) *WordIter { return wi } p.got(_Newl) - if _, ok := p.gotRsrv("in"); ok { + if pos, ok := p.gotRsrv("in"); ok { + wi.InPos = pos for !stopToken(p.tok) { if w := p.getWord(); w == nil { p.curErr("word list can only contain words") diff --git a/vendor/mvdan.cc/sh/syntax/printer.go b/vendor/mvdan.cc/sh/syntax/printer.go index b7da1606..87e31c3f 100644 --- a/vendor/mvdan.cc/sh/syntax/printer.go +++ b/vendor/mvdan.cc/sh/syntax/printer.go @@ -620,7 +620,7 @@ func (p *Printer) loop(loop Loop) { switch x := loop.(type) { case *WordIter: p.WriteString(x.Name.Value) - if len(x.Items) > 0 { + if x.InPos.IsValid() { p.spacedString(" in", Pos{}) p.wordJoin(x.Items) } @@ -788,7 +788,9 @@ func (p *Printer) elemJoin(elems []*ArrayElem, last []Comment) { if p.wroteIndex(el.Index) { p.WriteByte('=') } - p.word(el.Value) + if el.Value != nil { + p.word(el.Value) + } p.comments(left...) } if len(last) > 0 { diff --git a/vendor/mvdan.cc/sh/syntax/walk.go b/vendor/mvdan.cc/sh/syntax/walk.go index 1192d575..9ff07da8 100644 --- a/vendor/mvdan.cc/sh/syntax/walk.go +++ b/vendor/mvdan.cc/sh/syntax/walk.go @@ -199,7 +199,9 @@ func Walk(node Node, f func(Node) bool) { if x.Index != nil { Walk(x.Index, f) } - Walk(x.Value, f) + if x.Value != nil { + Walk(x.Value, f) + } case *ExtGlob: Walk(x.Pattern, f) case *ProcSubst: