beancount-parser icon indicating copy to clipboard operation
beancount-parser copied to clipboard

Doesn't handle txn and posting tags/links

Open tbm opened this issue 3 years ago • 5 comments

It seems bean-black doesn't handle #tags that are on the txn level:

lark.exceptions.UnexpectedCharacters: No terminal matches '#' in the current parser context, at line 14 col 3

  #opening-balance
  ^
Expected one of: 
	* FLAG
	* SECTION_HEADER
	* DATE
	* METADATA_KEY
	* ACCOUNT
	* COMMENT
...
  File "/home/tbm/.local/lib/python3.9/site-packages/lark/lexer.py", line 537, in lex
    raise UnexpectedToken(token, e.allowed, state=parser_state, token_history=[last_token], terminals_by_name=self.root_lexer.terminals_by_name)
lark.exceptions.UnexpectedToken: Unexpected token Token('TAGS', '#opening-balance') at line 14, column 3.

Test case:

2000-01-01 open Assets:Cash
2000-01-01 open Equity:Opening-Balance

2022-01-01 * "Opening balance: cash"
  #opening-balance
  Assets:Cash                                              10.00 EUR
  Equity:Opening-Balance

tbm avatar Apr 10 '22 07:04 tbm

Hmm, it seems it doesn't like posting-level tags either:

2000-01-01 open Assets:Cash
2000-01-01 open Equity:Opening-Balance

2022-01-01 * "Opening balance: cash"
  Assets:Cash                                              10.00 EUR
  Equity:Opening-Balance
    #opening-balance

tbm avatar Apr 10 '22 07:04 tbm

Same with links btw.

tbm avatar Apr 10 '22 07:04 tbm

AFAIK beancount never supports links / tags on a separate line, or at posting level.

The official parser happily accepts your example because it ignores any lines starting with [;*:#] or a flag character (https://github.com/beancount/beancount/blob/5464c2b3dba34774edb87a4d4dc1823dbf98c988/beancount/cparser/scanner.lxx#L342-L346). That being said, those hashtags are simply dropped rather than picked up as tags, as can be verified by bean-report print.

SEIAROTg avatar Jun 04 '22 15:06 SEIAROTg

Thanks for your comment.

There are two separate questions:

  1. Can tags and links (on transaction level) be on separate lines. The answer is yes.

Example:

2000-01-01 open Assets:Cash
2000-01-01 open Equity:Opening-Balance

2022-01-01 * "Opening balance: cash"
  #opening-balance
  ^foo
  Assets:Cash                                              10.00 EUR
  Equity:Opening-Balance

bean-report x.beancount print will show them:

...
2022-01-01 * "Opening balance: cash" #opening-balance ^foo
  Assets:Cash              10.00 EUR
...
  1. Posting-level tags/links: I completely forgot that they are currently not allowed in beancount. There is a longstanding ticket to support that but it's not allowed currently. You're right about this and I forgot.

tbm avatar Jun 05 '22 03:06 tbm

Sorry, you are right about the first point. I just found the rule that picks up those tags / links here, confusingly as part of posting_or_kv_list instead of transaction.

SEIAROTg avatar Jun 05 '22 13:06 SEIAROTg