Browse Source

make life a little easier

pull/16/head
Brett Langdon 11 years ago
parent
commit
873e7c60b7
2 changed files with 17 additions and 9 deletions
  1. +15
    -0
      config/section.go
  2. +2
    -9
      parser/parser.go

+ 15
- 0
config/section.go View File

@ -8,6 +8,21 @@ type SectionValue struct {
Comments []string 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) GetType() ConfigType { return SECTION }
func (this SectionValue) GetValue() interface{} { return this.Value } func (this SectionValue) GetValue() interface{} { return this.Value }


+ 2
- 9
parser/parser.go View File

@ -185,11 +185,7 @@ func (this *Parser) parseSetting(name string) error {
} }
func (this *Parser) parseSection(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.cur_section.Set(name, section)
this.previous = append(this.previous, this.cur_section) this.previous = append(this.previous, this.cur_section)
this.cur_section = 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) { 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{ parser := &Parser{
tokenizer: token.NewTokenizer(reader), tokenizer: token.NewTokenizer(reader),
settings: settings, settings: settings,


Loading…
Cancel
Save