read and store everything in a block for later replay.
(retainCurlies bool)
| 739 | |
| 740 | // read and store everything in a block for later replay. |
| 741 | func (p *parser) blockTokens(retainCurlies bool) ([]Token, error) { |
| 742 | // block must have curlies. |
| 743 | err := p.openCurlyBrace() |
| 744 | if err != nil { |
| 745 | return nil, err |
| 746 | } |
| 747 | nesting := 1 // count our own nesting |
| 748 | tokens := []Token{} |
| 749 | if retainCurlies { |
| 750 | tokens = append(tokens, p.Token()) |
| 751 | } |
| 752 | for p.Next() { |
| 753 | if p.Val() == "}" { |
| 754 | nesting-- |
| 755 | if nesting == 0 { |
| 756 | if retainCurlies { |
| 757 | tokens = append(tokens, p.Token()) |
| 758 | } |
| 759 | break |
| 760 | } |
| 761 | } |
| 762 | if p.Val() == "{" { |
| 763 | nesting++ |
| 764 | } |
| 765 | tokens = append(tokens, p.tokens[p.cursor]) |
| 766 | } |
| 767 | // make sure we're matched up |
| 768 | if nesting != 0 { |
| 769 | return nil, p.SyntaxErr("}") |
| 770 | } |
| 771 | return tokens, nil |
| 772 | } |
| 773 | |
| 774 | // ServerBlock associates any number of keys from the |
| 775 | // head of the server block with tokens, which are |