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

Handle multi-line entries #12

Closed
jmagnuson opened this issue Feb 10, 2019 · 0 comments
Closed

Handle multi-line entries #12

jmagnuson opened this issue Feb 10, 2019 · 0 comments

Comments

@jmagnuson
Copy link
Owner

The current PgnLibrary::from_dbc_file parse logic assumes each line => entry which isn't correct, since multi-line entries such as the below can exist:

CM_ SG_ 2566838526 IndustryGroup "0 = Global; 
   1  = On-Highway; 
   2  = Agricultural and Forestry; 
   3  = Construction; 
   4  = Marine;
   5  = Industrial - Process
          Control - Stationary (Gen-Sets)
   6  = Reserve for SAE
   7  = Reserve for SAE";

Unfortunately, this means the underlying Entry parse logic will either need to have access to the entire reader, or will need to leak to the consumer so that knowledge of when to create the parseable String can be ascertained.

One solution is to do away with the BufReader::lines and modify Entry::from_str to take on the entire String which is already getting pre-buffered in full anyway. The relevant regex definitions already capture anything in between double-quotes, so they should be able to stay as-is. As mentioned, impl FromStr for Entry would need to get hacked in order to iterate through the consumed characters, which could get messy.

Another similar solution is to do away with regexes and just use nom to provide more control over tokenization and error handling, and probably faster to boot. Disclaimer: I really like nom.

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

1 participant