From 15bf9c196c5972051f40ebadf50811bd06e328dd Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 14 Feb 2020 11:00:16 -0700 Subject: caddyfile: Refactor; NewFromNextSegment(); fix repeated matchers Now multiple instances of the same matcher can be used within a named matcher without overwriting previous ones. --- caddyconfig/caddyfile/dispenser.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'caddyconfig/caddyfile') diff --git a/caddyconfig/caddyfile/dispenser.go b/caddyconfig/caddyfile/dispenser.go index 4ed9325..932ab61 100755 --- a/caddyconfig/caddyfile/dispenser.go +++ b/caddyconfig/caddyfile/dispenser.go @@ -249,13 +249,20 @@ func (d *Dispenser) RemainingArgs() []string { return args } -// NewFromNextTokens returns a new dispenser with a copy of +// NewFromNextSegment returns a new dispenser with a copy of // the tokens from the current token until the end of the // "directive" whether that be to the end of the line or // the end of a block that starts at the end of the line; // in other words, until the end of the segment. -func (d *Dispenser) NewFromNextTokens() *Dispenser { - tkns := []Token{d.Token()} +func (d *Dispenser) NewFromNextSegment() *Dispenser { + return NewDispenser(d.NextSegment()) +} + +// NextSegment returns a copy of the tokens from the current +// token until the end of the line or block that starts at +// the end of the line. +func (d *Dispenser) NextSegment() Segment { + tkns := Segment{d.Token()} for d.NextArg() { tkns = append(tkns, d.Token()) } @@ -282,7 +289,7 @@ func (d *Dispenser) NewFromNextTokens() *Dispenser { // next iteration of the enclosing loop will // call Next() and consume it } - return NewDispenser(tkns) + return tkns } // Token returns the current token. -- cgit v1.2.3