Skip to content

Frixuu/KDLGo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KDLGo

GoDoc

WIP Go parser for the KDL Document Language, version 1.0.0.

Current status

  • parsing to a kdl.Document model
  • serializing a kdl.Document model to a string
  • marshalling from a struct
  • unmarshalling to a struct
  • improve performance?

Usage

import (
	kdl "github.com/frixuu/kdlgo"
)

Parse (to a Document model)

// or any of: ParseBytes, ParseFile, ParseReader
document, err := kdl.ParseString(`foo bar="baz"`)

Modify the Document

if document.Nodes[0].HasProp("bar") {
	n := kdl.NewNode("person")
	n.AddArg("known")
	// or: n.AddArgValue(kdl.NewStringValue("known", kdl.NoHint()))
	n.SetProp("name", "Joe")
	// or: n.SetPropValue("name", kdl.NewStringValue("Joe", kdl.NoHint()))
	document.AddChild(n)
}

Serialize the Document

// or Write() to an io.Writer
s, err := document.WriteString()