Commit eae02402 authored by Matthew Holt's avatar Matthew Holt

Parser fixes, and now using base filename

parent decfda27
...@@ -24,7 +24,12 @@ func Load(filename string) ([]Config, error) { ...@@ -24,7 +24,12 @@ func Load(filename string) ([]Config, error) {
return nil, err return nil, err
} }
defer file.Close() defer file.Close()
p := newParser(file)
p, err := newParser(file)
if err != nil {
return nil, err
}
return p.parse() return p.parse()
} }
......
...@@ -28,12 +28,16 @@ func init() { ...@@ -28,12 +28,16 @@ func init() {
return p.argErr() return p.argErr()
} }
file, err := os.Open(p.tkn()) filename := p.tkn()
file, err := os.Open(filename)
if err != nil { if err != nil {
return p.err("Parse", err.Error()) return p.err("Parse", err.Error())
} }
defer file.Close() defer file.Close()
p2 := newParser(file) p2, err := newParser(file)
if err != nil {
return p.err("Parse", "Could not import "+filename+"; "+err.Error())
}
p2.cfg = p.cfg p2.cfg = p.cfg
err = p2.directives() err = p2.directives()
......
...@@ -20,10 +20,16 @@ type parser struct { ...@@ -20,10 +20,16 @@ type parser struct {
// newParser makes a new parser and prepares it for parsing, given // newParser makes a new parser and prepares it for parsing, given
// the input to parse. // the input to parse.
func newParser(file *os.File) *parser { func newParser(file *os.File) (*parser, error) {
p := &parser{filename: file.Name()} stat, err := file.Stat()
if err != nil {
return nil, err
}
p := &parser{filename: stat.Name()}
p.lexer.load(file) p.lexer.load(file)
return p
return p, nil
} }
// Parse parses the configuration file. It produces a slice of Config // Parse parses the configuration file. It produces a slice of Config
......
...@@ -45,6 +45,7 @@ func (p *parser) addressBlock() error { ...@@ -45,6 +45,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
return p.directives() return p.directives()
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment