Skip to content

andygrunwald/vdf

Repository files navigation

vdf: A Lexer and Parser for Valves Data Format (known as vdf)

GoDoc Go Report Card

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

Table of Contents

Installation

It is go gettable

$ go get github.com/andygrunwald/vdf 

Usage

Given a file named gamestate_integration_consolesample.cfg with content:

"Console Sample v.1" {	"uri"	"http://127.0.0.1:3000"	"timeout"	"5.0"	"buffer"	"0.1"	"throttle"	"0.5"	"heartbeat"	"60.0"	[...] } 

Can be parsed with this Go code:

package main import ( "fmt" "os" "github.com/andygrunwald/vdf" ) func main() { f, err := os.Open("gamestate_integration_consolesample.cfg") if err != nil { panic(err)	} p := vdf.NewParser(f) m, err := p.Parse() if err != nil { panic(err)	} fmt.Println(m) }

And it will output:

map[	Console Sample v.1:map[	uri:http://127.0.0.1:3000	timeout:5.0	buffer:0.1	throttle:0.5	heartbeat:60.0	[...]	] ] 

API-Documentation

The official Go package documentation can be found at https://pkg.go.dev/github.com/andygrunwald/vdf.

Development

Unit testing

To run the local unit tests, execute

$ make test

To run the local unit tests and view the unit test code coverage in your local web browser, execute

$ make test-coverage-html

Fuzzing tests

This library implements Go fuzzing. The generated fuzzing corpus is stored in andygrunwald/vdf-fuzzing-corpus, to avoid blowing up the size of this repository.

To run fuzzing locally, execute

$ make init-fuzzing # Clone the corpus into testdata/fuzz $ make clean-fuzzing # Clean the local fuzzing cache $ make test-fuzzing # Execute the fuzzing

Press

VDF parser in other languages

Inspiration

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

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors