README

OGDL for Go

This library is being refactored. If you depend on the stable version, import gopkg.in/rveen/ogdl.v1 instead.

Package ogdl is used to process OGDL, the Ordered Graph Data Language.

OGDL is a textual format to write trees or graphs of text, where indentation and spaces define the structure. Here is an example:

network
  ip 192.168.1.100
  gw 192.168.1.9

The language is simple, either in its textual representation or its number of productions (the specification rules), allowing for compact implementations.

OGDL character streams are normally formed by Unicode characters, and encoded as UTF-8 strings, but any encoding that is ASCII transparent is compatible with the specification and the implementations.

This implementation does not support cyles (OGDL Level 2).

Documentation

The documentation of the package is kindly generated by godoc.org.

Installation

go get github.com/rveen/ogdl

go get gopkg.in/rveen/ogdl.v1  (for the previous -stable- version)

Discussion

There is a list: ogdl-go.

Example: a configuration file

If we have a text file 'conf.ogdl' like this:

eth0
  ip
    192.168.1.1
  gateway
    192.168.1.10
  mask
    255.255.255.0
  timeout
    20

then,

g := ogdl.FromFile("conf.ogdl")
ip := g.Get("eth0.ip").String()
to := g.Get("eth0.timeout").Int64(60)
println("ip:",ip,", timeout:",to)

will print

ip: 192.168.1.1, timeout: 20

If the timeout parameter were not present, then the default value (60) will be assigned to 'to'.

Expand ▾ Collapse ▴

Documentation

Overview

Package ogdl is used to process OGDL, the Ordered Graph Data Language.

OGDL is a textual format to write trees or graphs of text, where indentation and spaces define the structure. Here is an example:

network
  ip 192.168.1.100
  gw 192.168.1.9

The languange is simple, either in its textual representation or its number of productions (the specification rules), allowing for compact implementations.

OGDL character streams are normally formed by Unicode characters, and encoded as UTF-8 strings, but any encoding that is ASCII transparent is compatible with the specification.

See the full spec at http://ogdl.org.

Installation

To install this package just do:

go get github.com/rveen/ogdl

An example

If we have a text file 'config.ogdl' containing:

eth0
  ip
    192.168.1.1
  gateway
    192.168.1.10
  mask
    255.255.255.0
  timeout
    20

then,

g := ogdl.FromFile("config.ogdl")
ip := g.Get("eth0.ip").String()
to := g.Get("eth0.timeout").Int64(60)

println("ip:",ip,", timeout:",to)

will print

ip: 192.168.1.1, timeout: 20

If the timeout parameter was not present, then the default value (60) will be assigned to 'to'. The default value is optional, but be aware that Int64() will return 0 in case that the parameter doesn't exist.

The configuration file can be written in a conciser way:

eth0
  ip      192.168.1.1
  gateway 192.168.1.10
  mask    255.255.255.0
  timeout 20

A template example

The package includes a template processor. It takes an arbitrary input stream with some variables in it, and produces an output stream with the variables resolved out of a Graph object which acts as context.

For example (given the previous config file):

g := ogdl.FromFile("config.ogdl")
t := ogdl.NewTemplate("The gateway's IP is $eth0.gateway")
b := t.Process(g)

string(b) is then:

The gateway's IP is 192.168.1.10

Function signature conventions

Some rules are followed:

.<Type>()      Return the first subnode content converted to the specified type.

.This<Type>()  Return the node content itself converted to the specified type.

.Get()         Return the specified path as a (possible nil) *Graph object.

.Get<Type>()   Return the specified path converted to the specified type.
               These series of functions return value and error.

Index

Examples

Constants

