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

Support including other ledger files #15

Merged
merged 1 commit into from
May 7, 2018
Merged

Support including other ledger files #15

merged 1 commit into from
May 7, 2018

Conversation

kalafut
Copy link
Contributor

@kalafut kalafut commented May 7, 2018

Fixes #14

This began as a very compact Reader mod with no changes to the parser. Then I realized that approach would swallow up any accurate filename/line number information for errors, which are actually pretty important in this application. Things grew a bit in order to track the active location as one goes into and returns from files, but the intrusion into parser.go and the main.go files is pretty small.

I tried a few approaches. The strategy I settled on was to inject special comments into the reader stream for when the file/line location jumps due to include/return. The parser just has to detect this and update its file count.

I realize you're trying to keep this ledger app really simple but hopefully you'll be interested in bringing this in. Include support and commodities (which I'll tackle next) are the bigees for me to cut over from ledger-cli.

Thanks,
Jim

@howeyc
Copy link
Owner

howeyc commented May 7, 2018

Looks good.

I'm curious, what's the error message look like when you have an error in an included file? Does it show the path of the file where the error occurred, or the root file.

Also, I just glanced at this, can you nest includes a few levels deep with this?

@kalafut
Copy link
Contributor Author

kalafut commented May 7, 2018

The error messages will always show the actual filename (whether root or included) and correct line number where the error was detected. Format is the same as what you had. My first cut which didn't do that (and everything was relative to the root... not very useful), was like 15 lines of code. Price to pay for this clarity 🙂.

Yes, includes can be nested, and cycles will be detected and error out. The entire tree is parsed at the start so such errors (cycles, include files missing) will be reported before the parser even gets the Reader.

I planned to add some tests against error conditions and such but didn't want to get too far down the track before giving you a look.

@howeyc howeyc merged commit 2c54b0f into howeyc:master May 7, 2018
@kalafut kalafut deleted the include-directive branch January 2, 2019 21:03
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

Successfully merging this pull request may close these issues.

2 participants