Skip to content

Commit

Permalink
Go fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalholm committed Mar 28, 2013
1 parent 8e4f40c commit 111527e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 62 deletions.
24 changes: 11 additions & 13 deletions yaml/config.go
Expand Up @@ -90,34 +90,32 @@ func (f *File) Get(spec string) (string, error) {
}

func (f *File) GetInt(spec string) (int64, error) {
s, err := f.Get( spec )
s, err := f.Get(spec)
if err != nil {
return 0,err
return 0, err
}

i, err := strconv.ParseInt( s, 10, 64 )
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, err
}
return i,nil

return i, nil
}

func (f *File) GetBool(spec string) (bool, error) {
s, err := f.Get( spec )
s, err := f.Get(spec)
if err != nil {
return false,err
return false, err
}

b, err := strconv.ParseBool( s )
b, err := strconv.ParseBool(s)
if err != nil {
return false, err
}

return b,nil
}


return b, nil
}

// Count retrieves a the number of elements in the specified list from the file
// using the same format as that expected by Child. If the final node is not a
Expand Down Expand Up @@ -169,7 +167,7 @@ func (f *File) Require(spec string) string {
// The node tree is walked from the given node, considering each token of the
// above format. If a node along the evaluation path is not found, an error is
// returned. If a node is not the proper type, an error is returned. If the
// final node is not a Scalar, an error is returned.
// final node is not a Scalar, an error is returned.
func Child(root Node, spec string) (Node, error) {
if len(spec) == 0 {
return root, nil
Expand Down
16 changes: 8 additions & 8 deletions yaml/config_test.go
Expand Up @@ -67,19 +67,19 @@ func TestGet(t *testing.T) {
}
}

i, err := config.GetInt( "mapping.key3" )
i, err := config.GetInt("mapping.key3")
if err != nil || i != 5 {
t.Errorf("GetInt mapping.key3 wrong" )
t.Errorf("GetInt mapping.key3 wrong")
}

b, err := config.GetBool( "mapping.key4" )
if err != nil || b != true {
t.Errorf("GetBool mapping.key4 wrong" )
b, err := config.GetBool("mapping.key4")
if err != nil || b != true {
t.Errorf("GetBool mapping.key4 wrong")
}

b, err = config.GetBool( "mapping.key5" )
if err != nil || b != false {
t.Errorf("GetBool mapping.key5 wrong" )
b, err = config.GetBool("mapping.key5")
if err != nil || b != false {
t.Errorf("GetBool mapping.key5 wrong")
}

}
54 changes: 27 additions & 27 deletions yaml/doc.go
Expand Up @@ -4,52 +4,52 @@
// tabs, and GYPSY does not ever consider a tab to be a space character. It is
// recommended that your editor be configured to convert tabs to spaces when
// editing Gypsy config files.
//
//
// Gypsy understands the following to be a list:
//
//
// - one
// - two
// - three
//
//
// This is parsed as a `yaml.List`, and can be retrieved from the
// `yaml.Node.List()` method. In this case, each element of the `yaml.List` would
// be a `yaml.Scalar` whose value can be retrieved with the `yaml.Scalar.String()`
// method.
//
//
// Gypsy understands the following to be a mapping:
//
//
// key: value
// foo: bar
// running: away
//
//
// A mapping is an unordered list of `key:value` pairs. All whitespace after the
// colon is stripped from the value and is used for alignment purposes during
// export. If the value is not a list or a map, everything after the first
// non-space character until the end of the line is used as the `yaml.Scalar`
// value.
//
//
// Gypsy allows arbitrary nesting of maps inside lists, lists inside of maps, and
// maps and/or lists nested inside of themselves.
//
//
// A map inside of a list:
//
//
// - name: John Smith
// age: 42
// - name: Jane Smith
// age: 45
//
//
// A list inside of a map:
//
//
// schools:
// - Meadow Glen
// - Forest Creek
// - Shady Grove
// libraries:
// - Joseph Hollingsworth Memorial
// - Andrew Keriman Memorial
//
//
// A list of lists:
//
//
// - - one
// - two
// - three
Expand All @@ -59,9 +59,9 @@
// - - ichi
// - ni
// - san
//
//
// A map of maps:
//
//
// google:
// company: Google, Inc.
// ticker: GOOG
Expand All @@ -70,11 +70,11 @@
// company: Yahoo, Inc.
// ticker: YHOO
// url: http://yahoo.com/
//
//
// In the case of a map of maps, all sub-keys must be on subsequent lines and
// indented equally. It is allowable for the first key/value to be on the same
// line if there is more than one key/value pair, but this is not recommended.
//
//
// Values can also be expressed in long form (leading whitespace of the first line
// is removed from it and all subsequent lines). In the normal (baz) case,
// newlines are treated as spaces, all indentation is removed. In the folded case
Expand All @@ -83,40 +83,40 @@
// line is removed, and newlines at the end of indented lines are preserved. In
// the verbatim (foo) case, only the indent at the level of the first line is
// stripped. The example:
//
//
// foo: |
// lorem ipsum dolor
// sit amet
// bar: >
// lorem ipsum
//
//
// dolor
//
//
// sit amet
// baz:
// lorem ipsum
// dolor sit amet
//
//
// The YAML subset understood by Gypsy can be expressed (loosely) in the following
// grammar (not including comments):
//
//
// OBJECT = MAPPING | SEQUENCE | SCALAR .
// SHORT-OBJECT = SHORT-MAPPING | SHORT-SEQUENCE | SHORT-SCALAR .
// EOL = '\n'
//
//
// MAPPING = { LONG-MAPPING | SHORT-MAPPING } .
// SEQUENCE = { LONG-SEQUENCE | SHORT-SEQUENCE } .
// SCALAR = { LONG-SCALAR | SHORT-SCALAR } .
//
//
// LONG-MAPPING = { INDENT KEY ':' OBJECT EOL } .
// SHORT-MAPPING = '{' KEY ':' SHORT-OBJECT { ',' KEY ':' SHORT-OBJECT } '}' EOL .
//
//
// LONG-SEQUENCE = { INDENT '-' OBJECT EOL } EOL .
// SHORT-SEQUENCE = '[' SHORT-OBJECT { ',' SHORT-OBJECT } ']' EOL .
//
//
// LONG-SCALAR = ( '|' | '>' | ) EOL { INDENT SHORT-SCALAR EOL }
// SHORT-SCALAR = { alpha | digit | punct | ' ' | '\t' } .
//
//
// KEY = { alpha | digit }
// INDENT = { ' ' }
//
Expand Down
18 changes: 9 additions & 9 deletions yaml/parser.go
Expand Up @@ -107,23 +107,23 @@ func parseNode(r lineReader, ind int, initial Node) (node Node) {
trimmed := bytes.TrimSpace(end)
if len(trimmed) == 1 && trimmed[0] == '|' {
text := ""

for {
l := r.Next(1)
if l == nil {
break
}

s := string(l.line)
s = strings.TrimSpace( s )
s = strings.TrimSpace(s)
if len(s) == 0 {
break
}
text = text + "\n" + s
}

types = append(types, typScalar)
pieces = append(pieces, string(text))
pieces = append(pieces, string(text))
return
}
inlineValue(end)
Expand Down Expand Up @@ -241,8 +241,8 @@ func getType(line []byte) (typ, split int) {
// need to iterate past the first word
// things like "foo:" and "foo :" are mappings
// everything else is a scalar
idx := bytes.IndexAny( line, " \":" )

idx := bytes.IndexAny(line, " \":")
if idx < 0 {
return
}
Expand Down Expand Up @@ -276,11 +276,11 @@ func getType(line []byte) (typ, split int) {
}
}

if typ == typMapping && split + 1 < len(line) && line[split+1] != ' ' {
if typ == typMapping && split+1 < len(line) && line[split+1] != ' ' {
typ = typScalar
split = 0
}

return
}

Expand Down
10 changes: 5 additions & 5 deletions yaml/parser_test.go
Expand Up @@ -204,16 +204,16 @@ func TestGetType(t *testing.T) {
}

func Test_MultiLineString(t *testing.T) {
buf := bytes.NewBufferString( "a : |\n a\n b\n\nc : d" )
node, err := Parse( buf )
buf := bytes.NewBufferString("a : |\n a\n b\n\nc : d")
node, err := Parse(buf)
if err != nil {
t.Error( err )
t.Error(err)
} else {
m := node.(Map)
v := m["a"].(Scalar)
v2 := strings.TrimSpace( string(v) )
v2 := strings.TrimSpace(string(v))
if v2 != "a\nb" {
t.Errorf( "multi line parsed wrong thing: %v", v )
t.Errorf("multi line parsed wrong thing: %v", v)
}
}
}

0 comments on commit 111527e

Please sign in to comment.