From 360cc938a23a44edb934246216168d4c9e29d08f Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Tue, 16 Jun 2015 19:49:17 -0400 Subject: [PATCH] get comments/includes to save --- config/section.go | 32 ++++++++++++++++---------------- parser/parser.go | 15 +++++++-------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/config/section.go b/config/section.go index 1d129cd..29ed987 100644 --- a/config/section.go +++ b/config/section.go @@ -9,8 +9,8 @@ type SectionValue struct { Includes []string } -func NewNamedSection(name string) SectionValue { - return SectionValue{ +func NewNamedSection(name string) *SectionValue { + return &SectionValue{ Name: name, Value: make(map[string]ConfigValue), Comments: make([]string, 0), @@ -18,8 +18,8 @@ func NewNamedSection(name string) SectionValue { } } -func NewAnonymousSection() SectionValue { - return SectionValue{ +func NewAnonymousSection() *SectionValue { + return &SectionValue{ Value: make(map[string]ConfigValue), Comments: make([]string, 0), Includes: make([]string, 0), @@ -29,48 +29,48 @@ func NewAnonymousSection() SectionValue { func (this SectionValue) GetType() ConfigType { return SECTION } func (this SectionValue) GetValue() interface{} { return this.Value } -func (this SectionValue) AddComment(comment string) { +func (this *SectionValue) AddComment(comment string) { this.Comments = append(this.Comments, comment) } -func (this SectionValue) AddInclude(include string) { +func (this *SectionValue) AddInclude(include string) { this.Includes = append(this.Includes, include) } -func (this SectionValue) Set(name string, value ConfigValue) { +func (this *SectionValue) Set(name string, value ConfigValue) { this.Value[name] = value } -func (this SectionValue) Get(name string) ConfigValue { +func (this *SectionValue) Get(name string) ConfigValue { return this.Value[name] } -func (this SectionValue) GetSection(name string) SectionValue { +func (this *SectionValue) GetSection(name string) SectionValue { value := this.Value[name] return value.(SectionValue) } -func (this SectionValue) GetString(name string) StringValue { +func (this *SectionValue) GetString(name string) StringValue { value := this.Value[name] return value.(StringValue) } -func (this SectionValue) GetInteger(name string) IntegerValue { +func (this *SectionValue) GetInteger(name string) IntegerValue { value := this.Value[name] return value.(IntegerValue) } -func (this SectionValue) GetFloat(name string) FloatValue { +func (this *SectionValue) GetFloat(name string) FloatValue { value := this.Value[name] return value.(FloatValue) } -func (this SectionValue) Contains(name string) bool { +func (this *SectionValue) Contains(name string) bool { _, ok := this.Value[name] return ok } -func (this SectionValue) ToJSON() ([]byte, error) { +func (this *SectionValue) ToJSON() ([]byte, error) { data, err := this.ToMap() if err != nil { return nil, err @@ -78,11 +78,11 @@ func (this SectionValue) ToJSON() ([]byte, error) { return json.Marshal(data) } -func (this SectionValue) ToMap() (map[string]interface{}, error) { +func (this *SectionValue) ToMap() (map[string]interface{}, error) { settings := make(map[string]interface{}) for name, value := range this.Value { if value.GetType() == SECTION { - data, err := value.(SectionValue).ToMap() + data, err := value.(*SectionValue).ToMap() if err != nil { return nil, err } diff --git a/parser/parser.go b/parser/parser.go index 87102aa..4807672 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -14,11 +14,11 @@ import ( ) type Parser struct { - settings config.SectionValue + settings *config.SectionValue tokenizer *token.Tokenizer cur_tok token.Token - cur_section config.SectionValue - previous []config.SectionValue + cur_section *config.SectionValue + previous []*config.SectionValue } func (this *Parser) SyntaxError(msg string) error { @@ -57,7 +57,7 @@ func (this *Parser) readToken() token.Token { return this.cur_tok } -func (this *Parser) parseReference(starting_section config.SectionValue, period bool) (config.ConfigValue, error) { +func (this *Parser) parseReference(starting_section *config.SectionValue, period bool) (config.ConfigValue, error) { names := []string{} if period == false { names = append(names, this.cur_tok.Literal) @@ -98,7 +98,7 @@ func (this *Parser) parseReference(starting_section config.SectionValue, period } name := names[0] names = names[1:] - section := reference.(config.SectionValue) + section := reference.(*config.SectionValue) if section.Contains(name) == false { return nil, this.ReferenceMissingError(visited, name) } @@ -212,7 +212,6 @@ func (this *Parser) parseInclude() error { this.tokenizer = token.NewTokenizer(reader) this.Parse() } - fmt.Println(this.cur_section.Includes) this.tokenizer = old_tokenizer this.readToken() return nil @@ -290,7 +289,7 @@ func ParseReader(reader io.Reader) (*config.SectionValue, error) { tokenizer: token.NewTokenizer(reader), settings: settings, cur_section: settings, - previous: make([]config.SectionValue, 0), + previous: make([]*config.SectionValue, 0), } err := parser.Parse() if err != nil { @@ -301,5 +300,5 @@ func ParseReader(reader io.Reader) (*config.SectionValue, error) { return nil, parser.SyntaxError("expected end of section, instead found EOF") } - return &settings, nil + return settings, nil }