Rudd-O / ledgerhelpers

A collection of helper programs and a helper library for Ledger (ledger-cli)
GNU General Public License v2.0
97 stars 10 forks source link

account directives are not lexed #5

Open hellerbarde opened 8 years ago

hellerbarde commented 8 years ago

Explicit definitions of accounts are not lexed or parsed. How hard would this be to implement? could you point me in the right direction? Maybe I can find some time to do it and file a pull request. (No promises though, exams are looming :)

A snippet from my test ledger file (fantasy values, obviously):

<snip/>
account Expenses
    note Expenses
    check commodity == "CHF"

account Expenses:Taxes:Social Security
    note Social Security
    check commodity == "CHF"

account Expenses:Bank Service Charge
    note Bank Service Charge
    check commodity == "CHF"

account Income:Bonus
    note Bonus
    check commodity == "CHF"

account Income:Interest Income:Savings Interest
    note Savings Interest
    check commodity == "CHF"

2016/05/14 * Opening Balance
    Assets:Current Assets:Mieterkautionssparkonto    100.00 CHF
    Equity:Opening Balances                    -100.00 CHF

2016/05/14 * opening balance
    Assets:Current Assets:Sparkonto        100.00 CHF
    Equity:Opening Balances                   -100.00 CHF

2016/05/14 * opening balance
    Assets:Current Assets:Main              100.00 CHF
    Equity:Opening Balances                    -100.00 CHF

2016/05/14 * initial
    Liabilities:Credit Card                      100.00 CHF
    Equity:Opening Balances                     -100.00 CHF
Rudd-O commented 8 years ago

On 05/17/2016 12:04 PM, P Stark wrote:

Explicit definitions of accounts are not lexed or parsed. How hard would this be to implement? could you point me in the right direction? Maybe I can find some time to do it and file a pull request. (No promises though, exams are looming :)

A snippet from my test ledger file (fantasy values, obviously):

| account Expenses note Expenses check commodity == "CHF" account Expenses:Taxes:Social Security note Social Security check commodity == "CHF" account Expenses:Bank Service Charge note Bank Service Charge check commodity == "CHF" account Income:Bonus note Bonus check commodity == "CHF" account Income:Interest Income:Savings Interest note Savings Interest check commodity == "CHF" 2016/05/14 Opening Balance Assets:Current Assets:Mieterkautionssparkonto 100.00 CHF Equity:Opening Balances -100.00 CHF 2016/05/14 * opening balance Assets:Current Assets:Sparkonto 100.00 CHF Equity:Opening Balances -100.00 CHF 2016/05/14 * opening balance Assets:Current Assets:Main 100.00 CHF Equity:Opening Balances -100.00 CHF 2016/05/14 \ initial Liabilities:Credit Card 100.00 CHF Equity:Opening Balances -100.00 CHF |

This should be trivial to add to the lexer, actually. If you look into the lexer Python file, it should be a case to be added, following the examples in the file. You can also check in this file example you sent, and then wire it into the tests, so that you can run "nosetests -v" against the repository with your changes, and it will tell you whether your lexing case worked or not.

A formal lexer grammar that generated lexing code would be even better.

Happy to take pull requests! You also have a Mieterkautionssparkonto! Cool!

Rudd-O
http://rudd-o.com/