func mergeMap(m, r map[string]interface{}, key string) map[string]interface{} {
	if _, ok := m[key]; !ok {
		m[key] = r
	} else {
		for k, v := range r {
			m[key].(map[string]interface{})[k] = v
		}
	}
	return m
}
VDF files can contain duplicates of keys, when this occurs we need to merge the existing map and the returned map
package vdf
import (
	"bytes"
	"fmt"
	"io"
)
type Parser struct {
	s   *Scanner
	buf struct {
		tok Token   
		lit string  
		n   int     
	}
}
func NewParser(r io.Reader) *Parser {
	return &Parser{s: NewScanner(r)}
}
func (p *Parser) scan(respectWhitespace bool) (Token, string) {
	if p.buf.n != 0 {
		p.buf.n = 0
		return p.buf.tok, p.buf.lit
	}
	tok, lit := p.s.Scan(respectWhitespace)
	p.buf.tok, p.buf.lit = tok, lit
	return tok, lit
}
func (p *Parser) unscan() { p.buf.n = 1 }
func (p *Parser) scanIgnoreWSAndComments() (Token, string) {
	tok, lit := p.scan(false)
	if tok == WS {
		tok, lit = p.scan(false)
	}
	if tok == CommentDoubleSlash {
		for {
			tok, _ = p.scan(true)
			if tok == EOL {
				break
			}
		}
		return p.scanIgnoreWSAndComments()
	}
	return tok, lit
}
func (p *Parser) Parse() (map[string]interface{}, error) {
	m := make(map[string]interface{})
	key := ""
	tok, lit, err := p.scanMapKey()
	if err != nil {
		return nil, err
	}
	if tok != Ident {
		return nil, fmt.Errorf("found %q, expected an ident as a first part", lit)
	}
	key = lit
	tok, lit = p.scanIgnoreWSAndComments()
	if tok != CurlyBraceOpen {
		return nil, fmt.Errorf("found %q, expected an ident as a first part", lit)
	}
	p.unscan()
	m[key], err = p.parseMap()
	if err != nil {
		return nil, err
	}
	return m, nil
}
func (p *Parser) scanMapKey() (Token, string, error) {
	tok, lit := p.scanIgnoreWSAndComments()
	if tok == QuotationMark {
		return p.scanIdentSurroundedQuotationMark()
	} else if tok == Ident {
		return tok, lit, nil
	}
	return Illegal, lit, nil
}
func (p *Parser) parseMap() (map[string]interface{}, error) {
	m := make(map[string]interface{})
	key := ""
	tok, _ := p.scanIgnoreWSAndComments()
	if tok != CurlyBraceOpen {
		return m, nil
	}
	var err error
	for {
		tok, lit := p.scanIgnoreWSAndComments()
		switch tok {
		case QuotationMark:
			_, key, err = p.scanIdentSurroundedQuotationMark()
			if err != nil {
				return nil, err
			}
		case Ident:
			key = lit
		case CurlyBraceClose:
			return m, nil
		case CommentDoubleSlash:
			fmt.Println("KILLER")
			return m, nil
		default:
			return m, nil
		}
		tok, lit = p.scanIgnoreWSAndComments()
		switch tok {
		case QuotationMark:
			_, m[key], err = p.scanIdentSurroundedQuotationMark()
			if err != nil {
				return nil, err
			}
		case Ident:
			m[key] = lit
		case CurlyBraceOpen:
			p.unscan()
			m1, err := p.parseMap()
			if err != nil {
				return nil, err
			}
			mergeMap(m, m1, key)
		case CurlyBraceClose:
			return m, nil
		default:
			return m, nil
		}
	}
}
func (p *Parser) scanIdentSurroundedQuotationMark() (Token, string, error) {
	var buf bytes.Buffer
	escaped := false
	terminated := false
	for {
		tok, lit := p.scan(true)
		if tok == EOF && !terminated {
			return tok, "", ErrNotValidFormat
		}
		if tok == QuotationMark && !escaped {
			terminated = true
			break
		}
		if escaped && tok != EscapeSequence {
			escaped = false
		}
		if tok == EscapeSequence && !escaped {
			escaped = true
			continue
		}
		buf.WriteString(lit)
		if escaped && tok == EscapeSequence {
			escaped = false
		}
	}
	return Ident, buf.String(), nil
}