tidata

package
v0.12.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

A parser for tab indented trees of structured data.

Doc	:=	{ Elem | \n | Comment }

Elem	:=	N*\t Key [ \t Value ] \n
		{ (N+1)*\t Elem \n }

Comment	:=	{ \t } CommentPfx \n

Whitespace surrounding a Key/Value pair will be stripped. The comment prefix can be configured.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Sep            string // a string separating key and value, e.g. ":"
	MapSym         string
	KeyToFieldName func(string) string
	MultiStringSep string
}

type Deferred

type Deferred interface {
	DeferredWork(arg interface{}) error
}

type DeferredWorkRunner

type DeferredWorkRunner interface {
	RunDeferredWork(func(arg interface{}) error) error
}

type Elem

type Elem struct {
	Text     string
	Children []Elem
	LineNum  int
}

func (Elem) Decode

func (e Elem) Decode(i interface{}, c *Config) (err error)

func (*Elem) JoinSubElems

func (e *Elem) JoinSubElems(initialIndent, indent, sep string) string

func (Elem) Key

func (e Elem) Key() (key string)

func (*Elem) Lookup

func (el *Elem) Lookup(key string) (i int, e *Elem)

Find the first occurance of ‘key’ in the list of childs, on success, return the corresponding slice index and a pointer to the Elem. Otherwise, return nil.

func (*Elem) MapChildren

func (el *Elem) MapChildren() (m map[string]*Elem, err error)

Create a map from an Elem's slice of children. Each key of a child will be used as a key into the map, a pointer to the child's Elem as value.

func (*Elem) Match

func (el *Elem) Match(key string) bool

func (*Elem) String

func (e *Elem) String() string

func (Elem) Value

func (e Elem) Value() (val string)

type Error

type Error struct {
	Err error
	Key string
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Line

func (e *Error) Line() int

type Postprocessor

type Postprocessor interface {
	Postprocess() error
}

type Reader

type Reader struct {
	CommentPrefix        string
	CommentPrefixEscaped string

	TrimPrefix   string
	StripUtf8BOM bool

	LineNum int
	// contains filtered or unexported fields
}

func NewReader

func NewReader(s text.Scanner) *Reader

func (*Reader) ReadAll

func (r *Reader) ReadAll() (top *Elem, err error)

Parse a whole file into atree structure of Elems and return a pointer to the root Elem.

type StructPreprocessor

type StructPreprocessor interface {
	Preprocess(*Elem) error
}

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value string       // description of tidata value - "bool", "array", "number -5"
	Type  reflect.Type // type of Go value it could not be assigned to
}

An UnmarshalTypeError describes a tidata value that was not appropriate for a value of a specific Go type.

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalTidata(Elem) error
}

Jump to

Keyboard shortcuts

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