Parser
in package
Main parser for Beancount double-entry bookkeeping files.
This class parses Beancount-format files and returns an array of directive arrays. Each directive contains the parsed data including dates, accounts, amounts, and transactions.
Tags
Table of Contents
Properties
- $position : int
- $tokens : array<int, TokenInterface>
Methods
- __construct() : mixed
- Creates a new Parser instance.
- parse() : array<int, array<string, mixed>>
- Parses the Beancount content and returns an array of directives.
- advance() : TokenInterface
- expect() : TokenInterface
- expectAccount() : string
- isAtEnd() : bool
- isNextTokenEOL() : bool
- parseAccountName() : string|null
- parseBalance() : Balance
- parseClose() : Close
- parseCommodity() : Commodity
- parseCostOrPriceParts() : array{amount: string, currency: string}
- parseCustom() : Custom
- parseDatedDirective() : DirectiveInterface|null
- parseDirective() : DirectiveInterface|null
- Parses a single directive from the current position.
- parseDocument() : Document
- parseEvent() : Event
- parseMetadata() : array<string, mixed>
- parseNote() : Note
- parseOpen() : Open
- parsePad() : Pad
- parsePosting() : Posting|null
- parsePrice() : Price
- parsePriceAmount() : array<string, string|null>
- parseQuery() : Query
- parseTransaction() : Transaction
- peek() : TokenInterface
- peekColumn() : int
- peekLine() : int
- skipEOL() : void
Properties
$position
private
int
$position
= 0
$tokens
private
array<int, TokenInterface>
$tokens
= []
Methods
__construct()
Creates a new Parser instance.
public
__construct(string $input) : mixed
Parameters
- $input : string
-
The Beancount file content to parse
parse()
Parses the Beancount content and returns an array of directives.
public
parse() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>> —Array of directive arrays with 'directive', 'date', and other fields
advance()
private
advance() : TokenInterface
Return values
TokenInterfaceexpect()
private
expect(string $type) : TokenInterface
Parameters
- $type : string
Return values
TokenInterfaceexpectAccount()
private
expectAccount() : string
Return values
stringisAtEnd()
private
isAtEnd() : bool
Return values
boolisNextTokenEOL()
private
isNextTokenEOL() : bool
Return values
boolparseAccountName()
private
parseAccountName() : string|null
Return values
string|nullparseBalance()
private
parseBalance(string $date) : Balance
Parameters
- $date : string
Return values
BalanceparseClose()
private
parseClose(string $date) : Close
Parameters
- $date : string
Return values
CloseparseCommodity()
private
parseCommodity(string $date) : Commodity
Parameters
- $date : string
Return values
CommodityparseCostOrPriceParts()
private
parseCostOrPriceParts(string $value) : array{amount: string, currency: string}
Parameters
- $value : string
Return values
array{amount: string, currency: string}parseCustom()
private
parseCustom(string $date) : Custom
Parameters
- $date : string
Return values
CustomparseDatedDirective()
private
parseDatedDirective() : DirectiveInterface|null
Return values
DirectiveInterface|nullparseDirective()
Parses a single directive from the current position.
private
parseDirective() : DirectiveInterface|null
Tags
Return values
DirectiveInterface|null —The parsed directive or null if no directive found
parseDocument()
private
parseDocument(string $date) : Document
Parameters
- $date : string
Return values
DocumentparseEvent()
private
parseEvent(string $date) : Event
Parameters
- $date : string
Return values
EventparseMetadata()
private
parseMetadata() : array<string, mixed>
Return values
array<string, mixed>parseNote()
private
parseNote(string $date) : Note
Parameters
- $date : string
Return values
NoteparseOpen()
private
parseOpen(string $date) : Open
Parameters
- $date : string
Return values
OpenparsePad()
private
parsePad(string $date) : Pad
Parameters
- $date : string
Return values
PadparsePosting()
private
parsePosting() : Posting|null
Return values
Posting|nullparsePrice()
private
parsePrice(string $date) : Price
Parameters
- $date : string
Return values
PriceparsePriceAmount()
private
parsePriceAmount() : array<string, string|null>
Return values
array<string, string|null>parseQuery()
private
parseQuery(string $date) : Query
Parameters
- $date : string
Return values
QueryparseTransaction()
private
parseTransaction(string $date, string $flag) : Transaction
Parameters
- $date : string
- $flag : string
Return values
Transactionpeek()
private
peek() : TokenInterface
Return values
TokenInterfacepeekColumn()
private
peekColumn() : int
Return values
intpeekLine()
private
peekLine() : int
Return values
intskipEOL()
private
skipEOL() : void