command: operand (space operand)* space-separated arguments up to a pipeline character or right delimiter. we consume the pipe character but leave the right delim to terminate the action.
()
| 686 | // space-separated arguments up to a pipeline character or right delimiter. |
| 687 | // we consume the pipe character but leave the right delim to terminate the action. |
| 688 | func (t *Tree) command() *CommandNode { |
| 689 | cmd := t.newCommand(t.peekNonSpace().pos) |
| 690 | for { |
| 691 | t.peekNonSpace() // skip leading spaces. |
| 692 | operand := t.operand() |
| 693 | if operand != nil { |
| 694 | cmd.append(operand) |
| 695 | } |
| 696 | switch token := t.next(); token.typ { |
| 697 | case itemSpace: |
| 698 | continue |
| 699 | case itemRightDelim, itemRightParen: |
| 700 | t.backup() |
| 701 | case itemPipe: |
| 702 | // nothing here; break loop below |
| 703 | default: |
| 704 | t.unexpected(token, "operand") |
| 705 | } |
| 706 | break |
| 707 | } |
| 708 | if len(cmd.Args) == 0 { |
| 709 | t.errorf("empty command") |
| 710 | } |
| 711 | return cmd |
| 712 | } |
| 713 | |
| 714 | // operand: |
| 715 | // |
no test coverage detected