Models#
Models model beancount AST nodes. There are two types of models, token models and tree models.
Common interfaces#
The following interfaces are shared by all models, whether token or not.
__deepcopy__#
All models can be deep-copied, which makes an exact copy of everything in the model, into a separate token store.
file = p.parse('''\
2000-01-01 * ; inline comment
2000-01-02 *
''', models.File)
file.directives.append(file.directives[0])
ValueError: Cannot reuse node. Consider making a copy.
txn_copy = copy.deepcopy(file.directives[0])
file.directives.append(txn_copy)
_print_model(file)
2000-01-01 * ; inline comment
2000-01-02 *
2000-01-01 * ; inline comment
__eq__#
All models supports equality check. Two models are only equal if and only if:
They have the exact same type, and
They have the exact same text representations, and
They have the exact same structure.
tokens#
All models have a property tokens which returns a list of tokens inside that model. For a token, this returns itself.
close = p.parse('2000-01-01 close Assets:Foo ; inline comment', models.Close)
close.tokens
[<Date: '2000-01-01'>,
<Whitespace: ' '>,
<CloseLabel: 'close'>,
<Whitespace: ' '>,
<Account: 'Assets:Foo'>,
<Whitespace: ' '>,
<InlineComment: '; inline comment'>,
<Eol: ''>,
<Placeholder: ''>]
close.raw_inline_comment.tokens
[<InlineComment: '; inline comment'>]