diff --git a/config/section.go b/config/section.go index 44db07f..b3fd8ea 100644 --- a/config/section.go +++ b/config/section.go @@ -8,6 +8,21 @@ type SectionValue struct { Comments []string } +func NewNamedSection(name string) SectionValue { + return SectionValue{ + Name: name, + Value: make(map[string]ConfigValue), + Comments: make([]string, 0), + } +} + +func NewAnonymousSection() SectionValue { + return SectionValue{ + Value: make(map[string]ConfigValue), + Comments: make([]string, 0), + } +} + func (this SectionValue) GetType() ConfigType { return SECTION } func (this SectionValue) GetValue() interface{} { return this.Value } diff --git a/parser/parser.go b/parser/parser.go index bd98bd6..3c99ad9 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -185,11 +185,7 @@ func (this *Parser) parseSetting(name string) error { } func (this *Parser) parseSection(name string) error { - section := config.SectionValue{ - Name: name, - Value: make(map[string]config.ConfigValue), - Comments: make([]string, 0), - } + section := config.NewNamedSection(name) this.cur_section.Set(name, section) this.previous = append(this.previous, this.cur_section) this.cur_section = section @@ -253,10 +249,7 @@ func ParseFile(filename string) (settings *config.SectionValue, err error) { } func ParseReader(reader io.Reader) (*config.SectionValue, error) { - settings := config.SectionValue{ - Value: make(map[string]config.ConfigValue), - Comments: make([]string, 0), - } + settings := config.NewAnonymousSection() parser := &Parser{ tokenizer: token.NewTokenizer(reader), settings: settings,