Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Farrow committed May 5, 2021
1 parent bc0168f commit d725a63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ func Decode(reader io.Reader) (*Node, error) {
var key string
for tt := text.Scan(); tt != scanner.EOF; tt = text.Scan() {
token := text.TokenText()
if token[0] == '/' {
// skip comments
if tt == scanner.Comment {
continue
}

// first non-blank line in the input
if isFirst {
isFirst = false
if tt != scanner.Ident {
return nil, fmt.Errorf("line %d must begin with an identifer: %q", text.Pos().Line, token)
}
isFirst = false
root = NewNode(token, text.Indent)
nesting = append(nesting, root)
isElem = true
Expand Down Expand Up @@ -56,6 +59,7 @@ func Decode(reader io.Reader) (*Node, error) {
parent = nesting[leaf]
}

// continuation line
if tt == '+' {
key = ""
continue
Expand All @@ -69,6 +73,7 @@ func Decode(reader io.Reader) (*Node, error) {
continue
}

// adding a value to a key
if addValue {
addValue = false
switch tt {
Expand Down
2 changes: 1 addition & 1 deletion decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestScanner(t *testing.T) {
"p= Ident indent: 12 start: true line: 8",
"id= Ident indent: 12 start: false line: 8",
":= \":\" indent: 12 start: false line: 8",
"\"X:Y = 2\"= String indent: 12 start: false line: 8",
"\"X/Y = 2\"= String indent: 12 start: false line: 8",
"`the quick brown fox\njumped over the moon and ran into a cow`= RawString indent: 12 start: false line: 9",
}
t.Log(test0)
Expand Down

0 comments on commit d725a63

Please sign in to comment.