Commit Graph

16 Commits

Author SHA1 Message Date
Billy Keyes dc8fb6fdb5 Support adjustable read-ahead in parser
At the moment, we need only to read three lines, but now the value is
easy to adjust as needed. I've only seen the Git implementation read two
lines ahead so far, but it has the whole input in memory and may read
more in other places.
2019-03-25 21:30:08 -07:00
Billy Keyes ccf0c58db8 Change parser interface to be more iterator-like
Call Next() to advance the parser state until it returns a non-nil
error, then check if the error is io.EOF. This makes EOF handling easier
and also means that Line() and PeekLine() can be called multiple times
without changing state.

The next step is to update parse functions to return an internal marker
error if they are called on an invalid line. This should improve
correctness and remove the duplication of testing a condition and then
calling a parse function, which checks the same condition.
2019-03-24 22:03:53 -07:00
Billy Keyes 699084298b Accept comments when parsing fragment headers
Also parse the header directly instead of using a regexp. This allows
finer-grained errors.
2019-03-24 20:49:27 -07:00
Billy Keyes 6b7e4cd811 Move all header functions to file_header.go
Even though these are defined on *parser, it makes more sense to have
them in this file.
2019-03-21 22:51:19 -07:00
Billy Keyes cf2f946a66 Implement traditional file header parsing
While I think this works, this is mostly for completeness. I (and I
expect most other users, if any) intend to use this with git patches.
2019-03-21 22:47:52 -07:00
Billy Keyes 412e7a39b1 Add more tests for git file header parsing
Also fix a bug with EOF handling in the parsing function and make sure
the test does not ignore unexpected errors.
2019-03-20 22:20:21 -07:00
Billy Keyes 631c70505a Add basic tests for full git file header parsing 2019-03-19 23:05:15 -07:00
Billy Keyes b8b0c25c1e Move file header functions to a new file 2019-03-19 22:00:11 -07:00
Billy Keyes cbd3915448 Add final tests for git header parsing functions
This gets 100% test coverage for the functions involved in parsing
Git-style file headers. Whether that actually makes it correct remains
to be seen.
2019-03-19 21:50:50 -07:00
Billy Keyes a1f92fec30 Fix and test old/new file name verification 2019-03-18 23:05:15 -07:00
Billy Keyes 6daf604b25 Add tests for git header data parsing
Fix parseGitHeaderIndex to allow abbreviated OIDs and add a note about
this to the README. The behavior might change again later, based on some
experimentation with Git.
2019-03-17 21:38:14 -07:00
Billy Keyes 3f641b393f Add tests and fix bugs with name parsing
Also convert all table tests to use maps instead of structs with name
fields and standardize other field names.
2019-03-17 20:21:58 -07:00
Billy Keyes ea5b8bceea Finish parsing filenames from Git headers
Adds "default" name handling, error checks for missing names, and prefix
and double-slash stripping.
2019-03-17 15:34:03 -07:00
Billy Keyes bca8d0806e Detach parseFragmentHeader from parser struct
This operates on a single line and doesn't need any parser state.
2019-03-14 21:55:06 -07:00
Billy Keyes 4ddf1d962d Implement fragment header parsing
Use a regexp for simplicity, unlike the direct parsing in Git.
2019-03-13 23:04:01 -07:00
Billy Keyes f630455e5d Add a simple test for parser line operations 2019-03-11 23:05:15 -07:00