mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Tweak to parser and main's error handling
This commit is contained in:
parent
09aad777f4
commit
2dc39feabd
3 changed files with 15 additions and 9 deletions
|
@ -16,7 +16,7 @@ type (
|
||||||
cfg Config // each server gets one Config; this is the one we're currently building
|
cfg Config // each server gets one Config; this is the one we're currently building
|
||||||
other []locationContext // tokens to be 'parsed' later by middleware generators
|
other []locationContext // tokens to be 'parsed' later by middleware generators
|
||||||
scope *locationContext // the current location context (path scope) being populated
|
scope *locationContext // the current location context (path scope) being populated
|
||||||
unused bool // sometimes a token will be read but not immediately consumed
|
unused *token // sometimes a token will be read but not immediately consumed
|
||||||
}
|
}
|
||||||
|
|
||||||
// locationContext represents a location context
|
// locationContext represents a location context
|
||||||
|
@ -62,13 +62,13 @@ func (p *parser) parse() ([]Config, error) {
|
||||||
// nextArg loads the next token if it is on the same line.
|
// nextArg loads the next token if it is on the same line.
|
||||||
// Returns true if a token was loaded; false otherwise.
|
// Returns true if a token was loaded; false otherwise.
|
||||||
func (p *parser) nextArg() bool {
|
func (p *parser) nextArg() bool {
|
||||||
if p.unused {
|
if p.unused != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
line := p.line()
|
line, tkn := p.line(), p.lexer.token
|
||||||
if p.next() {
|
if p.next() {
|
||||||
if p.line() > line {
|
if p.line() > line {
|
||||||
p.unused = true
|
p.unused = &tkn
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -79,8 +79,8 @@ func (p *parser) nextArg() bool {
|
||||||
// next loads the next token and returns true if a token
|
// next loads the next token and returns true if a token
|
||||||
// was loaded; false otherwise.
|
// was loaded; false otherwise.
|
||||||
func (p *parser) next() bool {
|
func (p *parser) next() bool {
|
||||||
if p.unused {
|
if p.unused != nil {
|
||||||
p.unused = false
|
p.unused = nil
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return p.lexer.next()
|
return p.lexer.next()
|
||||||
|
@ -151,11 +151,17 @@ func (p *parser) unwrap() error {
|
||||||
|
|
||||||
// tkn is shorthand to get the text/value of the current token.
|
// tkn is shorthand to get the text/value of the current token.
|
||||||
func (p *parser) tkn() string {
|
func (p *parser) tkn() string {
|
||||||
|
if p.unused != nil {
|
||||||
|
return p.unused.text
|
||||||
|
}
|
||||||
return p.lexer.token.text
|
return p.lexer.token.text
|
||||||
}
|
}
|
||||||
|
|
||||||
// line is shorthand to get the line number of the current token.
|
// line is shorthand to get the line number of the current token.
|
||||||
func (p *parser) line() int {
|
func (p *parser) line() int {
|
||||||
|
if p.unused != nil {
|
||||||
|
return p.unused.line
|
||||||
|
}
|
||||||
return p.lexer.token.line
|
return p.lexer.token.line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (p *parser) addressBlock() error {
|
||||||
err := p.openCurlyBrace()
|
err := p.openCurlyBrace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// meh, single-server configs don't need curly braces
|
// meh, single-server configs don't need curly braces
|
||||||
p.unused = true // we read the token but aren't consuming it
|
p.unused = &p.lexer.token // we read the token but aren't consuming it
|
||||||
return p.directives()
|
return p.directives()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ func (p *parser) collectTokens() error {
|
||||||
if p.tkn() == "{" {
|
if p.tkn() == "{" {
|
||||||
nesting++
|
nesting++
|
||||||
} else if p.line() > line && nesting == 0 {
|
} else if p.line() > line && nesting == 0 {
|
||||||
p.unused = true
|
p.unused = &p.lexer.token
|
||||||
breakOk = true
|
breakOk = true
|
||||||
break
|
break
|
||||||
} else if p.tkn() == "}" && nesting > 0 {
|
} else if p.tkn() == "}" && nesting > 0 {
|
||||||
|
|
2
main.go
2
main.go
|
@ -39,7 +39,7 @@ func main() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
err := s.Serve()
|
err := s.Serve()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}(s)
|
}(s)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue