sparse

package module
v0.0.0-...-6ddf257 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2020 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package sparse implements a sparse definition parser.

Sparse is effectively an attribute language parser, where the language resembles Quake 3 style shaders. For example:

textures/base/wall_arc_01 {
        { # unit
                map textures/base/wall_arc_01.tga
        }
        {
                map textures/base/wall_arc_01.glow.tga
                blend add
        }

        next-line-brace
        {
        }

        no-collision!
        depth lte
        alpha always
        grid
                1     1     1 \
                1     1     1 \
                1     1     1
}

Which would yield the following Pieces (either via a Parser or calling Parse):

NodeEnter("textures/base/wall_arc_01")
NodeEnter("") // Unnamed nodes are given the empty key
Comment(" unit") // If ReadComments(true)
Field{"map", "textures/base/wall_arc_01.tga"}
NodeLeave(2) // The integer value corresponds to node depth
NodeEnter()
Field{"map", "textures/base/wall_arc_01.glow.tga"}
Field{"blend", "add"}
NodeLeave(2)
NodeEnter("next-line-brace") // Names go until they encounter a value, brace, or semicolon.
NodeLeave(2)
Field{"no-collision", ""}
Field{"depth", "lte"}
Field{"alpha", "always"}
Field{"grid", "1 1 1\n1 1 1\n1 1 1"
NodeLeave(1)

Index

Constants

View Source
const (
	KindField pieceKind = 1 + iota
	KindComment
	KindNodeEnter
	KindNodeLeave
)

Variables

View Source
var ErrUnexpectedNodeLeave = errors.New("sparse: unexpected end of node")

Functions

This section is empty.

Types

type ASCIIReader

type ASCIIReader struct{ io.Reader }

func (ASCIIReader) ReadByte

func (r ASCIIReader) ReadByte() (byte, error)

func (ASCIIReader) ReadBytes

func (r ASCIIReader) ReadBytes(delim byte) ([]byte, error)

func (ASCIIReader) ReadRune

func (r ASCIIReader) ReadRune() (rune, int, error)

type Comment

type Comment string

func (Comment) GoString

func (c Comment) GoString() string

func (Comment) Kind

func (c Comment) Kind() Kind

func (Comment) String

func (c Comment) String() string

type CompressWhitespace

type CompressWhitespace bool

type Configuration

type Configuration interface {
	// contains filtered or unexported methods
}

type Field

type Field struct{ Key, Value string }

func (Field) GoString

func (f Field) GoString() string

func (Field) Kind

func (f Field) Kind() Kind

func (Field) String

func (f Field) String() string

type Kind

type Kind interface {
	// contains filtered or unexported methods
}

type NodeEnter

type NodeEnter string

func (NodeEnter) GoString

func (s NodeEnter) GoString() string

func (NodeEnter) Kind

func (s NodeEnter) Kind() Kind

func (NodeEnter) String

func (s NodeEnter) String() string

type NodeLeave

type NodeLeave int

func (NodeLeave) GoString

func (l NodeLeave) GoString() string

func (NodeLeave) Kind

func (NodeLeave) Kind() Kind

func (NodeLeave) String

func (NodeLeave) String() string

type Parser

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

func NewParser

func NewParser(configs ...Configuration) *Parser

func (*Parser) Read

func (p *Parser) Read(r Reader) (piece Piece, err error)

func (*Parser) Reset

func (p *Parser) Reset(configs ...Configuration)

type Piece

type Piece interface {
	Kind() Kind
	String() string
	// contains filtered or unexported methods
}

func Parse

func Parse(r Reader, configs ...Configuration) (pieces []Piece, err error)

type ReadComments

type ReadComments bool

type Reader

type Reader interface {
	io.Reader
	io.RuneReader
}

type TrimWhitespace

type TrimWhitespace bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL