awoken-bible / reference

NPM package for bible verse reference parsing, formating and meta data
MIT License
11 stars 3 forks source link

Parse example from docs does not work #17

Closed cco3 closed 1 year ago

cco3 commented 1 year ago

This example is given in the docs: GEN1.1-2; EXO3:4 - DEU5v6,10; Revelation 22

https://awoken-bible.github.io/reference/globals.html#parse

However, it fails to parse on version 3.0.0

jnterry commented 1 year ago

EXO3:4 - DEU5v6,10 is the actual issue here.

This bug affects all comma continuations after a range that involves two books. (Ranges with just a single book DO work, eg EXO3:4 - 5v6,10 so for consistancy I think we ought to support this)


Note for future attempts to solve:

This is a fairly tricky... The "b2_extra" content after book name current only supports "int" or "int:int": https://github.com/awoken-bible/reference/blob/master/src/parser.ts#L215-L217

Instead, it should support the full pChapterVerseSpecifier. Wip change here: https://github.com/awoken-bible/reference/commit/6a26088143e2a84190dc00c3b504927341f45480

But this breaks many test cases, since the lookahead/fallback doesn't work with the throw in the seqMap callback function. Instead the parser needs to fail BEFORE it consumes the input tokens (Would using P.chain and then returning P.fail() change this behavior?)

An alternative approach would be to parse an optional cv list as a seperate item in the seqMap list, eg:

P.seq(pInt, pVerseSeparator.then(pInt).fallback(null)).fallback(null),

// After parsing full range, parse an optional comma to continue parsing more chapter/verse
// specifiers within the context of the book/chapter that ends the range
(pCommaSeparator.then(pChapterVerseSpecifier.sepBy(pCommaSeparator))).fallback(null),
(b1, b1_extra, r, b2, b2_extra, cv_list) => {

This allows the EXO3:4 - DEU5v6,10 example to be consumed by parsimon without breaking any other test cases - but processing the cv_list inside the callback function data has a lot of edge cases to account for, as we could be in either chapter or verse context (Ie: is the preceeding pattern 1:2, so new numbers are verses, or 1, so new numbers are chapters?)