Beancount PHP Parser Documentation

Tokenizer
in package

Tokenizer (Lexer) for Beancount files.

This class converts Beancount text content into a sequence of tokens that can be processed by the Parser.

Tags
example
$tokenizer = new Tokenizer($content);
$tokens = $tokenizer->tokenize();
foreach ($tokens as $token) {
    echo $token->getType() . ': ' . $token->getValue() . PHP_EOL;
}

Table of Contents

Constants

DIRECTIVE_KEYWORDS  = ['open', 'close', 'balance', 'pad', 'note', 'document', 'commodity', 'price', 'event', 'query', 'custom', 'txn']
VALID_ACCOUNT_TYPES  = ['Assets', 'Liabilities', 'Equity', 'Income', 'Expenses']

Properties

$column  : int
$input  : string
$line  : int
$position  : int

Methods

__construct()  : mixed
Creates a new Tokenizer instance.
tokenize()  : array<int, TokenInterface>
isAtEnd()  : bool
reset()  : void
scanToken()  : TokenInterface|null
advance()  : string
isAccountType()  : bool
isAtCommentStart()  : bool
isValidCurrencyCode()  : bool
isWhitespaceOrEOL()  : bool
peek()  : string
scanComment()  : Token
scanCost()  : Token
scanDateOrNumber()  : Token
scanIdentifier()  : TokenInterface
scanLink()  : Token
scanNumber()  : Token
scanPrice()  : Token
scanString()  : Token
scanTag()  : Token

Constants

DIRECTIVE_KEYWORDS

private mixed DIRECTIVE_KEYWORDS = ['open', 'close', 'balance', 'pad', 'note', 'document', 'commodity', 'price', 'event', 'query', 'custom', 'txn']

VALID_ACCOUNT_TYPES

private mixed VALID_ACCOUNT_TYPES = ['Assets', 'Liabilities', 'Equity', 'Income', 'Expenses']

Properties

Methods

__construct()

Creates a new Tokenizer instance.

public __construct(string $input) : mixed
Parameters
$input : string

The Beancount content to tokenize

isAtEnd()

protected isAtEnd() : bool
Return values
bool

advance()

private advance() : string
Return values
string

isAccountType()

private isAccountType(string $value) : bool
Parameters
$value : string
Return values
bool

isAtCommentStart()

private isAtCommentStart() : bool
Return values
bool

isValidCurrencyCode()

private isValidCurrencyCode(string $value) : bool
Parameters
$value : string
Return values
bool

isWhitespaceOrEOL()

private isWhitespaceOrEOL(string $char) : bool
Parameters
$char : string
Return values
bool

peek()

private peek([int $offset = 0 ]) : string
Parameters
$offset : int = 0
Return values
string

        
On this page

Search results