Reformat for better documentation output

This commit is contained in:
Thomas Pelletier
2013-02-24 19:34:32 +01:00
parent 3c9a474015
commit 6dd3db3d59
4 changed files with 27 additions and 29 deletions
+7 -7
View File
@@ -20,7 +20,7 @@ var dateRegexp *regexp.Regexp
type tokenType int
const (
EOF = - (iota + 1)
eof = - (iota + 1)
)
const (
@@ -108,7 +108,7 @@ func (l *lexer) emitWithValue(t tokenType, value string) {
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 @@ func lexVoid(l *lexer) stateFn {
l.ignore()
}
if l.next() == EOF { break }
if l.next() == eof { break }
}
l.emit(tokenEOF)
@@ -223,7 +223,7 @@ func lexRvalue(l *lexer) stateFn {
l.ignore()
}
if l.next() == EOF { break }
if l.next() == eof { break }
}
l.emit(tokenEOF)
@@ -276,7 +276,7 @@ func lexKey(l *lexer) stateFn {
func lexComment(l *lexer) stateFn {
for {
next := l.next()
if next == '\n' || next == EOF {
if next == '\n' || next == eof {
break
}
}
@@ -313,7 +313,7 @@ func lexString(l *lexer) stateFn {
growing_string += string(l.peek())
}
if l.next() == EOF { break }
if l.next() == eof { break }
}
return l.errorf("unclosed string")
@@ -338,7 +338,7 @@ func lexInsideKeyGroup(l *lexer) stateFn {
return lexVoid
}
if l.next() == EOF { break }
if l.next() == eof { break }
}
return l.errorf("unclosed key group")
}
+7 -7
View File
@@ -6,24 +6,24 @@ import (
"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
}
+1 -1
View File
@@ -4,7 +4,7 @@ import "testing"
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 {
+12 -14
View File
@@ -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 @@ func (t *tomlTree) Get(key string) interface{} {
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
}