Skip to content
/ vdf Public
forked from andygrunwald/vdf

A Lexer and Parser for Valves Data Format (known as vdf) written in Go

License

Notifications You must be signed in to change notification settings

qixizheng/vdf

 
 

Repository files navigation

vdf

GoDoc Go Report Card

A Lexer and Parser for Valves Data Format (known as vdf) written in Go.

Installation

It is go gettable

$ go get github.com/andygrunwald/vdf

(optional) to run unit / example tests:

$ cd $GOPATH/src/github.com/andygrunwald/vdf
$ go test -v ./...

Usage

Given a file named example.vdf with content:

"Example"
{
	"TimeNextStatsReport"      "1234567890"
	"ContentStatsID"           "-7123456789012345678"
}

Can be parsed with this Go code:

package main

import (
	"fmt"
	"github.com/andygrunwald/vdf"
	"log"
	"os"
)

func main() {
	f, err := os.Open("./example.vdf")
	if err != nil {
		log.Fatal(err)
	}

	p := vdf.NewParser(f)
	m, err := p.Parse()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(m)
}

And it will output:

map[
	Example:map[
		TimeNextStatsReport:1234567890
		ContentStatsID:-7123456789012345678
	]
]

Inspiration

The code and project idea is heavily inspired and driven by @benbjohnson article Handwritten Parsers & Lexers in Go and his example sql-parser. Thank you Ben!

Parser in other languages

License

This project is released under the terms of the MIT license.

About

A Lexer and Parser for Valves Data Format (known as vdf) written in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 97.2%
  • Makefile 2.8%