aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddyconfig/caddyfile/parse.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2019-08-21 15:23:00 -0600
committerMatthew Holt <[email protected]>2019-08-21 15:23:00 -0600
commit8420a2f250cf467a06c0081cb47a8f73b70e7f3f (patch)
tree3414aeedaa257ab98353f3e0a035be666f0f0cbb /caddyconfig/caddyfile/parse.go
parent59910923d10a99f694445ebded559cfc845eb4bd (diff)
downloadcaddy-8420a2f250cf467a06c0081cb47a8f73b70e7f3f.tar.gz
caddy-8420a2f250cf467a06c0081cb47a8f73b70e7f3f.zip
Clean up Dispenser and filename handling a bit
Diffstat (limited to 'caddyconfig/caddyfile/parse.go')
-rwxr-xr-xcaddyconfig/caddyfile/parse.go21
1 files changed, 8 insertions, 13 deletions
diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go
index cc7ed25db..3356f256c 100755
--- a/caddyconfig/caddyfile/parse.go
+++ b/caddyconfig/caddyfile/parse.go
@@ -29,18 +29,18 @@ import (
// an error. If you do not want to check for valid directives,
// pass in nil instead.
func Parse(filename string, input io.Reader) ([]ServerBlock, error) {
- tokens, err := allTokens(input)
+ tokens, err := allTokens(filename, input)
if err != nil {
return nil, err
}
- p := parser{Dispenser: NewDispenser(filename, tokens)}
+ p := parser{Dispenser: NewDispenser(tokens)}
return p.parseAll()
}
// allTokens lexes the entire input, but does not parse it.
// It returns all the tokens from the input, unstructured
// and in order.
-func allTokens(input io.Reader) ([]Token, error) {
+func allTokens(filename string, input io.Reader) ([]Token, error) {
l := new(lexer)
err := l.load(input)
if err != nil {
@@ -48,6 +48,7 @@ func allTokens(input io.Reader) ([]Token, error) {
}
var tokens []Token
for l.next() {
+ l.token.File = filename
tokens = append(tokens, l.token)
}
return tokens, nil
@@ -265,7 +266,7 @@ func (p *parser) doImport() error {
// list of matching filenames
absFile, err := filepath.Abs(p.Dispenser.File())
if err != nil {
- return p.Errf("Failed to get absolute path of file: %s: %v", p.Dispenser.filename, err)
+ return p.Errf("Failed to get absolute path of file: %s: %v", p.Dispenser.File(), err)
}
var matches []string
@@ -327,7 +328,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
return nil, p.Errf("Could not import %s: is a directory", importFile)
}
- importedTokens, err := allTokens(file)
+ importedTokens, err := allTokens(importFile, file)
if err != nil {
return nil, p.Errf("Could not read tokens while importing %s: %v", importFile, err)
}
@@ -336,7 +337,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
// (we use full, absolute path to avoid bugs: issue #1892)
filename, err := filepath.Abs(importFile)
if err != nil {
- return nil, p.Errf("Failed to get absolute path of file: %s: %v", p.Dispenser.filename, err)
+ return nil, p.Errf("Failed to get absolute path of file: %s: %v", importFile, err)
}
for i := 0; i < len(importedTokens); i++ {
importedTokens[i].File = filename
@@ -497,7 +498,7 @@ func (sb ServerBlock) DispenseDirective(dir string) *Dispenser {
tokens = append(tokens, seg...)
}
}
- return NewDispenser("", tokens)
+ return NewDispenser(tokens)
}
// Segment is a list of tokens which begins with a directive
@@ -513,9 +514,3 @@ func (s Segment) Directive() string {
}
return ""
}
-
-// NewDispenser returns a dispenser for this
-// segment's tokens.
-func (s Segment) NewDispenser() *Dispenser {
- return NewDispenser("", s)
-}