View Source
const (
	TypeExpression = "!e"
	TypePath       = "!p"
	TypeVariable   = "!v"
	TypeSelector   = "!s"
	TypeIndex      = "!i"
	TypeGroup      = "!g"
	TypeArguments  = "!a"
	TypeTemplate   = "!t"
	TypeString     = "!string"

	TypeIf    = "!if"
	TypeEnd   = "!end"
	TypeElse  = "!else"
	TypeFor   = "!for"
	TypeBreak = "!break"
)

    Nodes containing these strings are special

    Variables

    View Source
    var (
    	// ErrInvalidUnread reports an unsuccessful UnreadByte or UnreadRune
    	ErrInvalidUnread = errors.New("invalid use of UnreadByte or UnreadRune")
    
    	// ErrEOS indicates the end of the stream
    	ErrEOS = errors.New("EOS")
    
    	// ErrSpaceNotUniform indicates mixed use of spaces and tabs for indentation
    	ErrSpaceNotUniform = errors.New("space has both tabs and spaces")
    
    	// ErrUnterminatedQuotedString is obvious.
    	ErrUnterminatedQuotedString = errors.New("quoted string not terminated")
    
    	ErrNotANumber       = errors.New("not a number")
    	ErrNotFound         = errors.New("not found")
    	ErrIncompatibleType = errors.New("incompatible type")
    	ErrNilReceiver      = errors.New("nil function receiver")
    	ErrInvalidIndex     = errors.New("invalid index")
    	ErrFunctionNoGraph  = errors.New("functions doesn't return *Graph")
    	ErrInvalidArgs      = errors.New("invalid arguments or nil receiver")
    )

    Functions

    func IsBreakChar

    func IsBreakChar(c byte) bool

      IsBreakChar returns true for 10 and 13 (newline and carriage return)

      func IsDigit

      func IsDigit(c rune) bool

        IsDigit returns true if the given character a numeric digit, as per Unicode.

        func IsEndChar

        func IsEndChar(c byte) bool

          IsEndChar returns true for all integers < 32 that are not newline, carriage return or tab.

          func IsEndRune

          func IsEndRune(c rune) bool

            IsEndRune returns true for all integers < 32 that are not newline, carriage return or tab.

            func IsLetter

            func IsLetter(c rune) bool

              IsLetter returns true if the given character is a letter, as per Unicode.

              func IsSpaceChar

              func IsSpaceChar(c byte) bool

                IsSpaceChar returns true for space and tab

                func IsTextChar

                func IsTextChar(c byte) bool

                  IsTextChar returns true for all integers > 32 and are not OGDL separators (parenthesis and comma)

                  Types

                  type Graph

                  type Graph struct {
                  	This interface{}
                  	Out  []*Graph
                  }

                    Graph is a node with outgoing pointers to other Graph objects. It is implemented as a named list.

                    func FromBinary

                    func FromBinary(b []byte) *Graph

                      FromBinary converts an OGDL binary stream of bytes into a Graph.

                      func FromBinaryFile

                      func FromBinaryFile(file string) *Graph

                        FromBinaryFile converts an OGDL binary stream of bytes into a Graph.

                        func FromBinaryReader

                        func FromBinaryReader(r io.Reader) *Graph

                          FromBinaryReader converts an OGDL binary stream of bytes into a Graph.

                          func FromBytes

                          func FromBytes(b []byte) *Graph

                            FromBytes parses OGDL text contained in a byte array. It returns a *Graph

                            func FromFile

                            func FromFile(s string) *Graph

                              FromFile parses OGDL text contained in a file. It returns a Graph

                              func FromJSON

                              func FromJSON(buf []byte) (*Graph, error)

                                FromJSON converts a JSON text stream into OGDL.

                                Json types returned by Decode/Unmarshall: - bool, for JSON booleans - int64 / float64, for JSON numbers - string, for JSON strings - []interface{}, for JSON arrays - map[string]interface{}, for JSON objects - nil for JSON null

                                TODO I'm not sure about not giving lists a root node, but we need to avoid both useless nesting and also post-simplification (and its unwanted side effects). But, for example [ "a", [ "b", "c" ] ] will be returned as:

                                a
                                b
                                c
                                

                                func FromReader

                                func FromReader(r io.Reader) *Graph

                                  FromReader parses OGDL text coming from a generic io.Reader

                                  func FromString

                                  func FromString(s string) *Graph

                                    FromString parses OGDL text from the given string. It returns a *Graph

                                    func FromStringTypes

                                    func FromStringTypes(s string) *Graph

                                      FromStringTypes parses OGDL text from the given string. It returns a *Graph. Basic types found in the string are converted to their correspongind Go types (either string | int64 | float64 | bool).

                                      func New

                                      func New(n interface{}) *Graph

                                        New returns a pointer to Graph initialized to the object given.

                                        func NewExpression

                                        func NewExpression(s string) *Graph

                                          NewExpression parses an expression in text format (given in the string) to a Graph, in the form of a suitable syntax tree.

                                          expression := expr1 (op2 expr1)*
                                          expr1 := path | constant | op1 path | op1 constant | '(' expr ')' | op1 '(' expr ')'
                                          constant ::= quoted | number
                                          

                                          func NewPath

                                          func NewPath(s string) *Graph

                                            NewPath takes a Unicode string representing an OGDL path, parses it and returns it as a Graph object.

                                            It also parses extended paths, as those used in templates, which may have argument lists.

                                            func NewTemplate

                                            func NewTemplate(s string) *Graph

                                              NewTemplate parses a text template given as a string and converts it to a Graph. Templates have fixed and variable parts. Variables all begin with '$'.

                                              A template is a text file in any format: plain text, HTML, XML, OGDL or whatever. The dolar sign acts as an escape character that switches from the text to the variable plane. Parsed templates are converted back to text by evaluating the variable parts against a Graph object, by means of the Process() method.

                                              Template grammar

                                              template ::= ( text | variable )*
                                              
                                              variable ::= ('$' path) | ('$' '(' expression ')') | ('$' '{' expression '}')
                                              path ::= as defined in path.go
                                              expression ::= as defined in expression.go
                                              

                                              Some variables act as directives: $if, $else, $end, $for, $break.

                                              $if(expression)
                                              $else
                                              $end
                                              
                                              $for(destPath,sourcepath)
                                                $break
                                              $end
                                              
                                              Example
                                              Output:
                                              
                                              Hello, Jenny
                                              

                                              func NewTemplateFromBytes

                                              func NewTemplateFromBytes(b []byte) *Graph

                                                NewTemplateFromBytes has the same function as NewTemplate except that the input stream is a byte array.

                                                func (*Graph) Add

                                                func (g *Graph) Add(n interface{}) *Graph

                                                  Add adds a subnode to the current node.

                                                  func (*Graph) AddNodes

                                                  func (g *Graph) AddNodes(g2 *Graph) *Graph

                                                    AddNodes adds subnodes of the given Graph to the current node.

                                                    func (*Graph) Binary

                                                    func (g *Graph) Binary() []byte

                                                      Binary converts a Graph to a binary OGDL byte stream.

                                                      func (*Graph) Bool

                                                      func (g *Graph) Bool(def ...bool) bool

                                                        Bool returns the node as a boolean. If the node is not a boolean, it returns false, or the default value if given.

                                                        func (*Graph) Bytes

                                                        func (g *Graph) Bytes() []byte

                                                          Bytes returns the graph as []byte, or nil if not possble.

                                                          func (*Graph) Check

                                                          func (g *Graph) Check(x *Graph) (bool, string)

                                                            Check returns true if the Graph given as a parameter conforms to the schema represented by the receiver Graph.

                                                            Example
                                                            Output:
                                                            
                                                            true
                                                            

                                                            func (*Graph) Clear

                                                            func (g *Graph) Clear()

                                                              Clear removes all subnodes

                                                              func (*Graph) Clone

                                                              func (g *Graph) Clone() *Graph

                                                                Clone returns a copy of the current graph.

                                                                Warning (from the Go faq): Copying an interface value makes a copy of the thing stored in the interface value. If the interface value holds a struct, copying the interface value makes a copy of the struct. If the interface value holds a pointer, copying the interface value makes a copy of the pointer, but not the data it points to.

                                                                func (*Graph) Copy

                                                                func (g *Graph) Copy(c *Graph)

                                                                  Copy adds a copy of the graph given to the current graph.

                                                                  Warning (from the Go faq): Copying an interface value makes a copy of the thing stored in the interface value. If the interface value holds a struct, copying the interface value makes a copy of the struct. If the interface value holds a pointer, copying the interface value makes a copy of the pointer, but not the data it points to.

                                                                  func (*Graph) Create

                                                                  func (g *Graph) Create(s string) *Graph

                                                                    Create returns the first subnode whose string value is equal to the given string, with its subnodes deleted. If not found, the node is created and returned.

                                                                    func (*Graph) Delete

                                                                    func (g *Graph) Delete(n interface{})

                                                                      Delete removes all subnodes with the given content

                                                                      func (*Graph) DeleteAt

                                                                      func (g *Graph) DeleteAt(i int)

                                                                        DeleteAt removes a subnode by index

                                                                        func (*Graph) Equals

                                                                        func (g *Graph) Equals(c *Graph) bool

                                                                          Equals returns true if the given graph and the receiver graph are equal.

                                                                          func (*Graph) Eval

                                                                          func (g *Graph) Eval(e *Graph) (interface{}, error)

                                                                            Eval takes a parsed expression and evaluates it in the context of the current graph.

                                                                            func (*Graph) Find

                                                                            func (g *Graph) Find(re string) (*Graph, error)

                                                                              Find returns a Graph with all subnodes that match the regular expression given. It only walks through the subnodes of the current Graph. If the regex doesn't compile, an error will be returned. If the result set is empty, both return values are nil (no error is signaled).

                                                                              func (*Graph) Float64

                                                                              func (g *Graph) Float64(def ...float64) float64

                                                                                Float64 returns the node as a float64. If the node is not a number, it return NaN, or the default value if given.

                                                                                func (*Graph) Get

                                                                                func (g *Graph) Get(s string) *Graph

                                                                                  Get recurses a Graph following a given path and returns the result.

                                                                                  This function returns a *Graph in any condition. When there is nothing to return, a nil Graph is returned. This behavior is designed so that the next function in a chain never gets an invalid receiver, avoiding null pointer errors.

                                                                                  OGDL Path: elements are separated by '.' or [] or {} index := [N] selector := {N} tokens can be quoted

                                                                                  func (*Graph) GetAt

                                                                                  func (g *Graph) GetAt(i int) *Graph

                                                                                    GetAt returns a subnode by index, or nil if the index is out of range.

                                                                                    func (*Graph) GetBool

                                                                                    func (g *Graph) GetBool(path string) (bool, error)

                                                                                      GetBool returns the result of applying a path to the given Graph. The result is returned as a bool. If the path result cannot be converted to a boolean, then an error is returned.

                                                                                      func (*Graph) GetBytes

                                                                                      func (g *Graph) GetBytes(path string) ([]byte, error)

                                                                                        GetBytes returns the result of applying a path to the given Graph. The result is returned as a byte slice.

                                                                                        func (*Graph) GetFloat64

                                                                                        func (g *Graph) GetFloat64(path string) (float64, error)

                                                                                          GetFloat64 returns the result of applying a path to the given Graph. The result is returned as a float64. If the path result cannot be converted to a float, then an error is returned.

                                                                                          func (*Graph) GetInt64

                                                                                          func (g *Graph) GetInt64(path string) (int64, error)

                                                                                            GetInt64 returns the result of applying a path to the given Graph. The result is returned as an int64. If the path result cannot be converted to an integer, then an error is returned.

                                                                                            func (*Graph) GetString

                                                                                            func (g *Graph) GetString(path string) (string, error)

                                                                                              GetString returns the result of applying a path to the given Graph. The result is returned as a string. If the error information is not used, then this method is equivalent to Get(path).String()

                                                                                              func (*Graph) Int64

                                                                                              func (g *Graph) Int64(def ...int64) int64

                                                                                                Int64 returns the node as an int64. If the node is not a number, it returns 0, or the default value if given.

                                                                                                func (*Graph) Interface

                                                                                                func (g *Graph) Interface() interface{}

                                                                                                  Interface returns the first child of this node as an interface

                                                                                                  func (*Graph) JSON

                                                                                                  func (g *Graph) JSON() []byte

                                                                                                    JSON produces JSON text from a Graph

                                                                                                    JSON has maps (objects, {}), lists (arrays, []) and values.

                                                                                                    Values can be strings, numbers, maps, lists, 'true', 'false' or 'null'

                                                                                                    map ::= '{' string ':' value [',' string : value]* '}' list ::= '[' value [',' value]* ']'

                                                                                                    By definition, since maps and lists cannot be distinguished in OGDL, any list should have a '_' root node. Any non-leaf node is a map (unless is contains '_', obviously).

                                                                                                    func (*Graph) Len

                                                                                                    func (g *Graph) Len() int

                                                                                                      Len returns the number of subnodes (outgoing edges, out degree) of this node.

                                                                                                      func (*Graph) Node

                                                                                                      func (g *Graph) Node(s string) *Graph

                                                                                                        Node returns the first subnode whose string value is equal to the given string. It returns nil if not found.

                                                                                                        func (*Graph) Number

                                                                                                        func (g *Graph) Number() interface{}

                                                                                                          Number returns either a float64, int64 or nil

                                                                                                          func (*Graph) Process

                                                                                                          func (g *Graph) Process(ctx *Graph) []byte

                                                                                                            Process processes the parsed template, returning the resulting text in a byte array. The variable parts are resolved out of the Graph given.

                                                                                                            Example (For)
                                                                                                            Output:
                                                                                                            
                                                                                                            cvm
                                                                                                            req
                                                                                                              stkreq
                                                                                                              sysreq
                                                                                                            design
                                                                                                              hardware
                                                                                                            cvm
                                                                                                            req
                                                                                                            - stkreq
                                                                                                            - sysreq
                                                                                                            design
                                                                                                            - hardware
                                                                                                            

                                                                                                            func (*Graph) Scalar

                                                                                                            func (g *Graph) Scalar() interface{}

                                                                                                              Scalar returns the current node content, reducing the number of types following these rules:

                                                                                                              uint* -> int64
                                                                                                              int*  -> int64
                                                                                                              float* -> float64
                                                                                                              byte -> int64
                                                                                                              rune -> int64
                                                                                                              bool -> bool
                                                                                                              string, []byte: if it represents an int or float or bool,
                                                                                                                convert to int64, float64 or bool
                                                                                                              

                                                                                                              Any other type is returned as is.

                                                                                                              func (*Graph) Set

                                                                                                              func (g *Graph) Set(s string, val interface{}) *Graph

                                                                                                                Set sets the first occurrence of the given path to the value given.

                                                                                                                Example
                                                                                                                Output:
                                                                                                                
                                                                                                                a
                                                                                                                  b
                                                                                                                    d
                                                                                                                
                                                                                                                Example (A)
                                                                                                                Output:
                                                                                                                
                                                                                                                R
                                                                                                                  b
                                                                                                                  id
                                                                                                                    1
                                                                                                                
                                                                                                                Example (Index)
                                                                                                                Output:
                                                                                                                
                                                                                                                a
                                                                                                                  b
                                                                                                                    c
                                                                                                                  d
                                                                                                                

                                                                                                                func (*Graph) Show

                                                                                                                func (g *Graph) Show() string

                                                                                                                  Show prints the Graph as text including this (the top) node.

                                                                                                                  func (*Graph) String

                                                                                                                  func (g *Graph) String(def ...string) string

                                                                                                                    String returns a string representation of this node, or an empty string. This function doesn't return an error, because it is mostly used in single variable return situations. String accepts one default value, which will be returned instead of an empty string.

                                                                                                                    func (*Graph) StringCSV

                                                                                                                    func (g *Graph) StringCSV(def ...string) string

                                                                                                                      StringCSV returns a comma separated value representation of all direct subnodes. StringCSV accepts one default value, which will be returned instead of an empty string.

                                                                                                                      func (*Graph) Substitute

                                                                                                                      func (g *Graph) Substitute(s string, v interface{})

                                                                                                                        Substitute traverses the graph substituting all nodes with content equal to s by v.

                                                                                                                        func (*Graph) Text

                                                                                                                        func (g *Graph) Text() string

                                                                                                                          Text is the OGDL text emitter. It converts a Graph into OGDL text.

                                                                                                                          Strings are quoted if they contain spaces, newlines or special characters. Null elements are not printed, and act as transparent nodes.

                                                                                                                          func (*Graph) ThisBytes

                                                                                                                          func (g *Graph) ThisBytes() []byte

                                                                                                                            ThisBytes returns the node as []byte, or nil if not possble.

                                                                                                                            func (*Graph) ThisFloat64

                                                                                                                            func (g *Graph) ThisFloat64() (float64, bool)

                                                                                                                              ThisFloat64 returns a float64

                                                                                                                              func (*Graph) ThisInt64

                                                                                                                              func (g *Graph) ThisInt64() (int64, bool)

                                                                                                                                ThisInt64 returns a int64 or nil

                                                                                                                                func (*Graph) ThisNumber

                                                                                                                                func (g *Graph) ThisNumber() interface{}

                                                                                                                                  ThisNumber returns either a float64, int64 or nil

                                                                                                                                  func (*Graph) ThisScalar

                                                                                                                                  func (g *Graph) ThisScalar() interface{}

                                                                                                                                    ThisScalar returns this node's content as an interface

                                                                                                                                    func (*Graph) ThisString

                                                                                                                                    func (g *Graph) ThisString(def ...string) string

                                                                                                                                      ThisString returns the current node content as a string

                                                                                                                                      func (*Graph) ThisType

                                                                                                                                      func (g *Graph) ThisType() string

                                                                                                                                        ThisType returns the name of the native type contained in the current node.

                                                                                                                                        func (*Graph) ThisValue

                                                                                                                                        func (g *Graph) ThisValue() reflect.Value

                                                                                                                                          ThisValue returns this node as a reflect.Value.

                                                                                                                                          func (*Graph) Value

                                                                                                                                          func (g *Graph) Value() reflect.Value

                                                                                                                                            Value returns the node as a reflect.Value.

                                                                                                                                            type Lexer

                                                                                                                                            type Lexer struct {
                                                                                                                                            	// contains filtered or unexported fields
                                                                                                                                            }

                                                                                                                                              Lexer implements buffering for an io.Reader object, with multiple byte unread operations allowed.

                                                                                                                                              func NewLexer

                                                                                                                                              func NewLexer(rd io.Reader) *Lexer

                                                                                                                                                NewLexer returns a new Lexer whose buffer has the default size.

                                                                                                                                                func (*Lexer) Block

                                                                                                                                                func (p *Lexer) Block(nsp int) (string, bool)

                                                                                                                                                  Block ::= '\\' NL LINES_OF_TEXT

                                                                                                                                                  func (*Lexer) Break

                                                                                                                                                  func (p *Lexer) Break() bool

                                                                                                                                                    Break (= newline) is NL, CR or CR+NL

                                                                                                                                                    func (*Lexer) Byte

                                                                                                                                                    func (p *Lexer) Byte() (byte, error)

                                                                                                                                                      Byte reads and returns a single byte. If no byte is available, returns 0 and an error.

                                                                                                                                                      func (*Lexer) Comment

                                                                                                                                                      func (p *Lexer) Comment() bool

                                                                                                                                                        Comment consumes anything from # up to the end of the line.

                                                                                                                                                        func (*Lexer) End

                                                                                                                                                        func (p *Lexer) End() bool

                                                                                                                                                          End returns true if the end of stream has been reached.

                                                                                                                                                          func (*Lexer) Error

                                                                                                                                                          func (p *Lexer) Error() error

                                                                                                                                                          func (*Lexer) Integer

                                                                                                                                                          func (p *Lexer) Integer() (string, bool)

                                                                                                                                                            Integer returns true if it finds an (unsigned) integer at the current parser position. It returns also the number found.

                                                                                                                                                            func (*Lexer) Number

                                                                                                                                                            func (p *Lexer) Number() (string, bool)

                                                                                                                                                              Number returns true if it finds a number at the current parser position. It returns also the number found. TODO recognize exp notation ?

                                                                                                                                                              func (*Lexer) Operator

                                                                                                                                                              func (p *Lexer) Operator() (string, bool)

                                                                                                                                                                Operator returns true if it finds an operator at the current parser position It returns also the operator found.

                                                                                                                                                                func (*Lexer) PeekByte

                                                                                                                                                                func (p *Lexer) PeekByte() byte

                                                                                                                                                                  PeekByte returns the next byte witohut consuming it

                                                                                                                                                                  func (*Lexer) PeekRune

                                                                                                                                                                  func (p *Lexer) PeekRune() (rune, error)

                                                                                                                                                                    PeekRune returns the next rune witohut consuming it

                                                                                                                                                                    func (*Lexer) Quoted

                                                                                                                                                                    func (p *Lexer) Quoted(ind int) (string, bool, error)

                                                                                                                                                                      Quoted string. Can have newlines in it. It returns the string if any, a bool indicating if a quoted string was found, and a possible error.

                                                                                                                                                                      func (*Lexer) Rune

                                                                                                                                                                      func (p *Lexer) Rune() (rune, error)

                                                                                                                                                                        Rune reads a single UTF-8 encoded Unicode character and returns the rune. If the encoded rune is invalid, it consumes one byte and returns unicode.ReplacementChar (U+FFFD) with a size of 1.

                                                                                                                                                                        func (*Lexer) Scalar

                                                                                                                                                                        func (p *Lexer) Scalar(n int) (string, bool)

                                                                                                                                                                          Scalar ::= quoted | string

                                                                                                                                                                          func (*Lexer) ScalarType

                                                                                                                                                                          func (p *Lexer) ScalarType(n int) (interface{}, bool)

                                                                                                                                                                            ScalarType ::= string | int64 | float64 | bool

                                                                                                                                                                            func (*Lexer) Space

                                                                                                                                                                            func (p *Lexer) Space() (int, byte)

                                                                                                                                                                              Space is (0x20|0x09)+. It returns a boolean indicating if space has been found, and an integer indicating how many spaces, iff uniform (either all 0x20 or 0x09)

                                                                                                                                                                              func (*Lexer) String

                                                                                                                                                                              func (p *Lexer) String() (string, bool)

                                                                                                                                                                                String is a concatenation of characters that are > 0x20

                                                                                                                                                                                func (*Lexer) StringStop

                                                                                                                                                                                func (p *Lexer) StringStop(stopBytes []byte) (string, bool)

                                                                                                                                                                                  StringStop is a concatenation of text bytes that are not in the parameter stopBytes

                                                                                                                                                                                  func (*Lexer) TemplateText

                                                                                                                                                                                  func (p *Lexer) TemplateText() (string, bool)

                                                                                                                                                                                    TemplateText parses text in a template.

                                                                                                                                                                                    func (*Lexer) Token8

                                                                                                                                                                                    func (p *Lexer) Token8() (string, bool)

                                                                                                                                                                                      Token8 reads from the Parser input stream and returns a token, if any. A token is defined as a sequence of Unicode letters and/or numbers and/or _.

                                                                                                                                                                                      func (*Lexer) UnreadByte

                                                                                                                                                                                      func (p *Lexer) UnreadByte()

                                                                                                                                                                                        UnreadByte unreads the last byte. It can unread all buffered bytes.

                                                                                                                                                                                        func (*Lexer) UnreadRune

                                                                                                                                                                                        func (p *Lexer) UnreadRune() error

                                                                                                                                                                                          UnreadRune unreads the last rune.

                                                                                                                                                                                          func (*Lexer) WhiteSpace

                                                                                                                                                                                          func (p *Lexer) WhiteSpace() bool

                                                                                                                                                                                            WhiteSpace is equivalent to Space | Break. It consumes all white space, whether spaces, tabs or newlines

                                                                                                                                                                                            type Log

                                                                                                                                                                                            type Log struct {
                                                                                                                                                                                            	// contains filtered or unexported fields
                                                                                                                                                                                            }

                                                                                                                                                                                              Log is a log store for binary OGDL objects.

                                                                                                                                                                                              All objects are appended to a file, and a position is returned.

                                                                                                                                                                                              func OpenLog

                                                                                                                                                                                              func OpenLog(file string) (*Log, error)

                                                                                                                                                                                                OpenLog opens a log file. If the file doesn't exist, it is created.

                                                                                                                                                                                                func (*Log) Add

                                                                                                                                                                                                func (log *Log) Add(g *Graph) int64

                                                                                                                                                                                                  Add adds an OGDL object to the log. The starting position into the log is returned.

                                                                                                                                                                                                  func (*Log) AddBinary

                                                                                                                                                                                                  func (log *Log) AddBinary(b []byte) int64

                                                                                                                                                                                                    AddBinary adds an OGDL binary object to the log. The starting position into the log is returned.

                                                                                                                                                                                                    func (*Log) Close

                                                                                                                                                                                                    func (log *Log) Close()

                                                                                                                                                                                                      Close closes a log file

                                                                                                                                                                                                      func (*Log) Get

                                                                                                                                                                                                      func (log *Log) Get(i int64) (*Graph, int64, error)

                                                                                                                                                                                                        Get returns the OGDL object at the position given and the position of the next object, or an error.

                                                                                                                                                                                                        func (*Log) GetBinary

                                                                                                                                                                                                        func (log *Log) GetBinary(i int64) ([]byte, int64, error)

                                                                                                                                                                                                          GetBinary returns the OGDL object at the position given and the position of the next object, or an error. The object returned is in binary form, exactly as it is stored in the log.

                                                                                                                                                                                                          func (*Log) Sync

                                                                                                                                                                                                          func (log *Log) Sync()

                                                                                                                                                                                                            Sync commits the changes to disk (the exact behavior is OS dependent).

                                                                                                                                                                                                            type Parser

                                                                                                                                                                                                            type Parser struct {
                                                                                                                                                                                                            	Lexer // Buffered byte and rune readed
                                                                                                                                                                                                            	// contains filtered or unexported fields
                                                                                                                                                                                                            }

                                                                                                                                                                                                              Parser embeds Lexer and holds some state

                                                                                                                                                                                                              func NewBytesParser

                                                                                                                                                                                                              func NewBytesParser(buf []byte) *Parser

                                                                                                                                                                                                                NewBytesParser returns a new Parser from a byte array

                                                                                                                                                                                                                func NewParser

                                                                                                                                                                                                                func NewParser(rd io.Reader) *Parser

                                                                                                                                                                                                                  NewParser return a new Parser from a Reader

                                                                                                                                                                                                                  func NewStringParser

                                                                                                                                                                                                                  func NewStringParser(s string) *Parser

                                                                                                                                                                                                                    NewStringParser returns a new Parser from a string

                                                                                                                                                                                                                    func (*Parser) ArgList

                                                                                                                                                                                                                    func (p *Parser) ArgList() bool

                                                                                                                                                                                                                      ArgList ::= space? expression space? [, space? expression]* space?

                                                                                                                                                                                                                      arglist < stream > events

                                                                                                                                                                                                                      arglist can be empty, then returning false (this fact is not represented in the BNF definition).

                                                                                                                                                                                                                      func (*Parser) Args

                                                                                                                                                                                                                      func (p *Parser) Args(dot bool) (bool, error)

                                                                                                                                                                                                                        Args ::= '(' space? sequence? space? ')'

                                                                                                                                                                                                                        func (*Parser) Dec

                                                                                                                                                                                                                        func (p *Parser) Dec()

                                                                                                                                                                                                                          Dec decreses the event handler level by one

                                                                                                                                                                                                                          func (*Parser) Emit

                                                                                                                                                                                                                          func (p *Parser) Emit(s string)

                                                                                                                                                                                                                            Emit outputs a string event at the current level. This will show up in the graph

                                                                                                                                                                                                                            func (*Parser) Expression

                                                                                                                                                                                                                            func (p *Parser) Expression() bool

                                                                                                                                                                                                                              Expression := expr1 (op2 expr1)*

                                                                                                                                                                                                                              func (*Parser) Graph

                                                                                                                                                                                                                              func (p *Parser) Graph() *Graph

                                                                                                                                                                                                                                Graph returns the parser tree

                                                                                                                                                                                                                                func (*Parser) Handler

                                                                                                                                                                                                                                func (p *Parser) Handler() *SimpleEventHandler

                                                                                                                                                                                                                                  Handler returns the event handler being used

                                                                                                                                                                                                                                  func (*Parser) Inc

                                                                                                                                                                                                                                  func (p *Parser) Inc()

                                                                                                                                                                                                                                    Inc increases the event handler level by one

                                                                                                                                                                                                                                    func (*Parser) Index

                                                                                                                                                                                                                                    func (p *Parser) Index() bool

                                                                                                                                                                                                                                      Index ::= '[' expression ']'

                                                                                                                                                                                                                                      func (*Parser) Ogdl

                                                                                                                                                                                                                                      func (p *Parser) Ogdl()

                                                                                                                                                                                                                                        Ogdl is the main function for parsing OGDL text.

                                                                                                                                                                                                                                        An OGDL stream is a sequence of lines (a block of text or a quoted string can span multiple lines but is still parsed by Line())

                                                                                                                                                                                                                                        Graph ::= Line* End
                                                                                                                                                                                                                                        

                                                                                                                                                                                                                                        func (*Parser) OgdlTypes

                                                                                                                                                                                                                                        func (p *Parser) OgdlTypes()

                                                                                                                                                                                                                                          OgdlTypes is the main function for parsing OGDL text.

                                                                                                                                                                                                                                          This version tries to convert unquoted strings that can be parsed as ints, floats or bools to their corresponding type in Go (string | int64 | float64 | bool).

                                                                                                                                                                                                                                          func (*Parser) Path

                                                                                                                                                                                                                                          func (p *Parser) Path() bool

                                                                                                                                                                                                                                            Path parses an OGDL path, or an extended path as used in templates.

                                                                                                                                                                                                                                            path ::= element ('.' element)*
                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                            element ::= token | integer | quoted | group | index | selector
                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                            (Dot optional before Group, Index, Selector)
                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                            group := '(' Expression [[,] Expression]* ')'
                                                                                                                                                                                                                                            index := '[' Expression ']'
                                                                                                                                                                                                                                            selector := '{' Expression '}'
                                                                                                                                                                                                                                            

                                                                                                                                                                                                                                            The OGDL parser doesn't need to know about Unicode. The character classification relies on values < 127, thus in the ASCII range, which is also part of Unicode.

                                                                                                                                                                                                                                            Note: On the other hand it would be stupid not to recognize for example Unicode quotation marks if we know that we have UTF-8. But when do we know for sure?

                                                                                                                                                                                                                                            func (*Parser) Selector

                                                                                                                                                                                                                                            func (p *Parser) Selector() bool

                                                                                                                                                                                                                                              Selector ::= '{' expression? '}'

                                                                                                                                                                                                                                              func (*Parser) Template

                                                                                                                                                                                                                                              func (p *Parser) Template()

                                                                                                                                                                                                                                                Template ::= (Text | Variable)*

                                                                                                                                                                                                                                                func (*Parser) Text

                                                                                                                                                                                                                                                func (p *Parser) Text() bool

                                                                                                                                                                                                                                                  Text returns the next text part of the template (until it finds a variable)

                                                                                                                                                                                                                                                  func (*Parser) UnaryExpression

                                                                                                                                                                                                                                                  func (p *Parser) UnaryExpression() bool

                                                                                                                                                                                                                                                    UnaryExpression := cpath | constant | op1 cpath | op1 constant | '(' expr ')' | op1 '(' expr ')'

                                                                                                                                                                                                                                                    func (*Parser) Variable

                                                                                                                                                                                                                                                    func (p *Parser) Variable() bool

                                                                                                                                                                                                                                                      Variable parses variables in a template. They begin with $.

                                                                                                                                                                                                                                                      type SimpleEventHandler

                                                                                                                                                                                                                                                      type SimpleEventHandler struct {
                                                                                                                                                                                                                                                      	// contains filtered or unexported fields
                                                                                                                                                                                                                                                      }

                                                                                                                                                                                                                                                        SimpleEventHandler receives events and produces a tree.

                                                                                                                                                                                                                                                        func (*SimpleEventHandler) Add

                                                                                                                                                                                                                                                        func (e *SimpleEventHandler) Add(s string)

                                                                                                                                                                                                                                                          Add creates a string node at the current level.

                                                                                                                                                                                                                                                          func (*SimpleEventHandler) AddAt

                                                                                                                                                                                                                                                          func (e *SimpleEventHandler) AddAt(s string, lv int)

                                                                                                                                                                                                                                                            AddAt creates a string node at the specified level.

                                                                                                                                                                                                                                                            func (*SimpleEventHandler) AddBytes

                                                                                                                                                                                                                                                            func (e *SimpleEventHandler) AddBytes(b []byte)

                                                                                                                                                                                                                                                              AddBytes creates a byte array node at the current level

                                                                                                                                                                                                                                                              func (*SimpleEventHandler) AddBytesAt

                                                                                                                                                                                                                                                              func (e *SimpleEventHandler) AddBytesAt(b []byte, lv int)

                                                                                                                                                                                                                                                                AddBytesAt creates a byte array node at the specified level

                                                                                                                                                                                                                                                                func (*SimpleEventHandler) AddItf

                                                                                                                                                                                                                                                                func (e *SimpleEventHandler) AddItf(i interface{})

                                                                                                                                                                                                                                                                  AddItf creates a string node at the current level.

                                                                                                                                                                                                                                                                  func (*SimpleEventHandler) Dec

                                                                                                                                                                                                                                                                  func (e *SimpleEventHandler) Dec()

                                                                                                                                                                                                                                                                    Dec decrements the current level by 1.

                                                                                                                                                                                                                                                                    func (*SimpleEventHandler) Delete

                                                                                                                                                                                                                                                                    func (e *SimpleEventHandler) Delete()

                                                                                                                                                                                                                                                                      Delete removes the last node added

                                                                                                                                                                                                                                                                      func (*SimpleEventHandler) Inc

                                                                                                                                                                                                                                                                      func (e *SimpleEventHandler) Inc()

                                                                                                                                                                                                                                                                        Inc increments the current level by 1.

                                                                                                                                                                                                                                                                        func (*SimpleEventHandler) Level

                                                                                                                                                                                                                                                                        func (e *SimpleEventHandler) Level() int

                                                                                                                                                                                                                                                                          Level returns the current level

                                                                                                                                                                                                                                                                          func (*SimpleEventHandler) SetLevel

                                                                                                                                                                                                                                                                          func (e *SimpleEventHandler) SetLevel(l int)

                                                                                                                                                                                                                                                                            SetLevel sets the current level

                                                                                                                                                                                                                                                                            func (*SimpleEventHandler) Tree

                                                                                                                                                                                                                                                                            func (e *SimpleEventHandler) Tree() *Graph

                                                                                                                                                                                                                                                                              Tree returns the Graph object built from the events sent to this event handler.

                                                                                                                                                                                                                                                                              Directories

                                                                                                                                                                                                                                                                              Path Synopsis
                                                                                                                                                                                                                                                                              cmd
                                                                                                                                                                                                                                                                              gpath
                                                                                                                                                                                                                                                                              gpath <path> [file] Return the specified path from an OGDL file, or from stdin.
                                                                                                                                                                                                                                                                              gpath <path> [file] Return the specified path from an OGDL file, or from stdin.
                                                                                                                                                                                                                                                                              gtemplate
                                                                                                                                                                                                                                                                              gtemplate <template_file> [ogdl_file]* Processes a template file and solves variables in it using data from any of the OGDL files given
                                                                                                                                                                                                                                                                              gtemplate <template_file> [ogdl_file]* Processes a template file and solves variables in it using data from any of the OGDL files given
                                                                                                                                                                                                                                                                              json2ogdl
                                                                                                                                                                                                                                                                              json2ogdl [json_file]*
                                                                                                                                                                                                                                                                              json2ogdl [json_file]*
                                                                                                                                                                                                                                                                              io