parser

package
v0.0.0-...-661510b Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortDirectives

func SortDirectives(ast *AST) error

SortDirectives sort all directives by their parsed date.

This is called automatically during Parse*(), but can be called on a manually constructed AST.

Types

type AST

type AST struct {
	Directives Directives `parser:"(@@"`
	Options    []*Option  `parser:"| @@ | ~ignore)*"`
}

func Parse

func Parse(r io.Reader) (*AST, error)

Parse AST from an io.Reader.

func ParseBytes

func ParseBytes(data []byte) (*AST, error)

ParseBytes parses AST from bytes.

func ParseString

func ParseString(str string) (*AST, error)

ParseString parses AST from a string.

type Account

type Account string

func (*Account) Capture

func (a *Account) Capture(values []string) error

type Amount

type Amount struct {
	Value    string `parser:"@Number"`
	Currency string `parser:"@Ident"`
}

type Balance

type Balance struct {
	Date    *Date   `parser:"@Date 'balance'"`
	Account Account `parser:"@Account"`
	Amount  *Amount `parser:"@@"`
	// contains filtered or unexported fields
}

func (*Balance) AddMetadata

func (w *Balance) AddMetadata(m ...*Metadata)

func (*Balance) Directive

func (b *Balance) Directive() string

type Close

type Close struct {
	Date    *Date   `parser:"@Date 'close'"`
	Account Account `parser:"@Account"`
	// contains filtered or unexported fields
}

func (*Close) AddMetadata

func (w *Close) AddMetadata(m ...*Metadata)

func (*Close) Directive

func (c *Close) Directive() string

type Commodity

type Commodity struct {
	Date     *Date  `parser:"@Date 'commodity'"`
	Currency string `parser:"@Ident"`
	// contains filtered or unexported fields
}

func (*Commodity) AddMetadata

func (w *Commodity) AddMetadata(m ...*Metadata)

func (*Commodity) Directive

func (c *Commodity) Directive() string

type Date

type Date struct {
	time.Time
}

func (*Date) Capture

func (d *Date) Capture(values []string) error

type Directive

type Directive interface {
	WithMetadata

	Directive() string
	// contains filtered or unexported methods
}

type Directives

type Directives []Directive

func (Directives) Len

func (d Directives) Len() int

func (Directives) Less

func (d Directives) Less(i, j int) bool

func (Directives) Swap

func (d Directives) Swap(i, j int)

type Document

type Document struct {
	Date           *Date   `parser:"@Date 'document'"`
	Account        Account `parser:"@Account"`
	PathToDocument string  `parser:"@String"`
	// contains filtered or unexported fields
}

func (*Document) AddMetadata

func (w *Document) AddMetadata(m ...*Metadata)

func (*Document) Directive

func (d *Document) Directive() string

type Event

type Event struct {
	Date  *Date  `parser:"@Date 'event'"`
	Name  string `parser:"@String"`
	Value string `parser:"@String"`
	// contains filtered or unexported fields
}

func (*Event) AddMetadata

func (w *Event) AddMetadata(m ...*Metadata)

func (*Event) Directive

func (e *Event) Directive() string

type Metadata

type Metadata struct {
	Key   string `parser:"@Ident ':'"`
	Value string `parser:"@(~'\\n'+)"`
}

type Note

type Note struct {
	Date        *Date   `parser:"@Date 'note'"`
	Account     Account `parser:"@Account"`
	Description string  `parser:"@String"`
	// contains filtered or unexported fields
}

func (*Note) AddMetadata

func (w *Note) AddMetadata(m ...*Metadata)

func (*Note) Directive

func (n *Note) Directive() string

type Open

type Open struct {
	Date                 *Date    `parser:"@Date 'open'"`
	Account              Account  `parser:"@Account"`
	ConstraintCurrencies []string `parser:"(@Ident (',' @Ident)*)?"`
	BookingMethod        string   `parser:"@('STRICT' | 'NONE')?"`
	// contains filtered or unexported fields
}

func (*Open) AddMetadata

func (w *Open) AddMetadata(m ...*Metadata)

func (*Open) Directive

func (o *Open) Directive() string

type Option

type Option struct {
	Name  string `parser:"'option' @String"`
	Value string `parser:"@String"`
}

type Pad

type Pad struct {
	Date       *Date   `parser:"@Date 'pad'"`
	Account    Account `parser:"@Account"`
	AccountPad Account `parser:"@Account"`
	// contains filtered or unexported fields
}

func (*Pad) AddMetadata

func (w *Pad) AddMetadata(m ...*Metadata)

func (*Pad) Directive

func (p *Pad) Directive() string

type Posting

type Posting struct {
	Flag       string  `parser:"@('*' | '!')?"`
	Account    Account `parser:"@Account"`
	Amount     *Amount `parser:"(@@"`
	PriceTotal bool    `parser:"(('@' | @'@@')"`
	Price      *Amount `parser:"@@)?"`
	Cost       *Amount `parser:"('{' @@ '}')?)?"`
	// contains filtered or unexported fields
}

func (*Posting) AddMetadata

func (w *Posting) AddMetadata(m ...*Metadata)

type Price

type Price struct {
	Date      *Date   `parser:"@Date 'price'"`
	Commodity string  `parser:"@Ident"`
	Amount    *Amount `parser:"@@"`
	// contains filtered or unexported fields
}

func (*Price) AddMetadata

func (w *Price) AddMetadata(m ...*Metadata)

func (*Price) Directive

func (p *Price) Directive() string

type Transaction

type Transaction struct {
	Date      *Date  `parser:"@Date ('txn' | "`
	Flag      string `parser:"@('*' | '!' | 'P') )"`
	Payee     string `parser:"@(String (?= String))?"`
	Narration string `parser:"@String?"`

	Postings []*Posting `parser:"@@*"`
	// contains filtered or unexported fields
}

func (*Transaction) AddMetadata

func (w *Transaction) AddMetadata(m ...*Metadata)

func (*Transaction) Directive

func (t *Transaction) Directive() string

type WithMetadata

type WithMetadata interface {
	AddMetadata(...*Metadata)
}

Jump to

Keyboard shortcuts

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