parse

package
v0.0.0-...-5c847d5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package parse implements a low-level parser of ledger files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AmountNode

type AmountNode struct {
	NodeType
	Pos

	Raw       string // Raw representation of the amount, like "- CAD  100.20", with spacing and all. Will be used for printing unless empty, in which case the string will be reconstructed based on the other values herein.
	Quantity  string
	Negative  bool
	Commodity string
	ValueExpr string // Mutually exclusive with "Quantity". Expression, to be evaluated by some engine..
	// contains filtered or unexported fields
}

func (*AmountNode) String

func (n *AmountNode) String() string

type CommentNode

type CommentNode struct {
	NodeType
	Pos

	Comment string
	// contains filtered or unexported fields
}

func (*CommentNode) String

func (n *CommentNode) String() string

type CommodityNode

type CommodityNode struct {
	NodeType
	Pos

	Commodity string
	Note      string
	Alias     string
	Format    string
	NoMarket  bool
	Default   bool
	// contains filtered or unexported fields
}

type DirectiveNode

type DirectiveNode struct {
	NodeType
	Pos

	Raw       string
	Directive string
	Args      string
	// contains filtered or unexported fields
}

func (*DirectiveNode) String

func (n *DirectiveNode) String() string

type ListNode

type ListNode struct {
	NodeType
	Pos

	Nodes []Node // The top-level element nodes in lexical order.
	// contains filtered or unexported fields
}

ListNode holds a sequence of Entry Nodes

func (*ListNode) String

func (l *ListNode) String() string

type Node

type Node interface {
	Type() NodeType
	String() string
	// Copy does a deep copy of the Node and all its components.
	// To avoid type assertions, some XxxNodes also have specialized
	// CopyXxx methods that return *XxxNode.
	//Copy() Node
	Position() Pos // byte position of start of node in full original input string
	// contains filtered or unexported methods
}

A Node is an element in the parse tree. The interface is trivial. The interface contains an unexported method so that only types local to this package can satisfy it.

type NodeType

type NodeType int

NodeType identifies the type of a parse tree node.

const (
	NodeJournal NodeType = iota
	NodeList
	NodeXact
	NodePosting
	NodeComment
	NodeSpace
	NodeAmount
	NodeDirective
	NodeCommodity
)

func (NodeType) String

func (t NodeType) String() string

func (NodeType) Type

func (t NodeType) Type() NodeType

Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes.

type Pos

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

func (Pos) Position

func (p Pos) Position() Pos

type PostingNode

type PostingNode struct {
	NodeType
	Pos

	IsPending         bool
	IsCleared         bool
	AccountPreSpace   string
	Account           string
	AccountPostSpace  string // if non-empty, this must always be two spaces, one space and one tab, one tab, or more whitespace, as per specs.
	Amount            *AmountNode
	BalanceAssertion  *AmountNode
	BalanceAssignment *AmountNode
	Price             *AmountNode
	PriceIsForWhole   bool // false = per unit (@); true = price for the whole (@@), meaningful only if `Price` is defined.
	LotDate           time.Time
	LotPrice          *AmountNode
	NotePreSpace      string
	Note              string
	// contains filtered or unexported fields
}

func (*PostingNode) String

func (n *PostingNode) String() string

type SpaceNode

type SpaceNode struct {
	NodeType
	Pos

	Space string
	// contains filtered or unexported fields
}

func (*SpaceNode) String

func (n *SpaceNode) String() string

type Tree

type Tree struct {
	FileName string    // name of the template represented by the tree.
	Root     *ListNode // top-level root of the tree.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed Ledger file.

func New

func New(name, input string) *Tree

New creates a new Parse Tree for a Ledger file. Call .Parse() with parameter to retrieve an AST and parsed nodes.

func Parse

func Parse(filename string) (t *Tree, err error)

func (*Tree) ErrorContext

func (t *Tree) ErrorContext(n Node) (location, context string)

ErrorContext returns a textual representation of the location of the node in the input text. The receiver is only used when the node does not have a pointer to the tree inside, which can occur in old code.

func (*Tree) Parse

func (t *Tree) Parse() (err error)

parse is the top-level parser for a Ledger file. It runs to EOF.

type XactNode

type XactNode struct {
	NodeType
	Pos

	Date          time.Time
	EffectiveDate time.Time
	Description   string
	Code          string
	IsPending     bool
	IsCleared     bool
	NotePreSpace  string
	Note          string
	Postings      []*PostingNode
	// contains filtered or unexported fields
}

func (*XactNode) String

func (n *XactNode) String() string

Jump to

Keyboard shortcuts

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