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) {
return nil, err
}
defer file.Close()
p := newParser(file)
p, err := newParser(file)
if err != nil {
return nil, err
}
return p.parse()
}
......
......@@ -28,12 +28,16 @@ func init() {
return p.argErr()
}
file, err := os.Open(p.tkn())
filename := p.tkn()
file, err := os.Open(filename)
if err != nil {
return p.err("Parse", err.Error())
}
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
err = p2.directives()
......
......@@ -20,10 +20,16 @@ type parser struct {
// newParser makes a new parser and prepares it for parsing, given
// the input to parse.
func newParser(file *os.File) *parser {
p := &parser{filename: file.Name()}
func newParser(file *os.File) (*parser, error) {
stat, err := file.Stat()
if err != nil {
return nil, err
}
p := &parser{filename: stat.Name()}
p.lexer.load(file)
return p
return p, nil
}
// Parse parses the configuration file. It produces a slice of Config
......
......@@ -45,6 +45,7 @@ func (p *parser) addressBlock() error {
err := p.openCurlyBrace()
if err != nil {
// meh, single-server configs don't need curly braces
p.unused = true // we read the token but aren't consuming it
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