Skip to content

Reset default chapter and verse at semicolons when parsing references#21

Open
kobsy wants to merge 1 commit intoboblail:masterfrom
kobsy:parse-multiple-chapters
Open

Reset default chapter and verse at semicolons when parsing references#21
kobsy wants to merge 1 commit intoboblail:masterfrom
kobsy:parse-multiple-chapters

Conversation

@kobsy
Copy link
Collaborator

@kobsy kobsy commented Nov 20, 2019

Summary

This could likely be considered a breaking change in how parsing works. Before, the only way to "reset" the default chapter was to encounter a reference with a colon in it. For example, "Genesis 2; 3:15" would parse correctly, but "Genesis 2; 3" would not, since the latter reference had no colon to mark it clearly as indicating a chapter. However, in common usage, the semicolon is what signals to the human reader that what is meant is not verse 3 of chapter 2, but chapters 2 and 3; this updates Pericope to behave the same way.

This is a departure from previous behavior, as is illustrated by the test that is modified as part of this PR. Because of the use of commas and semicolons, the pair of references no longer parsed in the same way. (I referenced the comment and the expected ranges themselves to preference the way that seemed intended.) Even so, common usage being what it is, I would predict the impact of the change to be pretty minimal -- the handful of edge cases corrected by the change should outweigh the number of edge cases broken by the change. That said, I understand if this change needs further scrutiny and care because it changes behavior in this way.

…rences (20m)

This could likely be considered a breaking change in how parsing works. Before, the only way to "reset" the default chapter was to encounter a reference with a colon in it. For example, "Genesis 2; 3:15" would parse correctly, but "Genesis 2; 3" would not, since the latter reference had no colon to mark it clearly as indicating a chapter. However, in common usage, the semicolon is what signals to the human reader that what is meant is not verse 3 of chapter 2, but chapters 2 and 3; this updates Pericope to behave the same way.
def parse_reference(book, reference)
parse_ranges(book, normalize_reference(reference).split(/[,;]/))
# Use positive lookahead to keep delimiter with the fragment that follows
parse_ranges(book, normalize_reference(reference).split(/(?=[,;])/))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that the positive lookahead does impact performance — but not by a lot

Before
PERFORMANCE
  0.021496   0.000342   0.021838 (  0.021919)
  0.191024   0.001824   0.192848 (  0.193286)
  1.908849   0.009966   1.918815 (  1.924357)
After
PERFORMANCE
  0.022117   0.000469   0.022586 (  0.022739)
  0.252090   0.004195   0.256285 (  0.258896)
  2.136289   0.012225   2.148514 (  2.161139)

Copy link
Owner

@boblail boblail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in the tests seem reasonable to me 👍

What do you think of making a corresponding PR on pericope.js?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants