GitXplorerGitXplorer
r

virgo

public
135 stars
7 forks
6 issues

Commits

List of commits on branch default.
Verified
a9591470daacc74bac9618bd48f84623eff233b0

Merge pull request #7 from r2d4/node-without-edge

rr2d4 committed 4 years ago
Unverified
8159070ccb43ec6d577d865aaaccd4fe8cf75f66

add node without edge to grammar

rr2d4 committed 4 years ago
Unverified
beafe4ea7b70f9cb0325748e944c9ec3b0463d43

fix make test

rr2d4 committed 4 years ago
Unverified
472d1e13eb47a61bd666fd79b91360dbd43fb348

MIT license

rr2d4 committed 4 years ago
Unverified
75b5ef6f1ae4c6f84badb029cc7aaf2ec785af69

add reference to python implementation

rr2d4 committed 4 years ago
Unverified
53e942fbe5b20296b4ca95c1fd504b6cda1ac261

typo

rr2d4 committed 4 years ago

README

The README file for this repository.

Virgo Configuration Language

Most configuration problems reduce to graphs, e.g. Dockerfiles and Makefiles

But there are no graph-based configuration languages. So virgo is an attempt to make a programming language that optimizes for natural graph readability, editability, and representation.

Imagine dot language, but focused on config instead of presentation.

Virgo Logo

Virgo is a graph-based configuration language. It has two main features: edge definitions and vertex definitions. The Virgo configuration file then parses into an adjacency list. You can clearly achieve similar results from adding additional conventions and restrictions on YAML or JSON. Much like YAML optimized for human readability, Virgo optimizes for natural graph readability, editability, and representation.

Go

This repository contains a reference implementation written in Go, with yacc and lex definitions.

Python

There is a python implementation maintained at jwg4/pyvirgo which can also be found on PyPi.

// config.vgo

a -> b, c, d -> e <- f, g

Virgo Example

Example

// config.vgo

clean -> parser, lexer -> "src files" -> test

parser = `goyacc parser.y`
lexer  = `golex lex.l`
clean  = `rm lex.yy.go parser.go || true`
"test"   = `go test-v`
"src files"  = `go build ./...`

How to parse and topologically sort the graph with the Go library.

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strings"

	"github.com/pkg/errors"
	"matt-rickard.com/virgo/pkg/virgo"
)

func main() {
	if err := run("config.go"); err != nil {
		log.Fatal(err)
		os.Exit(1)
	}
}

func run(fname string) error {
	f, err := ioutil.ReadFile(fname)
	if err != nil {
		return errors.Wrap(err, "reading file")
	}
	g, err := virgo.Parse(f)
	if err != nil {
		return errors.Wrap(err, "parsing virgo file")
	}

	nodes, err := virgo.TopSort(g)
	if err != nil {
		return errors.Wrap(err, "topological sort")
	}

	out := []string{}
	for _, n := range nodes {
		out = append(out, g.Vertices[n]...)
	}
	fmt.Println(strings.Join(out, "\n"))
	return nil
}

How to parse and topologically sort the graph with the Virgo CLI tool

$ virgo run build.vgo

Or topologically sort from a specific vertex

$ virgo run build.vgo:lexer

Virgo is Open for Proposals

I use virgo in a variety of ways for my own projects. That being said, I'm open to significant language change and feature proposals. Please open up a detailed issue and I'll do my best to respond. I'm also open to taking on more full time maintainers.

Language Reference

  • Newline delimited
  • Line contiuations can be created with a |
  • Single-line comments start with a //
  • Multi-line block comments start with a /* and end with a */

Edge Statement

a -> b, c -> d, e <- f <- g
a -> h
b -> h, i
  • Valid edge operators are right edge ->, left edge <-, and undirected edge --
  • Multiple edge definitions can be strung together per line
  • Multiple endpoints can be specified with a comma , on either side of the edge operator

Vertex Statement

vertex_definition_1 = `
    anything
    can
    go
    ${here}
`
  • Vertices do not require a definition
  • Vertex definitions lines start with the vertex name, followed by an equal sign = followed by a start backtick `, definition, and then end backtick `` `.
  • Vertex definitions are multiline by default and start and end with a backtick `` `
  • Vertex definitions valid characters are [a-zA-Z_:0-9] but cannot start with a digit