Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't handle txn and posting tags/links #3

Open
tbm opened this issue Apr 10, 2022 · 5 comments
Open

Doesn't handle txn and posting tags/links #3

tbm opened this issue Apr 10, 2022 · 5 comments

Comments

@tbm
Copy link

tbm commented Apr 10, 2022

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
Copy link
Author

tbm commented Apr 10, 2022

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 tbm changed the title Doesn't handle txn-wide tag Doesn't handle txn and posting tags/links Apr 10, 2022
@tbm
Copy link
Author

tbm commented Apr 10, 2022

Same with links btw.

@SEIAROTg
Copy link
Contributor

SEIAROTg commented Jun 4, 2022

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.

@tbm
Copy link
Author

tbm commented Jun 5, 2022

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.

@SEIAROTg
Copy link
Contributor

SEIAROTg commented Jun 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants