Skip to content

Commit d52d74c

Browse files
committed
go mod vendor
1 parent d36f73d commit d52d74c

File tree

11 files changed

+63
-90
lines changed

11 files changed

+63
-90
lines changed

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ golang.org/x/xerrors
3737
golang.org/x/xerrors/internal
3838
# gopkg.in/yaml.v2 v2.2.2
3939
gopkg.in/yaml.v2
40-
# mvdan.cc/sh/v3 v3.0.0-beta1
40+
# mvdan.cc/sh/v3 v3.0.2
4141
mvdan.cc/sh/v3/expand
4242
mvdan.cc/sh/v3/interp
4343
mvdan.cc/sh/v3/pattern

vendor/mvdan.cc/sh/v3/expand/braces.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func Braces(word *syntax.Word) []*syntax.Word {
2424
continue
2525
}
2626
if br.Sequence {
27-
var from, to int
28-
if br.Chars {
27+
chars := false
28+
from, err1 := strconv.Atoi(br.Elems[0].Lit())
29+
to, err2 := strconv.Atoi(br.Elems[1].Lit())
30+
if err1 != nil || err2 != nil {
31+
chars = true
2932
from = int(br.Elems[0].Lit()[0])
3033
to = int(br.Elems[1].Lit()[0])
31-
} else {
32-
from, _ = strconv.Atoi(br.Elems[0].Lit())
33-
to, _ = strconv.Atoi(br.Elems[1].Lit())
3434
}
3535
upward := from <= to
3636
incr := 1
@@ -54,7 +54,7 @@ func Braces(word *syntax.Word) []*syntax.Word {
5454
next := *word
5555
next.Parts = next.Parts[i+1:]
5656
lit := &syntax.Lit{}
57-
if br.Chars {
57+
if chars {
5858
lit.Value = string(n)
5959
} else {
6060
lit.Value = strconv.Itoa(n)

vendor/mvdan.cc/sh/v3/expand/expand.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func Document(cfg *Config, word *syntax.Word) (string, error) {
159159
return cfg.fieldJoin(field), nil
160160
}
161161

162+
const patMode = pattern.Filenames | pattern.Braces
163+
162164
// Pattern expands a single shell word as a pattern, using syntax.QuotePattern
163165
// on any non-quoted parts of the input word. The result can be used on
164166
// syntax.TranslatePattern directly.
@@ -174,7 +176,7 @@ func Pattern(cfg *Config, word *syntax.Word) (string, error) {
174176
buf := cfg.strBuilder()
175177
for _, part := range field {
176178
if part.quote > quoteNone {
177-
buf.WriteString(pattern.QuoteMeta(part.val))
179+
buf.WriteString(pattern.QuoteMeta(part.val, patMode))
178180
} else {
179181
buf.WriteString(part.val)
180182
}
@@ -345,11 +347,11 @@ func (cfg *Config) escapedGlobField(parts []fieldPart) (escaped string, glob boo
345347
buf := cfg.strBuilder()
346348
for _, part := range parts {
347349
if part.quote > quoteNone {
348-
buf.WriteString(pattern.QuoteMeta(part.val))
350+
buf.WriteString(pattern.QuoteMeta(part.val, patMode))
349351
continue
350352
}
351353
buf.WriteString(part.val)
352-
if pattern.HasMeta(part.val) {
354+
if pattern.HasMeta(part.val, patMode) {
353355
glob = true
354356
}
355357
}
@@ -367,9 +369,10 @@ func Fields(cfg *Config, words ...*syntax.Word) ([]string, error) {
367369
fields := make([]string, 0, len(words))
368370
dir := cfg.envGet("PWD")
369371
for _, word := range words {
370-
afterBraces := []*syntax.Word{word}
371-
if syntax.SplitBraces(word) {
372-
afterBraces = Braces(word)
372+
word := *word // make a copy, since SplitBraces replaces the Parts slice
373+
afterBraces := []*syntax.Word{&word}
374+
if syntax.SplitBraces(&word) {
375+
afterBraces = Braces(&word)
373376
}
374377
for _, word2 := range afterBraces {
375378
wfields, err := cfg.wordFields(word2.Parts)
@@ -540,7 +543,6 @@ func (cfg *Config) wordFields(wps []syntax.WordPart) ([][]fieldPart, error) {
540543
}
541544
curField = append(curField, fp)
542545
case *syntax.DblQuoted:
543-
allowEmpty = true
544546
if len(x.Parts) == 1 {
545547
pe, _ := x.Parts[0].(*syntax.ParamExp)
546548
if elems := cfg.quotedElems(pe); elems != nil {
@@ -556,6 +558,7 @@ func (cfg *Config) wordFields(wps []syntax.WordPart) ([][]fieldPart, error) {
556558
continue
557559
}
558560
}
561+
allowEmpty = true
559562
wfield, err := cfg.wordField(x.Parts, quoteDouble)
560563
if err != nil {
561564
return nil, err

vendor/mvdan.cc/sh/v3/interp/interp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ func (r *Runner) sub() *Runner {
745745
Env: r.Env,
746746
Dir: r.Dir,
747747
Params: r.Params,
748-
Funcs: r.Funcs,
749748
execHandler: r.execHandler,
750749
openHandler: r.openHandler,
751750
stdin: r.stdin,
@@ -766,6 +765,10 @@ func (r *Runner) sub() *Runner {
766765
for k, v := range r.cmdVars {
767766
r2.cmdVars[k] = v
768767
}
768+
r2.Funcs = make(map[string]*syntax.Stmt, len(r.Funcs))
769+
for k, v := range r.Funcs {
770+
r2.Funcs[k] = v
771+
}
769772
r2.dirStack = append(r2.dirBootstrap[:0], r.dirStack...)
770773
r2.fillExpandConfig(r.ectx)
771774
r2.didReset = true

vendor/mvdan.cc/sh/v3/pattern/pattern.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"strings"
1717
)
1818

19-
// TODO: support Mode in the other APIs too
20-
19+
// Mode can be used to supply a number of options to the package's functions.
20+
// Not all functions change their behavior with all of the options below.
2121
type Mode uint
2222

2323
const (
@@ -254,13 +254,17 @@ func charClass(s string) (string, error) {
254254
// This can be useful to avoid extra work, like TranslatePattern. Note that this
255255
// function cannot be used to avoid QuotePattern, as backslashes are quoted by
256256
// that function but ignored here.
257-
func HasMeta(pat string) bool {
257+
func HasMeta(pat string, mode Mode) bool {
258258
for i := 0; i < len(pat); i++ {
259259
switch pat[i] {
260260
case '\\':
261261
i++
262262
case '*', '?', '[':
263263
return true
264+
case '{':
265+
if mode&Braces != 0 {
266+
return true
267+
}
264268
}
265269
}
266270
return false
@@ -270,11 +274,16 @@ func HasMeta(pat string) bool {
270274
// given text. The returned string is a pattern that matches the literal text.
271275
//
272276
// For example, QuoteMeta(`foo*bar?`) returns `foo\*bar\?`.
273-
func QuoteMeta(pat string) string {
277+
func QuoteMeta(pat string, mode Mode) string {
274278
any := false
275279
loop:
276280
for _, r := range pat {
277281
switch r {
282+
case '{':
283+
if mode&Braces == 0 {
284+
continue
285+
}
286+
fallthrough
278287
case '*', '?', '[', '\\':
279288
any = true
280289
break loop
@@ -288,6 +297,10 @@ loop:
288297
switch r {
289298
case '*', '?', '[', '\\':
290299
buf.WriteByte('\\')
300+
case '{':
301+
if mode&Braces != 0 {
302+
buf.WriteByte('\\')
303+
}
291304
}
292305
buf.WriteRune(r)
293306
}

vendor/mvdan.cc/sh/v3/shell/source.go

Lines changed: 0 additions & 57 deletions
This file was deleted.

vendor/mvdan.cc/sh/v3/syntax/braces.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func SplitBraces(word *Word) bool {
129129
broken = true
130130
}
131131
if !broken {
132-
br.Chars = chars[0]
133132
acc.Parts = append(acc.Parts, br)
134133
break
135134
}

vendor/mvdan.cc/sh/v3/syntax/lexer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ skipSpace:
256256
for r != '\n' && r != utf8.RuneSelf {
257257
if r == escNewl {
258258
p.litBs = append(p.litBs, '\\', '\n')
259+
break
259260
}
260261
r = p.rune()
261262
}
@@ -316,6 +317,7 @@ skipSpace:
316317
} else {
317318
p.tok = rightParen
318319
p.quote = noState
320+
p.rune() // we are tokenizing manually
319321
}
320322
default: // including '(', '|'
321323
p.advanceLitRe(r)

vendor/mvdan.cc/sh/v3/syntax/nodes.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ type Word struct {
409409
func (w *Word) Pos() Pos { return w.Parts[0].Pos() }
410410
func (w *Word) End() Pos { return w.Parts[len(w.Parts)-1].End() }
411411

412-
// Lit returns the word as a literal value, if the word consists of *syntax.Lit
413-
// nodes only. An empty string is returned otherwise. Words with multiple
414-
// literals, which can appear in some edge cases, are handled properly.
412+
// Lit returns the word as a literal value, if the word consists of *Lit nodes
413+
// only. An empty string is returned otherwise. Words with multiple literals,
414+
// which can appear in some edge cases, are handled properly.
415415
//
416416
// For example, the word "foo" will return "foo", but the word "foo${bar}" will
417417
// return "".
@@ -859,12 +859,11 @@ type LetClause struct {
859859
func (l *LetClause) Pos() Pos { return l.Let }
860860
func (l *LetClause) End() Pos { return l.Exprs[len(l.Exprs)-1].End() }
861861

862-
// BraceExp represents a Bash brace expression, such as "{x,y}" or "{1..10}".
862+
// BraceExp represents a Bash brace expression, such as "{a,f}" or "{1..10}".
863863
//
864864
// This node will only appear as a result of SplitBraces.
865865
type BraceExp struct {
866866
Sequence bool // {x..y[..incr]} instead of {x,y[,...]}
867-
Chars bool // sequence is of chars, not numbers (TODO: remove)
868867
Elems []*Word
869868
}
870869

vendor/mvdan.cc/sh/v3/syntax/parser.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// ParserOption is a function which can be passed to NewParser
1616
// to alter its behaviour. To apply option to existing Parser
17-
// call it directly, for example syntax.KeepComments(true)(parser).
17+
// call it directly, for example KeepComments(true)(parser).
1818
type ParserOption func(*Parser)
1919

2020
// KeepComments makes the parser parse comments and attach them to
@@ -524,9 +524,13 @@ func (p *Parser) unquotedWordPart(buf *bytes.Buffer, wp WordPart, quotes bool) (
524524
}
525525

526526
func (p *Parser) doHeredocs() {
527+
hdocs := p.heredocs[p.buriedHdocs:]
528+
if len(hdocs) == 0 {
529+
// Nothing do do; don't even issue a read.
530+
return
531+
}
527532
p.rune() // consume '\n', since we know p.tok == _Newl
528533
old := p.quote
529-
hdocs := p.heredocs[p.buriedHdocs:]
530534
p.heredocs = p.heredocs[:p.buriedHdocs]
531535
for i, r := range hdocs {
532536
if p.err != nil {
@@ -840,7 +844,7 @@ func (p *Parser) invalidStmtStart() {
840844
}
841845

842846
func (p *Parser) getWord() *Word {
843-
if parts := p.wordParts(); len(parts) > 0 {
847+
if parts := p.wordParts(); len(parts) > 0 && p.err == nil {
844848
return p.word(parts)
845849
}
846850
return nil
@@ -1546,13 +1550,15 @@ func (p *Parser) hasValidIdent() bool {
15461550
}
15471551
if end := p.eqlOffs; end > 0 {
15481552
if p.val[end-1] == '+' && p.lang != LangPOSIX {
1549-
end--
1553+
end-- // a+=x
15501554
}
15511555
if ValidName(p.val[:end]) {
15521556
return true
15531557
}
1558+
} else if !ValidName(p.val) {
1559+
return false // *[i]=x
15541560
}
1555-
return p.r == '['
1561+
return p.r == '[' // a[i]=x
15561562
}
15571563

15581564
func (p *Parser) getAssign(needEqual bool) *Assign {

0 commit comments

Comments
 (0)