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

Method parseReplaceFunc

parse/parse.go:248–296  ·  view source on GitHub ↗

parses the ${param/pattern/string} string function parses the ${param//pattern/string} string function parses the ${param/#pattern/string} string function parses the ${param/%pattern/string} string function

(name string)

Source from the content-addressed store, hash-verified

246// parses the ${param/#pattern/string} string function
247// parses the ${param/%pattern/string} string function
248func (t *Tree) parseReplaceFunc(name string) (Node, error) {
249 node := new(FuncNode)
250 node.Param = name
251
252 t.scanner.accept = acceptReplaceFunc
253 t.scanner.mode = scanIdent
254 switch t.scanner.scan() {
255 case tokenIdent:
256 node.Name = t.scanner.string()
257 default:
258 return nil, ErrBadSubstitution
259 }
260
261 // scan arg[1]
262 {
263 param, err := t.parseParam(acceptNotSlash, scanIdent|scanEscape)
264 if err != nil {
265 return nil, err
266 }
267 node.Args = append(node.Args, param)
268 }
269
270 // expect delimiter
271 t.scanner.accept = acceptSlash
272 t.scanner.mode = scanIdent
273 switch t.scanner.scan() {
274 case tokenIdent:
275 // no-op
276 default:
277 return nil, ErrBadSubstitution
278 }
279
280 // check for blank string
281 switch t.scanner.peek() {
282 case '}':
283 return node, t.consumeRbrack()
284 }
285
286 // scan arg[2]
287 {
288 param, err := t.parseParam(acceptNotClosing, scanIdent|scanEscape)
289 if err != nil {
290 return nil, err
291 }
292 node.Args = append(node.Args, param)
293 }
294
295 return node, t.consumeRbrack()
296}
297
298// parses the ${parameter=word} string function
299// parses the ${parameter:=word} string function

Callers 1

parseFuncMethod · 0.95

Calls 5

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

Tested by

no test coverage detected