Beancount PHP Parser Documentation

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
example
$parser = new Parser($beancountContent);
$entries = $parser->parse();
foreach ($entries as $entry) {
    echo $entry['directive'] . PHP_EOL;
}

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

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

expectAccount()

private expectAccount() : string
Return values
string

isAtEnd()

private isAtEnd() : bool
Return values
bool

isNextTokenEOL()

private isNextTokenEOL() : bool
Return values
bool

parseAccountName()

private parseAccountName() : string|null
Return values
string|null

parseBalance()

private parseBalance(string $date) : Balance
Parameters
$date : string
Return values
Balance

parseClose()

private parseClose(string $date) : Close
Parameters
$date : string
Return values
Close

parseCostOrPriceParts()

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
Custom

parseDocument()

private parseDocument(string $date) : Document
Parameters
$date : string
Return values
Document

parseEvent()

private parseEvent(string $date) : Event
Parameters
$date : string
Return values
Event

parseMetadata()

private parseMetadata() : array<string, mixed>
Return values
array<string, mixed>

parseNote()

private parseNote(string $date) : Note
Parameters
$date : string
Return values
Note

parseOpen()

private parseOpen(string $date) : Open
Parameters
$date : string
Return values
Open

parsePad()

private parsePad(string $date) : Pad
Parameters
$date : string
Return values
Pad

parsePrice()

private parsePrice(string $date) : Price
Parameters
$date : string
Return values
Price

parsePriceAmount()

private parsePriceAmount() : array<string, string|null>
Return values
array<string, string|null>

parseQuery()

private parseQuery(string $date) : Query
Parameters
$date : string
Return values
Query

parseTransaction()

private parseTransaction(string $date, string $flag) : Transaction
Parameters
$date : string
$flag : string
Return values
Transaction

peekColumn()

private peekColumn() : int
Return values
int

peekLine()

private peekLine() : int
Return values
int

skipEOL()

private skipEOL() : void

        
On this page

Search results