Go implementation of Link Foundation's Links Notation (Lino) parser and formatter.
go get github.com/link-foundation/links-notation/gopackage main
import (
"fmt"
"log"
lino "github.com/link-foundation/links-notation/go"
)
func main() {
// Parse links notation
links, err := lino.Parse("papa (lovesMama: loves mama)")
if err != nil {
log.Fatal(err)
}
// Format back to string
output := lino.Format(links)
fmt.Println(output)
}- Parse Links Notation (Lino) into structured Link objects
- Format Link objects back to Lino notation
- Support for inline and indented syntax
- Quoted strings with special characters
- Triple-quoted strings for embedded quotes
- Configurable formatting with
FormatConfig - Full compatibility with other language implementations (JS, Rust, C#, Python)
type Link struct {
ID *string
Values []*Link
}Represents a link in Lino notation. A link can be:
- A reference (ID only, no values)
- A link with ID and values
- A link with only values (no ID)
type FormatConfig struct {
LessParentheses bool // Omit parentheses when safe
IndentString string // String for indentation (default: " ")
PreferInline bool // Prefer inline over indented format
IndentByRefCount int // Indent when ref count >= this value
IndentByLength int // Indent when line length > this value
GroupConsecutive bool // Group consecutive links with same ID
}func Parse(input string) ([]*Link, error)Parses Lino notation text into a slice of Link objects.
func Format(links []*Link) stringFormats a collection of Links as a multi-line string.
func FormatWithConfig(links []*Link, config *FormatConfig) stringFormats Links using the specified FormatConfig.
func NewRef(id string) *LinkCreates a new reference Link (ID only, no values).
func NewLink(id *string, values []*Link) *LinkCreates a new Link with optional ID and values.
func (l *Link) IsRef() boolReturns true if this Link is a simple reference (ID only).
func (l *Link) IsLink() boolReturns true if this Link has values.
func (l *Link) Format(lessParentheses bool) stringFormats the link as a string.
func (l *Link) Equal(other *Link) boolChecks equality with another Link.
// Parse a simple link
links, _ := lino.Parse("(papa has car)")
// Parse with ID and values
links, _ := lino.Parse("(address: source target)")
// Parse multiple links
links, _ := lino.Parse(`(papa has car)
(mama has house)`)// References with spaces need quotes
links, _ := lino.Parse(`("New York": city state)`)
// Special characters
links, _ := lino.Parse(`('key:with:colons': 'value')`)// Indented format is equivalent to inline
indented := `id:
value1
value2`
inline := "(id: value1 value2)"
// Both produce the same result
indentedLinks, _ := lino.Parse(indented)
inlineLinks, _ := lino.Parse(inline)links, _ := lino.Parse("(outer: (inner: value))")
// Deep nesting
links, _ := lino.Parse("(a: (b: (c: (d: value))))")link := lino.NewLink(lino.StrPtr("id"), []*lino.Link{
lino.NewRef("value1"),
lino.NewRef("value2"),
})
// Less parentheses mode
output := link.Format(true) // "id: value1 value2"
// Using FormatConfig
config := lino.DefaultFormatConfig().
WithLessParentheses(true).
WithIndentByRefCount(3)
output = link.FormatWithConfig(config)papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
papa has car
mama has house
(papa and mama) are happy
I'm a friendly AI.
(I'm a friendly AI too.)
(linksNotation: links notation)
3:
papa
loves
mama
Equivalent to: (3: papa loves mama)
cd go
go test -v