MCPcopy Create free account
hub / github.com/drone/envsubst / parseDefaultFunc

Method parseDefaultFunc

parse/parse.go:303–333  ·  view source on GitHub ↗

parses the ${parameter=word} string function parses the ${parameter:=word} string function parses the ${parameter:-word} string function parses the ${parameter:?word} string function parses the ${parameter:+word} string function

(name string)

Source from the content-addressed store, hash-verified

301// parses the ${parameter:?word} string function
302// parses the ${parameter:+word} string function
303func (t *Tree) parseDefaultFunc(name string) (Node, error) {
304 node := new(FuncNode)
305 node.Param = name
306
307 t.scanner.accept = acceptDefaultFunc
308 if t.scanner.peek() == '=' {
309 t.scanner.accept = acceptOneEqual
310 }
311 t.scanner.mode = scanIdent
312 switch t.scanner.scan() {
313 case tokenIdent:
314 node.Name = t.scanner.string()
315 default:
316 return nil, ErrParseDefaultFunction
317 }
318
319 // loop through all possible runes in default param
320 for {
321 // this acts as the break condition. Peek to see if we reached the end
322 switch t.scanner.peek() {
323 case '}':
324 return node, t.consumeRbrack()
325 }
326 param, err := t.parseParam(acceptNotClosing, scanIdent)
327 if err != nil {
328 return nil, err
329 }
330
331 node.Args = append(node.Args, param)
332 }
333}
334
335// parses the ${param,} string function
336// parses the ${param,,} string function

Callers 2

parseFuncMethod · 0.95
parseDefaultOrSubstrMethod · 0.95

Calls 5

consumeRbrackMethod · 0.95
parseParamMethod · 0.95
peekMethod · 0.80
scanMethod · 0.80
stringMethod · 0.80

Tested by

no test coverage detected