parser

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: MIT Imports: 5 Imported by: 23

Documentation

Overview

Package parser implements a parser for TOML, as defined by the TOML v1 specification https://toml.io/en/v1.0.0.

Unlike other TOML libraries, this parser does not unmarshal into Go values, but only constructs an abstract syntax tree for its input. This is meant to support manipulating the structure of a TOML document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []ArrayItem

An Array represents a (possibly empty) array value.

func (Array) String

func (a Array) String() string

type ArrayItem

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

An ArrayItem is an element in a TOML array value. The concrete type of an ArrayItem is one of Comments or Value.

type Comments

type Comments []string

Comments is an Item that represents a block of comments. Each entry represents a single comment line, including its comment marker but omitting the trailing line break.

func (Comments) String

func (c Comments) String() string

type Datum

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

A Datum is the representation of a data value. The concrete type of a Datum is one of Token, Array, or Inline.

type Heading

type Heading struct {
	Block   Comments // a block comment before the heading (empty if none)
	Trailer string   // a trailing line comment after the heading (empty if none)
	IsArray bool     // whether this is an array (true) or table (false)
	Name    Key      // the name of the array
}

Heading is an Item that represents a table or array section heading.

func (*Heading) String

func (h *Heading) String() string

type Inline

type Inline []*KeyValue

An Inline represents a (possibly empty) inline table value.

func (Inline) String

func (t Inline) String() string

type Item

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

An Item is an element in a TOML document. The concrete type of an Item is one of Comments, Heading, or KeyValue.

type Key

type Key []string

A Key represents a dotted compound name.

func ParseKey

func ParseKey(s string) (Key, error)

ParseKey parses s as a TOML key.

func (Key) Before added in v0.0.8

func (k Key) Before(k2 Key) bool

Before reports whether k is lexicographically prior to k2.

func (Key) Equals

func (k Key) Equals(k2 Key) bool

Equals reports whether k and k2 are equal.

func (Key) IsPrefixOf

func (k Key) IsPrefixOf(k2 Key) bool

IsPrefixOf reports whether k is a prefix of k2.

func (Key) String

func (k Key) String() string

type KeyValue

type KeyValue struct {
	Block Comments // a block comment before the key-value pair (empty if none)
	Name  Key
	Value Value
}

KeyValue is an Item that represents a key-value definition.

func (*KeyValue) String

func (kv *KeyValue) String() string

type Parser

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

A Parser is a parser for TOML syntax.

func New

func New(r io.Reader) *Parser

New constructs a new parser that consumes input from r.

func (*Parser) Items

func (p *Parser) Items() ([]Item, error)

Items reads the top-level items from the input.

type Token

type Token struct {
	Type scanner.Token // the lexical type of the token
	// contains filtered or unexported fields
}

A Token represents a lexical data element such as a string, integer, floating point literal, Boolean, or date/time literal.

func (Token) String

func (t Token) String() string

type Value

type Value struct {
	Trailer string // a trailing line-comment after the value (empty if none)
	X       Datum  // the concrete value
}

A Value represents a value in an array or a key-value assignment.

func MustValue

func MustValue(s string) Value

MustValue parses s as a TOML value. It panics if parsing fails. This is intended for use at program initialization time, or for static string constants that are expected to be always valid. For all other casesl, use ParseValue to check the error.

func ParseValue

func ParseValue(s string) (Value, error)

ParseValue parses s as a TOML value.

func (Value) String

func (v Value) String() string

func (Value) WithComment added in v0.0.4

func (v Value) WithComment(text string) Value

WithComment returns a copy of v with its trailer set to text.

Jump to

Keyboard shortcuts

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