MCPcopy
hub / github.com/caddyserver/caddy / blockTokens

Method blockTokens

caddyconfig/caddyfile/parse.go:741–772  ·  view source on GitHub ↗

read and store everything in a block for later replay.

(retainCurlies bool)

Source from the content-addressed store, hash-verified

739
740// read and store everything in a block for later replay.
741func (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

Callers 1

beginMethod · 0.95

Calls 5

openCurlyBraceMethod · 0.95
TokenMethod · 0.80
ValMethod · 0.80
SyntaxErrMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected