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)
| 301 | // parses the ${parameter:?word} string function |
| 302 | // parses the ${parameter:+word} string function |
| 303 | func (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 |
no test coverage detected