diff --git a/parser.go b/parser.go index 6cc630a..de927c9 100644 --- a/parser.go +++ b/parser.go @@ -169,7 +169,7 @@ func (parser *Parser) parseInclude() error { if err != nil { return err } - // parser.curSection.AddInclude(filename) + parser.curSection.AddInclude(filename) parser.scanner = NewScanner(reader) parser.parse() } @@ -207,7 +207,7 @@ func (parser *Parser) parse() error { parser.readToken() switch tok.ID { case token.COMMENT: - // parser.curSection.AddComment(tok.Literal) + parser.curSection.AddComment(tok.Literal) case token.INCLUDE: parser.parseInclude() case token.IDENTIFIER: diff --git a/section.go b/section.go index ca894fa..7d20b59 100644 --- a/section.go +++ b/section.go @@ -9,24 +9,50 @@ import ( // Section struct holds a map of values type Section struct { - parent *Section - values map[string]Value + comments []string + includes []string + parent *Section + values map[string]Value } // NewSection will create and initialize a new Section func NewSection() *Section { return &Section{ - values: make(map[string]Value), + comments: make([]string, 0), + includes: make([]string, 0), + values: make(map[string]Value), } } func newChildSection(parent *Section) *Section { return &Section{ - parent: parent, - values: make(map[string]Value), + comments: make([]string, 0), + includes: make([]string, 0), + parent: parent, + values: make(map[string]Value), } } +// AddComment will append a new comment into the section +func (section *Section) AddComment(comment string) { + section.comments = append(section.comments, comment) +} + +// AddInclude will append a new filename into the section +func (section *Section) AddInclude(filename string) { + section.includes = append(section.includes, filename) +} + +// GetComments will return all the comments were defined for this Section +func (section *Section) GetComments() []string { + return section.comments +} + +// GetIncludes will return the filenames of all the includes were parsed for this Section +func (section *Section) GetIncludes() []string { + return section.includes +} + // GetType will respond with the ValueType of this Section (hint, always SECTION) func (section *Section) GetType() ValueType { return SECTION