Browse Source

add back in AddComment/AddInclude

pull/16/head
Brett Langdon 11 years ago
parent
commit
7b653ec302
2 changed files with 33 additions and 7 deletions
  1. +2
    -2
      parser.go
  2. +31
    -5
      section.go

+ 2
- 2
parser.go View File

@ -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:


+ 31
- 5
section.go View File

@ -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


Loading…
Cancel
Save