Reformat for better documentation output
diff --git a/src/toml/lexer.go b/src/toml/lexer.go index d057294..7484b7b 100644 --- a/src/toml/lexer.go +++ b/src/toml/lexer.go
@@ -20,7 +20,7 @@ type tokenType int const ( - EOF = - (iota + 1) + eof = - (iota + 1) ) const ( @@ -108,7 +108,7 @@ func (l *lexer) next() (rune) { if l.pos >= len(l.input) { l.width = 0 - return EOF + return eof } var r rune r, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) @@ -174,7 +174,7 @@ l.ignore() } - if l.next() == EOF { break } + if l.next() == eof { break } } l.emit(tokenEOF) @@ -223,7 +223,7 @@ l.ignore() } - if l.next() == EOF { break } + if l.next() == eof { break } } l.emit(tokenEOF) @@ -276,7 +276,7 @@ func lexComment(l *lexer) stateFn { for { next := l.next() - if next == '\n' || next == EOF { + if next == '\n' || next == eof { break } } @@ -313,7 +313,7 @@ growing_string += string(l.peek()) } - if l.next() == EOF { break } + if l.next() == eof { break } } return l.errorf("unclosed string") @@ -338,7 +338,7 @@ return lexVoid } - if l.next() == EOF { break } + if l.next() == eof { break } } return l.errorf("unclosed key group") }
diff --git a/src/toml/parser.go b/src/toml/parser.go index 6dd9b16..0441423 100644 --- a/src/toml/parser.go +++ b/src/toml/parser.go
@@ -6,24 +6,24 @@ "strings" ) -// Given a tree and a key, create the necessary intermediate subtrees to create -// a subtree at that point. In-place. +// createSubTree takes a tree and a key andcreate the necessary intermediate +// subtrees to create a subtree at that point. In-place. // // e.g. passing a.b.c will create (assuming tree is empty) tree[a], tree[a][b] // and tree[a][b][c] -func createSubTree(tree *tomlTree, key string) { +func createSubTree(tree *TomlTree, key string) { subtree := tree for _, intermediate_key := range strings.Split(key, ".") { _, exists := (*subtree)[intermediate_key] if !exists { - (*subtree)[intermediate_key] = make(tomlTree) + (*subtree)[intermediate_key] = make(TomlTree) } - subtree = (*subtree)[intermediate_key].(*tomlTree) + subtree = (*subtree)[intermediate_key].(*TomlTree) } } -func parse(chan token) *tomlTree { - result := make(tomlTree) +func parse(chan token) *TomlTree { + result := make(TomlTree) return &result }
diff --git a/src/toml/parser_test.go b/src/toml/parser_test.go index 1dcbc70..f61135d 100644 --- a/src/toml/parser_test.go +++ b/src/toml/parser_test.go
@@ -4,7 +4,7 @@ func testCreateSubTree(t *testing.T) { - tree := make(tomlTree) + tree := make(TomlTree) createSubTree(&tree, "a.b.c") tree.Set("a.b.c", 42) if tree.Get("a.b.c") != 42 {
diff --git a/src/toml/toml.go b/src/toml/toml.go index f0779d5..717e81f 100644 --- a/src/toml/toml.go +++ b/src/toml/toml.go
@@ -1,18 +1,17 @@ -// TOML interface. - +// TOML markup language parser. package toml import ( "strings" ) -// Definition of a tomlTree -type tomlTree map[string]interface{} +// Definition of a TomlTree. +// This is the result of the parsing of a TOML file. +type TomlTree map[string]interface{} -// Retrieve an element from the tree. -// +// Get an element from the tree. // If the path described by the key does not exist, nil is returned. -func (t *tomlTree) Get(key string) interface{} { +func (t *TomlTree) Get(key string) interface{} { subtree := t keys := strings.Split(key, ".") for _, intermediate_key := range keys[:len(keys)-1] { @@ -20,29 +19,28 @@ if !exists { return nil } - subtree = (*subtree)[intermediate_key].(*tomlTree) + subtree = (*subtree)[intermediate_key].(*TomlTree) } return (*subtree)[keys[len(keys) - 1]] } // Set an element in the tree. -// // Creates all necessary intermediates trees, if needed. -func (t *tomlTree) Set(key string, value interface{}) { +func (t *TomlTree) Set(key string, value interface{}) { subtree := t keys := strings.Split(key, ".") for _, intermediate_key := range keys[:len(keys)-1] { _, exists := (*subtree)[intermediate_key] if !exists { - (*subtree)[intermediate_key] = make(tomlTree) + (*subtree)[intermediate_key] = make(TomlTree) } - subtree = (*subtree)[intermediate_key].(*tomlTree) + subtree = (*subtree)[intermediate_key].(*TomlTree) } (*subtree)[keys[len(key) - 1]] = value } -func Load() tomlTree { - result := make(tomlTree) +func Load() TomlTree { + result := make(TomlTree) return result }