PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 2ms

/js/eu/he_bcv_parser.js

https://github.com/davidortinau/Bible-Passage-Reference-Parser
JavaScript | 10069 lines | 9783 code | 191 blank | 95 comment | 1218 complexity | 12d49753477751673265817cc436ae2a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. // Generated by CoffeeScript 1.3.3
  2. (function() {
  3. var bcv_parser, bcv_passage, bcv_utils, root,
  4. __hasProp = {}.hasOwnProperty;
  5. root = this;
  6. bcv_parser = (function() {
  7. bcv_parser.prototype.s = "";
  8. bcv_parser.prototype.entities = [];
  9. bcv_parser.prototype.passage = null;
  10. bcv_parser.prototype.regexps = {};
  11. bcv_parser.prototype.default_options = {};
  12. bcv_parser.prototype.options = {
  13. consecutive_combination_strategy: "combine",
  14. osis_compaction_strategy: "b",
  15. book_sequence_strategy: "ignore",
  16. invalid_sequence_strategy: "ignore",
  17. sequence_combination_strategy: "combine",
  18. invalid_passage_strategy: "ignore",
  19. zero_chapter_strategy: "error",
  20. zero_verse_strategy: "error",
  21. non_latin_digits_strategy: "ignore",
  22. book_alone_strategy: "ignore",
  23. captive_end_digits_strategy: "delete",
  24. end_range_digits_strategy: "verse",
  25. include_apocrypha: false,
  26. versification_system: "default"
  27. };
  28. function bcv_parser() {
  29. var key, val, _ref;
  30. this.options = {};
  31. _ref = bcv_parser.prototype.options;
  32. for (key in _ref) {
  33. if (!__hasProp.call(_ref, key)) continue;
  34. val = _ref[key];
  35. this.options[key] = val;
  36. }
  37. this.versification_system(this.options.versification_system);
  38. }
  39. bcv_parser.prototype.parse = function(s) {
  40. var accum, entities, entity, _i, _len, _ref;
  41. this.reset();
  42. this.s = s;
  43. s = this.replace_control_characters(s);
  44. _ref = this.match_books(s), s = _ref[0], this.passage.books = _ref[1];
  45. entities = this.match_passages(s);
  46. this.entities = [];
  47. for (_i = 0, _len = entities.length; _i < _len; _i++) {
  48. entity = entities[_i];
  49. accum = this.passage.handle_array([entity])[0];
  50. this.entities = this.entities.concat(accum);
  51. }
  52. return this;
  53. };
  54. bcv_parser.prototype.reset = function() {
  55. this.s = "";
  56. this.entities = [];
  57. if (this.passage) {
  58. this.passage.books = [];
  59. return this.passage.indices = {};
  60. } else {
  61. this.passage = new bcv_passage;
  62. this.passage.options = this.options;
  63. return this.passage.translations = this.translations;
  64. }
  65. };
  66. bcv_parser.prototype.set_options = function(options) {
  67. var key, val, _results;
  68. _results = [];
  69. for (key in options) {
  70. if (!__hasProp.call(options, key)) continue;
  71. val = options[key];
  72. if (key === "include_apocrypha" || key === "versification_system") {
  73. _results.push(this[key](val));
  74. } else {
  75. _results.push(this.options[key] = val);
  76. }
  77. }
  78. return _results;
  79. };
  80. bcv_parser.prototype.include_apocrypha = function(arg) {
  81. if (!((arg != null) && (arg === true || arg === false))) {
  82. return this;
  83. }
  84. this.options.include_apocrypha = arg;
  85. this.regexps.books = this.regexps.get_books(arg);
  86. if (arg === true) {
  87. this.translations["default"].chapters.Ps[150] = this.translations["default"].chapters.Ps151[0];
  88. } else if (arg === false) {
  89. if (this.translations["default"].chapters.Ps.length === 151) {
  90. this.translations["default"].chapters.Ps.pop();
  91. }
  92. }
  93. return this;
  94. };
  95. bcv_parser.prototype.versification_system = function(system) {
  96. var book, chapter_list, _base, _ref, _ref1;
  97. if (!((system != null) && (this.translations.alternates[system] != null))) {
  98. return this;
  99. }
  100. this.options.versification_system = system;
  101. if ((_ref = (_base = this.translations.alternates)["default"]) == null) {
  102. _base["default"] = {
  103. order: null,
  104. chapters: {}
  105. };
  106. }
  107. if (this.translations.alternates[system].order != null) {
  108. if (this.translations.alternates["default"].order == null) {
  109. this.translations.alternates["default"].order = bcv_utils.shallow_clone(this.translations["default"].order);
  110. }
  111. this.translations["default"].order = bcv_utils.shallow_clone(this.translations.alternates[system].order);
  112. }
  113. if (this.translations.alternates[system].chapters != null) {
  114. _ref1 = this.translations.alternates[system].chapters;
  115. for (book in _ref1) {
  116. if (!__hasProp.call(_ref1, book)) continue;
  117. chapter_list = _ref1[book];
  118. if (this.translations.alternates["default"].chapters[book] == null) {
  119. this.translations.alternates["default"].chapters[book] = bcv_utils.shallow_clone_array(this.translations["default"].chapters[book]);
  120. }
  121. this.translations["default"].chapters[book] = bcv_utils.shallow_clone_array(chapter_list);
  122. }
  123. }
  124. this.include_apocrypha(this.options.include_apocrypha);
  125. return this;
  126. };
  127. bcv_parser.prototype.replace_control_characters = function(s) {
  128. s = s.replace(this.regexps.control, " ");
  129. if (this.options.non_latin_digits_strategy === "replace") {
  130. s = s.replace(/[٠۰߀0]/g, "0");
  131. s = s.replace(/[١۱߁]/g, "1");
  132. s = s.replace(/[٢۲߂]/g, "2");
  133. s = s.replace(/[٣۳߃]/g, "3");
  134. s = s.replace(/[٤۴߄]/g, "4");
  135. s = s.replace(/[٥۵߅]/g, "5");
  136. s = s.replace(/[٦۶߆]/g, "6");
  137. s = s.replace(/[٧۷߇]/g, "7");
  138. s = s.replace(/[٨۸߈]/g, "8");
  139. s = s.replace(/[٩۹߉]/g, "9");
  140. }
  141. return s;
  142. };
  143. bcv_parser.prototype.match_books = function(s) {
  144. var book, books, _i, _len, _ref;
  145. books = [];
  146. _ref = this.regexps.books;
  147. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  148. book = _ref[_i];
  149. s = s.replace(book.regexp, function(full, prev, bk) {
  150. var extra;
  151. books.push({
  152. value: bk,
  153. parsed: book.osis
  154. });
  155. extra = book.extra != null ? "/" + book.extra : "";
  156. return "" + prev + "\x1f" + (books.length - 1) + extra + "\x1f";
  157. });
  158. }
  159. s = s.replace(this.regexps.translations, function(match) {
  160. books.push({
  161. value: match,
  162. parsed: match.toLowerCase()
  163. });
  164. return "\x1e" + (books.length - 1) + "\x1e";
  165. });
  166. return [s, this.get_book_indices(books, s)];
  167. };
  168. bcv_parser.prototype.get_book_indices = function(books, s) {
  169. var add_index, match, re;
  170. add_index = 0;
  171. re = /([\x1f\x1e])(\d+)(?:\/[a-z])?\1/g;
  172. while (match = re.exec(s)) {
  173. books[match[2]].start_index = match.index + add_index;
  174. add_index += books[match[2]].value.length - match[0].length;
  175. }
  176. return books;
  177. };
  178. bcv_parser.prototype.match_passages = function(s) {
  179. var book_id, full, match, next_char, part, passage, passages, re, start_index_adjust;
  180. passages = [];
  181. while (match = this.regexps.escaped_passage.exec(s)) {
  182. full = match[0], part = match[1], book_id = match[2];
  183. match.index += full.length - part.length;
  184. if (/\s[2-9]\d\d\s*$|\s\d{4,}\s*$/.test(part)) {
  185. re = /\s+\d+\s*$/;
  186. part = part.replace(re, "");
  187. }
  188. if (!/[\d\x1f\x1e)]$/.test(part)) {
  189. part = this.replace_match_end(part);
  190. }
  191. if (this.options.captive_end_digits_strategy === "delete") {
  192. next_char = match.index + part.length;
  193. if (s.length > next_char && /^\w/.test(s.substr(next_char, 1))) {
  194. part = part.replace(/[\s*]+\d+$/, "");
  195. }
  196. part = part.replace(/(\x1e[)\]]?)[\s*]*\d+$/, "$1");
  197. }
  198. part = part.replace(/[A-Z]+/g, function(capitals) {
  199. return capitals.toLowerCase();
  200. });
  201. start_index_adjust = part.substr(0, 1 === "\x1f") ? 0 : part.split("\x1f")[0].length;
  202. passage = {
  203. value: grammar.parse(part),
  204. type: "base",
  205. start_index: this.passage.books[book_id].start_index - start_index_adjust,
  206. match: part
  207. };
  208. if (this.options.book_alone_strategy === "full" && passage.value.length === 1 && passage.value[0].type === "b" && start_index_adjust === 0 && this.passage.books[book_id].parsed.length === 1 && /^[234]/.test(this.passage.books[book_id].parsed[0])) {
  209. this.create_book_range(s, passage, book_id);
  210. }
  211. passages.push(passage);
  212. }
  213. return passages;
  214. };
  215. bcv_parser.prototype.replace_match_end = function(part) {
  216. var match, remove;
  217. remove = part.length;
  218. while (match = this.regexps.match_end_split.exec(part)) {
  219. remove = match.index + match[0].length;
  220. }
  221. if (remove < part.length) {
  222. part = part.substr(0, remove);
  223. }
  224. return part;
  225. };
  226. bcv_parser.prototype.create_book_range = function(s, passage, book_id) {
  227. var cases, i, limit, prev, range_regexp, _i;
  228. cases = [bcv_parser.prototype.regexps.first, bcv_parser.prototype.regexps.second, bcv_parser.prototype.regexps.third];
  229. limit = parseInt(this.passage.books[book_id].parsed[0].substr(0, 1), 10);
  230. for (i = _i = 1; 1 <= limit ? _i < limit : _i > limit; i = 1 <= limit ? ++_i : --_i) {
  231. range_regexp = i === limit - 1 ? bcv_parser.prototype.regexps.range_and : bcv_parser.prototype.regexps.range_only;
  232. prev = s.match(RegExp("(?:^|\\W)(" + cases[i - 1] + "\\s*" + range_regexp + "\\s*)\\x1f" + book_id + "\\x1f", "i"));
  233. if (prev != null) {
  234. return this.add_book_range_object(passage, prev, i);
  235. }
  236. }
  237. return false;
  238. };
  239. bcv_parser.prototype.add_book_range_object = function(passage, prev, start_book_number) {
  240. var length;
  241. length = prev[1].length;
  242. passage.value[0] = {
  243. type: "b_range_pre",
  244. value: [
  245. {
  246. type: "b_pre",
  247. value: start_book_number.toString(),
  248. indices: [prev.index, prev.index + length]
  249. }, passage.value[0]
  250. ],
  251. indices: [0, passage.value[0].indices[1] + length]
  252. };
  253. passage.value[0].value[1].indices[0] += length;
  254. passage.value[0].value[1].indices[1] += length;
  255. passage.start_index -= length;
  256. return passage.match = prev[1] + passage.match;
  257. };
  258. bcv_parser.prototype.osis = function() {
  259. var osis, out, _i, _len, _ref;
  260. out = [];
  261. _ref = this.parsed_entities();
  262. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  263. osis = _ref[_i];
  264. if (osis.osis.length > 0) {
  265. out.push(osis.osis);
  266. }
  267. }
  268. return out.join(",");
  269. };
  270. bcv_parser.prototype.osis_and_translations = function() {
  271. var osis, out, _i, _len, _ref;
  272. out = [];
  273. _ref = this.parsed_entities();
  274. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  275. osis = _ref[_i];
  276. if (osis.osis.length > 0) {
  277. out.push([osis.osis, osis.translations.join(",")]);
  278. }
  279. }
  280. return out;
  281. };
  282. bcv_parser.prototype.osis_and_indices = function() {
  283. var osis, out, _i, _len, _ref;
  284. out = [];
  285. _ref = this.parsed_entities();
  286. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  287. osis = _ref[_i];
  288. if (osis.osis.length > 0) {
  289. out.push({
  290. osis: osis.osis,
  291. translations: osis.translations,
  292. indices: osis.indices
  293. });
  294. }
  295. }
  296. return out;
  297. };
  298. bcv_parser.prototype.parsed_entities = function() {
  299. var entity, entity_id, i, last_i, length, osis, osises, out, passage, strings, translation, translation_alias, translation_osis, translations, _i, _j, _k, _l, _len, _len1, _ref, _ref1, _ref2, _ref3, _ref4;
  300. out = [];
  301. for (entity_id = _i = 0, _ref = this.entities.length; 0 <= _ref ? _i < _ref : _i > _ref; entity_id = 0 <= _ref ? ++_i : --_i) {
  302. entity = this.entities[entity_id];
  303. if (entity.type && entity.type === "translation_sequence" && out.length > 0 && entity_id === out[out.length - 1].entity_id + 1) {
  304. out[out.length - 1].indices[1] = entity.absolute_indices[1];
  305. }
  306. if (entity.passages == null) {
  307. continue;
  308. }
  309. if ((entity.type === "b" || entity.type === "b_range") && this.options.book_alone_strategy === "ignore") {
  310. continue;
  311. }
  312. translations = [];
  313. translation_alias = null;
  314. if (entity.passages[0].translations != null) {
  315. _ref1 = entity.passages[0].translations;
  316. for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
  317. translation = _ref1[_j];
  318. translation_osis = ((_ref2 = translation.osis) != null ? _ref2.length : void 0) > 0 ? translation.osis : "";
  319. if (translation_alias == null) {
  320. translation_alias = translation.alias;
  321. }
  322. translations.push(translation_osis);
  323. }
  324. } else {
  325. translations = [""];
  326. translation_alias = "default";
  327. }
  328. osises = [];
  329. length = entity.passages.length;
  330. for (i = _k = 0; 0 <= length ? _k < length : _k > length; i = 0 <= length ? ++_k : --_k) {
  331. passage = entity.passages[i];
  332. if ((_ref3 = passage.type) == null) {
  333. passage.type = entity.type;
  334. }
  335. if (passage.valid.valid === false) {
  336. if (this.options.invalid_sequence_strategy === "ignore" && entity.type === "sequence") {
  337. this.snap_sequence("ignore", entity, osises, i, length);
  338. }
  339. if (this.options.invalid_passage_strategy === "ignore") {
  340. continue;
  341. }
  342. }
  343. if ((passage.type === "b" || passage.type === "b_range") && this.options.book_sequence_strategy === "ignore" && entity.type === "sequence") {
  344. this.snap_sequence("book", entity, osises, i, length);
  345. continue;
  346. }
  347. if ((_ref4 = passage.absolute_indices) == null) {
  348. passage.absolute_indices = entity.absolute_indices;
  349. }
  350. osises.push({
  351. osis: passage.valid.valid ? this.to_osis(passage.start, passage.end, translation_alias) : "",
  352. type: passage.type,
  353. indices: passage.absolute_indices,
  354. translations: translations,
  355. start: passage.start,
  356. end: passage.end,
  357. enclosed_indices: passage.enclosed_absolute_indices,
  358. entity_id: entity_id,
  359. entities: [passage]
  360. });
  361. }
  362. if (osises.length === 0) {
  363. continue;
  364. }
  365. if (osises.length > 1 && this.options.consecutive_combination_strategy === "combine") {
  366. osises = this.combine_consecutive_passages(osises, translation_alias);
  367. }
  368. if (this.options.sequence_combination_strategy === "separate") {
  369. out = out.concat(osises);
  370. } else {
  371. strings = [];
  372. last_i = osises.length - 1;
  373. if ((osises[last_i].enclosed_indices != null) && osises[last_i].enclosed_indices[1] >= 0) {
  374. entity.absolute_indices[1] = osises[last_i].enclosed_indices[1];
  375. }
  376. for (_l = 0, _len1 = osises.length; _l < _len1; _l++) {
  377. osis = osises[_l];
  378. if (osis.osis.length > 0) {
  379. strings.push(osis.osis);
  380. }
  381. }
  382. out.push({
  383. osis: strings.join(","),
  384. indices: entity.absolute_indices,
  385. translations: translations,
  386. entity_id: entity_id,
  387. entities: osises
  388. });
  389. }
  390. }
  391. return out;
  392. };
  393. bcv_parser.prototype.to_osis = function(start, end, translation) {
  394. var osis, _ref, _ref1, _ref2, _ref3;
  395. if (!(end.c != null) && !(end.v != null) && start.b === end.b && !(start.c != null) && !(start.v != null) && this.options.book_alone_strategy === "first_chapter") {
  396. end.c = 1;
  397. }
  398. osis = {
  399. start: "",
  400. end: ""
  401. };
  402. if ((_ref = start.c) == null) {
  403. start.c = 1;
  404. }
  405. if ((_ref1 = start.v) == null) {
  406. start.v = 1;
  407. }
  408. if ((_ref2 = end.c) == null) {
  409. end.c = this.passage.translations[translation].chapters[end.b].length;
  410. }
  411. if ((_ref3 = end.v) == null) {
  412. end.v = this.passage.translations[translation].chapters[end.b][end.c - 1];
  413. }
  414. if (this.options.osis_compaction_strategy === "b" && start.c === 1 && start.v === 1 && end.c === this.passage.translations[translation].chapters[end.b].length && end.v === this.passage.translations[translation].chapters[end.b][end.c - 1]) {
  415. osis.start = start.b;
  416. osis.end = end.b;
  417. } else if (this.options.osis_compaction_strategy.length <= 2 && start.v === 1 && end.v === this.passage.translations[translation].chapters[end.b][end.c - 1]) {
  418. osis.start = start.b + "." + start.c.toString();
  419. osis.end = end.b + "." + end.c.toString();
  420. } else {
  421. osis.start = start.b + "." + start.c.toString() + "." + start.v.toString();
  422. osis.end = end.b + "." + end.c.toString() + "." + end.v.toString();
  423. }
  424. if (osis.start === osis.end) {
  425. return osis.start;
  426. }
  427. return osis.start + "-" + osis.end;
  428. };
  429. bcv_parser.prototype.combine_consecutive_passages = function(osises, translation) {
  430. var enclosed_sequence_start, i, last_i, osis, out, prev, prev_i, _i;
  431. out = [];
  432. prev = {};
  433. last_i = osises.length - 1;
  434. enclosed_sequence_start = -1;
  435. for (i = _i = 0; 0 <= last_i ? _i <= last_i : _i >= last_i; i = 0 <= last_i ? ++_i : --_i) {
  436. osis = osises[i];
  437. if (osis.osis.length > 0) {
  438. prev_i = out.length - 1;
  439. osis.is_enclosed_first = false;
  440. osis.is_enclosed_last = false;
  441. if (osis.enclosed_indices[0] !== enclosed_sequence_start) {
  442. enclosed_sequence_start = osis.enclosed_indices[0];
  443. if (enclosed_sequence_start >= 0) {
  444. osis.is_enclosed_first = true;
  445. }
  446. }
  447. if (enclosed_sequence_start >= 0 && (i === last_i || osises[i + 1].enclosed_indices[0] !== osis.enclosed_indices[0])) {
  448. osis.is_enclosed_last = true;
  449. }
  450. if (this.is_verse_consecutive(prev, osis.start, translation)) {
  451. out[prev_i].end = osis.end;
  452. out[prev_i].is_enclosed_last = osis.is_enclosed_last;
  453. out[prev_i].indices[1] = osis.indices[1];
  454. out[prev_i].enclosed_indices[1] = osis.enclosed_indices[1];
  455. out[prev_i].osis = this.to_osis(out[prev_i].start, osis.end, translation);
  456. } else {
  457. out.push(osis);
  458. }
  459. prev = {
  460. b: osis.end.b,
  461. c: osis.end.c,
  462. v: osis.end.v
  463. };
  464. } else {
  465. out.push(osis);
  466. prev = {};
  467. }
  468. }
  469. return this.snap_enclosed_indices(out);
  470. };
  471. bcv_parser.prototype.snap_enclosed_indices = function(osises) {
  472. var osis, _i, _len;
  473. for (_i = 0, _len = osises.length; _i < _len; _i++) {
  474. osis = osises[_i];
  475. if (osis.enclosed_indices[0] < 0 && osis.is_enclosed_last) {
  476. osis.indices[1] = osis.enclosed_indices[1];
  477. }
  478. delete osis.is_enclosed_first;
  479. delete osis.is_enclosed_last;
  480. }
  481. return osises;
  482. };
  483. bcv_parser.prototype.is_verse_consecutive = function(prev, check, translation) {
  484. var translation_order;
  485. if (prev.b == null) {
  486. return false;
  487. }
  488. translation_order = this.passage.translations[translation].order != null ? this.passage.translations[translation].order : this.passage.translations["default"].order;
  489. if (prev.b === check.b) {
  490. if (prev.c === check.c) {
  491. if (prev.v === check.v - 1) {
  492. return true;
  493. }
  494. } else if (check.v === 1 && prev.c === check.c - 1) {
  495. if (prev.v === this.passage.translations[translation].chapters[prev.b][prev.c - 1]) {
  496. return true;
  497. }
  498. }
  499. } else if (check.c === 1 && check.v === 1 && translation_order[prev.b] === translation_order[check.b] - 1) {
  500. if (prev.c === this.passage.translations[translation].chapters[prev.b].length && prev.v === this.passage.translations[translation].chapters[prev.b][prev.c - 1]) {
  501. return true;
  502. }
  503. }
  504. return false;
  505. };
  506. bcv_parser.prototype.snap_sequence = function(type, entity, osises, i, length) {
  507. var passage;
  508. passage = entity.passages[i];
  509. if (passage.absolute_indices[0] === entity.absolute_indices[0] && i < length - 1 && this.get_snap_sequence_i(entity.passages, i, length) !== i) {
  510. entity.absolute_indices[0] = entity.passages[i + 1].absolute_indices[0];
  511. this.remove_absolute_indices(entity.passages, i + 1);
  512. } else if (passage.absolute_indices[1] === entity.absolute_indices[1] && i > 0) {
  513. entity.absolute_indices[1] = osises.length > 0 ? osises[osises.length - 1].indices[1] : entity.passages[i - 1].absolute_indices[1];
  514. } else if (type === "book" && i < length - 1 && !this.starts_with_book(entity.passages[i + 1])) {
  515. entity.passages[i + 1].absolute_indices[0] = passage.absolute_indices[0];
  516. }
  517. return entity;
  518. };
  519. bcv_parser.prototype.get_snap_sequence_i = function(passages, i, length) {
  520. var j, _i, _ref;
  521. for (j = _i = _ref = i + 1; _ref <= length ? _i < length : _i > length; j = _ref <= length ? ++_i : --_i) {
  522. if (this.starts_with_book(passages[j])) {
  523. return j;
  524. }
  525. if (passages[j].valid.valid) {
  526. return i;
  527. }
  528. }
  529. return i;
  530. };
  531. bcv_parser.prototype.starts_with_book = function(passage) {
  532. if (passage.type.substr(0, 1) === "b") {
  533. return true;
  534. }
  535. if ((passage.type === "range" || passage.type === "ff") && passage.start.type.substr(0, 1) === "b") {
  536. return true;
  537. }
  538. return false;
  539. };
  540. bcv_parser.prototype.remove_absolute_indices = function(passages, i) {
  541. var end, passage, start, _i, _len, _ref, _ref1;
  542. if (passages[i].enclosed_absolute_indices[0] < 0) {
  543. return false;
  544. }
  545. _ref = passages[i].enclosed_absolute_indices, start = _ref[0], end = _ref[1];
  546. _ref1 = passages.slice(i);
  547. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  548. passage = _ref1[_i];
  549. if (passage.enclosed_absolute_indices[0] === start && passage.enclosed_absolute_indices[1] === end) {
  550. passage.enclosed_absolute_indices = [-1, -1];
  551. } else {
  552. break;
  553. }
  554. }
  555. return true;
  556. };
  557. return bcv_parser;
  558. })();
  559. root.bcv_parser = bcv_parser;
  560. bcv_passage = (function() {
  561. function bcv_passage() {}
  562. bcv_passage.prototype.books = [];
  563. bcv_passage.prototype.indices = {};
  564. bcv_passage.prototype.options = {};
  565. bcv_passage.prototype.translations = {};
  566. bcv_passage.prototype.handle_array = function(passages, accum, context) {
  567. var passage, _i, _len, _ref;
  568. if (accum == null) {
  569. accum = [];
  570. }
  571. if (context == null) {
  572. context = {};
  573. }
  574. for (_i = 0, _len = passages.length; _i < _len; _i++) {
  575. passage = passages[_i];
  576. if (passage.type === "stop") {
  577. break;
  578. }
  579. _ref = this.handle_obj(passage, accum, context), accum = _ref[0], context = _ref[1];
  580. }
  581. return [accum, context];
  582. };
  583. bcv_passage.prototype.handle_obj = function(passage, accum, context) {
  584. if ((passage.type != null) && (this[passage.type] != null)) {
  585. return this[passage.type](passage, accum, context);
  586. } else {
  587. return [accum, context];
  588. }
  589. };
  590. bcv_passage.prototype.b = function(passage, accum, context) {
  591. var alternates, b, obj, valid, _i, _len, _ref, _ref1;
  592. passage.start_context = bcv_utils.shallow_clone(context);
  593. passage.passages = [];
  594. alternates = [];
  595. _ref = this.books[passage.value].parsed;
  596. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  597. b = _ref[_i];
  598. valid = this.validate_ref(passage.start_context.translations, {
  599. b: b
  600. });
  601. obj = {
  602. start: {
  603. b: b
  604. },
  605. end: {
  606. b: b
  607. },
  608. valid: valid
  609. };
  610. if (passage.passages.length === 0 && valid.valid) {
  611. passage.passages.push(obj);
  612. } else {
  613. alternates.push(obj);
  614. }
  615. }
  616. if (passage.passages.length === 0) {
  617. passage.passages.push(alternates.shift());
  618. }
  619. if (alternates.length > 0) {
  620. passage.passages[0].alternates = alternates;
  621. }
  622. if (passage.start_context.translations != null) {
  623. passage.passages[0].translations = passage.start_context.translations;
  624. }
  625. if ((_ref1 = passage.absolute_indices) == null) {
  626. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  627. }
  628. accum.push(passage);
  629. context = {
  630. b: passage.passages[0].start.b
  631. };
  632. if (passage.start_context.translations != null) {
  633. context.translations = passage.start_context.translations;
  634. }
  635. return [accum, context];
  636. };
  637. bcv_passage.prototype.b_range = function(passage, accum, context) {
  638. return this.range(passage, accum, context);
  639. };
  640. bcv_passage.prototype.b_range_pre = function(passage, accum, context) {
  641. var alternates, book, end, start_obj, _ref, _ref1, _ref2;
  642. passage.start_context = bcv_utils.shallow_clone(context);
  643. passage.passages = [];
  644. alternates = [];
  645. book = this.pluck("b", passage.value);
  646. _ref = this.b(book, [], context), (_ref1 = _ref[0], end = _ref1[0]), context = _ref[1];
  647. if ((_ref2 = passage.absolute_indices) == null) {
  648. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  649. }
  650. start_obj = {
  651. b: passage.value[0].value + end.passages[0].start.b.substr(1),
  652. type: "b"
  653. };
  654. passage.passages = [
  655. {
  656. start: start_obj,
  657. end: end.passages[0].end,
  658. valid: end.passages[0].valid
  659. }
  660. ];
  661. if (passage.start_context.translations != null) {
  662. passage.passages[0].translations = passage.start_context.translations;
  663. }
  664. accum.push(passage);
  665. return [accum, context];
  666. };
  667. bcv_passage.prototype.base = function(passage, accum, context) {
  668. this.indices = this.calculate_indices(passage.match, passage.start_index);
  669. return this.handle_array(passage.value, accum, context);
  670. };
  671. bcv_passage.prototype.bc = function(passage, accum, context) {
  672. var alternates, b, c, context_key, obj, type, valid, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4;
  673. passage.start_context = bcv_utils.shallow_clone(context);
  674. passage.passages = [];
  675. _ref = ["b", "c", "v"];
  676. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  677. type = _ref[_i];
  678. delete context[type];
  679. }
  680. c = this.pluck("c", passage.value).value;
  681. alternates = [];
  682. _ref1 = this.books[this.pluck("b", passage.value).value].parsed;
  683. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  684. b = _ref1[_j];
  685. context_key = "c";
  686. valid = this.validate_ref(passage.start_context.translations, {
  687. b: b,
  688. c: c
  689. });
  690. obj = {
  691. start: {
  692. b: b
  693. },
  694. end: {
  695. b: b
  696. },
  697. valid: valid
  698. };
  699. if (valid.messages.start_chapter_not_exist_in_single_chapter_book) {
  700. obj.valid = this.validate_ref(passage.start_context.translations, {
  701. b: b,
  702. v: c
  703. });
  704. obj.start.c = 1;
  705. obj.end.c = 1;
  706. context_key = "v";
  707. }
  708. obj.start[context_key] = c;
  709. _ref2 = this.fix_start_zeroes(obj.valid, obj.start.c, obj.start.v), obj.start.c = _ref2[0], obj.start.v = _ref2[1];
  710. obj.end[context_key] = obj.start[context_key];
  711. if (passage.passages.length === 0 && obj.valid.valid) {
  712. passage.passages.push(obj);
  713. } else {
  714. alternates.push(obj);
  715. }
  716. }
  717. if (passage.passages.length === 0) {
  718. passage.passages.push(alternates.shift());
  719. }
  720. if (alternates.length > 0) {
  721. passage.passages[0].alternates = alternates;
  722. }
  723. if (passage.start_context.translations != null) {
  724. passage.passages[0].translations = passage.start_context.translations;
  725. }
  726. if ((_ref3 = passage.absolute_indices) == null) {
  727. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  728. }
  729. _ref4 = ["b", "c", "v"];
  730. for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
  731. type = _ref4[_k];
  732. if (passage.passages[0].start[type] != null) {
  733. context[type] = passage.passages[0].start[type];
  734. }
  735. }
  736. accum.push(passage);
  737. return [accum, context];
  738. };
  739. bcv_passage.prototype.bc_title = function(passage, accum, context) {
  740. var bc, i, title, _i, _ref, _ref1, _ref2;
  741. passage.start_context = bcv_utils.shallow_clone(context);
  742. _ref = this.bc(this.pluck("bc", passage.value), [], context), (_ref1 = _ref[0], bc = _ref1[0]), context = _ref[1];
  743. if (bc.passages[0].start.b !== "Ps" && (bc.passages[0].alternates != null)) {
  744. for (i = _i = 0, _ref2 = bc.passages[0].alternates.length; 0 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 0 <= _ref2 ? ++_i : --_i) {
  745. if (bc.passages[0].alternates[i].start.b !== "Ps") {
  746. continue;
  747. }
  748. bc.passages[0] = bc.passages[0].alternates[i];
  749. break;
  750. }
  751. }
  752. if (bc.passages[0].start.b !== "Ps") {
  753. accum.push(bc);
  754. return [accum, context];
  755. }
  756. this.books[this.pluck("b", bc.value).value].parsed = ["Ps"];
  757. title = this.pluck("title", passage.value);
  758. passage.value[1] = {
  759. type: "v",
  760. value: [
  761. {
  762. type: "integer",
  763. value: 1,
  764. indices: title.indices
  765. }
  766. ],
  767. indices: title.indices
  768. };
  769. passage.original_type = "bc_title";
  770. passage.type = "bcv";
  771. return this.bcv(passage, accum, passage.start_context);
  772. };
  773. bcv_passage.prototype.bcv = function(passage, accum, context) {
  774. var alternates, b, bc, c, obj, type, v, valid, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4;
  775. passage.start_context = bcv_utils.shallow_clone(context);
  776. passage.passages = [];
  777. _ref = ["b", "c", "v"];
  778. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  779. type = _ref[_i];
  780. delete context[type];
  781. }
  782. bc = this.pluck("bc", passage.value);
  783. c = this.pluck("c", bc.value).value;
  784. v = this.pluck("v", passage.value).value;
  785. alternates = [];
  786. _ref1 = this.books[this.pluck("b", bc.value).value].parsed;
  787. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  788. b = _ref1[_j];
  789. valid = this.validate_ref(passage.start_context.translations, {
  790. b: b,
  791. c: c,
  792. v: v
  793. });
  794. _ref2 = this.fix_start_zeroes(valid, c, v), c = _ref2[0], v = _ref2[1];
  795. obj = {
  796. start: {
  797. b: b,
  798. c: c,
  799. v: v
  800. },
  801. end: {
  802. b: b,
  803. c: c,
  804. v: v
  805. },
  806. valid: valid
  807. };
  808. if (passage.passages.length === 0 && valid.valid) {
  809. passage.passages.push(obj);
  810. } else {
  811. alternates.push(obj);
  812. }
  813. }
  814. if (passage.passages.length === 0) {
  815. passage.passages.push(alternates.shift());
  816. }
  817. if (alternates.length > 0) {
  818. passage.passages[0].alternates = alternates;
  819. }
  820. if (passage.start_context.translations != null) {
  821. passage.passages[0].translations = passage.start_context.translations;
  822. }
  823. if ((_ref3 = passage.absolute_indices) == null) {
  824. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  825. }
  826. _ref4 = ["b", "c", "v"];
  827. for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
  828. type = _ref4[_k];
  829. if (passage.passages[0].start[type] != null) {
  830. context[type] = passage.passages[0].start[type];
  831. }
  832. }
  833. accum.push(passage);
  834. return [accum, context];
  835. };
  836. bcv_passage.prototype.bv = function(passage, accum, context) {
  837. var b, bcv, v, _ref, _ref1, _ref2, _ref3;
  838. passage.start_context = bcv_utils.shallow_clone(context);
  839. _ref = passage.value, b = _ref[0], v = _ref[1];
  840. bcv = {
  841. indices: passage.indices,
  842. value: [
  843. {
  844. type: "bc",
  845. value: [
  846. b, {
  847. type: "c",
  848. value: [
  849. {
  850. type: "integer",
  851. value: 1
  852. }
  853. ]
  854. }
  855. ]
  856. }, v
  857. ]
  858. };
  859. _ref1 = this.bcv(bcv, [], context), (_ref2 = _ref1[0], bcv = _ref2[0]), context = _ref1[1];
  860. passage.passages = bcv.passages;
  861. if (passage.start_context.translations != null) {
  862. passage.passages[0].translations = passage.start_context.translations;
  863. }
  864. if ((_ref3 = passage.absolute_indices) == null) {
  865. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  866. }
  867. accum.push(passage);
  868. return [accum, context];
  869. };
  870. bcv_passage.prototype.c = function(passage, accum, context) {
  871. var c, valid, _ref;
  872. passage.start_context = bcv_utils.shallow_clone(context);
  873. c = passage.type === "integer" ? passage.value : this.pluck("integer", passage.value).value;
  874. valid = this.validate_ref(passage.start_context.translations, {
  875. b: context.b,
  876. c: c
  877. });
  878. if (!valid.valid && valid.messages.start_chapter_not_exist_in_single_chapter_book) {
  879. return this.v(passage, accum, context);
  880. }
  881. c = this.fix_start_zeroes(valid, c)[0];
  882. passage.passages = [
  883. {
  884. start: {
  885. b: context.b,
  886. c: c
  887. },
  888. end: {
  889. b: context.b,
  890. c: c
  891. },
  892. valid: valid
  893. }
  894. ];
  895. if (passage.start_context.translations != null) {
  896. passage.passages[0].translations = passage.start_context.translations;
  897. }
  898. accum.push(passage);
  899. context.c = c;
  900. delete context.v;
  901. if ((_ref = passage.absolute_indices) == null) {
  902. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  903. }
  904. return [accum, context];
  905. };
  906. bcv_passage.prototype.c_psalm = function(passage, accum, context) {
  907. var c;
  908. passage.original_type = passage.type;
  909. passage.original_value = passage.value;
  910. passage.type = "bc";
  911. c = this.books[passage.value].value.match(/^\d+/)[0];
  912. passage.value = [
  913. {
  914. type: "b",
  915. value: passage.original_value,
  916. indices: passage.indices
  917. }, {
  918. type: "c",
  919. value: [
  920. {
  921. type: "integer",
  922. value: c,
  923. indices: passage.indices
  924. }
  925. ],
  926. indices: passage.indices
  927. }
  928. ];
  929. return this.bc(passage, accum, context);
  930. };
  931. bcv_passage.prototype.c_title = function(passage, accum, context) {
  932. var title;
  933. passage.start_context = bcv_utils.shallow_clone(context);
  934. if (context.b !== "Ps") {
  935. return this.c(passage.value[0], accum, context);
  936. }
  937. title = this.pluck("title", passage.value);
  938. passage.value[1] = {
  939. type: "v",
  940. value: [
  941. {
  942. type: "integer",
  943. value: 1,
  944. indices: title.indices
  945. }
  946. ],
  947. indices: title.indices
  948. };
  949. passage.original_type = "c_title";
  950. passage.type = "cv";
  951. return this.cv(passage, accum, passage.start_context);
  952. };
  953. bcv_passage.prototype.cv = function(passage, accum, context) {
  954. var c, v, valid, _ref, _ref1;
  955. passage.start_context = bcv_utils.shallow_clone(context);
  956. c = this.pluck("c", passage.value).value;
  957. v = this.pluck("v", passage.value).value;
  958. valid = this.validate_ref(passage.start_context.translations, {
  959. b: context.b,
  960. c: c,
  961. v: v
  962. });
  963. _ref = this.fix_start_zeroes(valid, c, v), c = _ref[0], v = _ref[1];
  964. passage.passages = [
  965. {
  966. start: {
  967. b: context.b,
  968. c: c,
  969. v: v
  970. },
  971. end: {
  972. b: context.b,
  973. c: c,
  974. v: v
  975. },
  976. valid: valid
  977. }
  978. ];
  979. if (passage.start_context.translations != null) {
  980. passage.passages[0].translations = passage.start_context.translations;
  981. }
  982. accum.push(passage);
  983. context.c = c;
  984. context.v = v;
  985. if ((_ref1 = passage.absolute_indices) == null) {
  986. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  987. }
  988. return [accum, context];
  989. };
  990. bcv_passage.prototype.cb_range = function(passage, accum, context) {
  991. var b, end_c, start_c, _ref;
  992. passage.original_type = passage.type;
  993. passage.type = "range";
  994. _ref = passage.value, b = _ref[0], start_c = _ref[1], end_c = _ref[2];
  995. passage.original_value = [b, start_c, end_c];
  996. passage.value = [
  997. {
  998. type: "bc",
  999. value: [b, start_c],
  1000. indices: passage.indices
  1001. }, end_c
  1002. ];
  1003. end_c.indices[1] = passage.indices[1];
  1004. return this.range(passage, accum, context);
  1005. };
  1006. bcv_passage.prototype.cv_psalm = function(passage, accum, context) {
  1007. var bc, c_psalm, v, _ref;
  1008. passage.start_context = bcv_utils.shallow_clone(context);
  1009. passage.original_type = passage.type;
  1010. passage.original_value = passage.value;
  1011. _ref = passage.value, c_psalm = _ref[0], v = _ref[1];
  1012. passage.type = "bcv";
  1013. bc = this.c_psalm(c_psalm, [], passage.start_context)[0][0];
  1014. passage.value = [bc, v];
  1015. return this.bcv(passage, accum, context);
  1016. };
  1017. bcv_passage.prototype.ff = function(passage, accum, context) {
  1018. var _ref, _ref1, _ref2;
  1019. passage.start_context = bcv_utils.shallow_clone(context);
  1020. passage.value.push({
  1021. type: "integer",
  1022. indices: passage.indices,
  1023. value: 999
  1024. });
  1025. _ref = this.range(passage, [], passage.start_context), (_ref1 = _ref[0], passage = _ref1[0]), context = _ref[1];
  1026. passage.value.pop();
  1027. if (passage.passages[0].valid.end_verse_not_exist != null) {
  1028. delete passage.passages[0].valid.end_verse_not_exist;
  1029. }
  1030. if (passage.passages[0].valid.end_chapter_not_exist != null) {
  1031. delete passage.passages[0].valid.end_chapter_not_exist;
  1032. }
  1033. if (passage.passages[0].end.original_c != null) {
  1034. delete passage.passages[0].end.original_c;
  1035. }
  1036. accum.push(passage);
  1037. if ((_ref2 = passage.absolute_indices) == null) {
  1038. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  1039. }
  1040. return [accum, context];
  1041. };
  1042. bcv_passage.prototype.integer_title = function(passage, accum, context) {
  1043. var v_indices;
  1044. passage.start_context = bcv_utils.shallow_clone(context);
  1045. if (context.b !== "Ps") {
  1046. return this.integer(passage.value[0], accum, context);
  1047. }
  1048. passage.value[0] = {
  1049. type: "c",
  1050. value: [passage.value[0]],
  1051. indices: [passage.value[0].indices[0], passage.value[0].indices[1]]
  1052. };
  1053. v_indices = [passage.indices[1] - 5, passage.indices[1]];
  1054. passage.value[1] = {
  1055. type: "v",
  1056. value: [
  1057. {
  1058. type: "integer",
  1059. value: 1,
  1060. indices: v_indices
  1061. }
  1062. ],
  1063. indices: v_indices
  1064. };
  1065. passage.original_type = "integer_title";
  1066. passage.type = "cv";
  1067. return this.cv(passage, accum, passage.start_context);
  1068. };
  1069. bcv_passage.prototype.integer = function(passage, accum, context) {
  1070. if (context.v != null) {
  1071. return this.v(passage, accum, context);
  1072. }
  1073. return this.c(passage, accum, context);
  1074. };
  1075. bcv_passage.prototype.sequence = function(passage, accum, context) {
  1076. var obj, psg, sub_psg, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
  1077. passage.start_context = bcv_utils.shallow_clone(context);
  1078. passage.passages = [];
  1079. _ref = passage.value;
  1080. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1081. obj = _ref[_i];
  1082. _ref1 = this.handle_array(obj, [], context), (_ref2 = _ref1[0], psg = _ref2[0]), context = _ref1[1];
  1083. _ref3 = psg.passages;
  1084. for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
  1085. sub_psg = _ref3[_j];
  1086. if ((_ref4 = sub_psg.type) == null) {
  1087. sub_psg.type = psg.type;
  1088. }
  1089. if ((_ref5 = sub_psg.absolute_indices) == null) {
  1090. sub_psg.absolute_indices = psg.absolute_indices;
  1091. }
  1092. if (psg.start_context.translations != null) {
  1093. sub_psg.translations = psg.start_context.translations;
  1094. }
  1095. sub_psg.enclosed_absolute_indices = psg.type === "sequence_post_enclosed" ? psg.absolute_indices : [-1, -1];
  1096. passage.passages.push(sub_psg);
  1097. }
  1098. }
  1099. if (passage.absolute_indices == null) {
  1100. if (passage.passages.length > 0 && passage.type === "sequence") {
  1101. passage.absolute_indices = [passage.passages[0].absolute_indices[0], passage.passages[passage.passages.length - 1].absolute_indices[1]];
  1102. } else {
  1103. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  1104. }
  1105. }
  1106. accum.push(passage);
  1107. return [accum, context];
  1108. };
  1109. bcv_passage.prototype.sequence_post_enclosed = function(passage, accum, context) {
  1110. return this.sequence(passage, accum, context);
  1111. };
  1112. bcv_passage.prototype.v = function(passage, accum, context) {
  1113. var c, no_c, v, valid, _ref, _ref1;
  1114. v = passage.type === "integer" ? passage.value : this.pluck("integer", passage.value).value;
  1115. passage.start_context = bcv_utils.shallow_clone(context);
  1116. c = context.c != null ? context.c : 1;
  1117. valid = this.validate_ref(passage.start_context.translations, {
  1118. b: context.b,
  1119. c: c,
  1120. v: v
  1121. });
  1122. _ref = this.fix_start_zeroes(valid, 0, v), no_c = _ref[0], v = _ref[1];
  1123. passage.passages = [
  1124. {
  1125. start: {
  1126. b: context.b,
  1127. c: c,
  1128. v: v
  1129. },
  1130. end: {
  1131. b: context.b,
  1132. c: c,
  1133. v: v
  1134. },
  1135. valid: valid
  1136. }
  1137. ];
  1138. if (passage.start_context.translations != null) {
  1139. passage.passages[0].translations = passage.start_context.translations;
  1140. }
  1141. if ((_ref1 = passage.absolute_indices) == null) {
  1142. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  1143. }
  1144. accum.push(passage);
  1145. context.v = v;
  1146. return [accum, context];
  1147. };
  1148. bcv_passage.prototype.range = function(passage, accum, context) {
  1149. var end, end_obj, new_end, start, start_obj, temp_valid, temp_value, valid, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
  1150. passage.start_context = bcv_utils.shallow_clone(context);
  1151. _ref = passage.value, start = _ref[0], end = _ref[1];
  1152. if (end.type === "v" && (start.type === "bc" || start.type === "c") && this.options.end_range_digits_strategy === "verse") {
  1153. return this.range_change_integer_end(passage, accum);
  1154. }
  1155. _ref1 = this.handle_obj(start, [], context), (_ref2 = _ref1[0], start = _ref2[0]), context = _ref1[1];
  1156. _ref3 = this.handle_obj(end, [], context), (_ref4 = _ref3[0], end = _ref4[0]), context = _ref3[1];
  1157. passage.value = [start, end];
  1158. passage.indices = [start.indices[0], end.indices[1]];
  1159. delete passage.absolute_indices;
  1160. start_obj = {
  1161. b: start.passages[0].start.b,
  1162. c: start.passages[0].start.c,
  1163. v: start.passages[0].start.v,
  1164. type: start.type
  1165. };
  1166. end_obj = {
  1167. b: end.passages[0].end.b,
  1168. c: end.passages[0].end.c,
  1169. v: end.passages[0].end.v,
  1170. type: end.type
  1171. };
  1172. if (end.passages[0].valid.messages.start_chapter_is_zero) {
  1173. end_obj.c = 0;
  1174. }
  1175. if (end.passages[0].valid.messages.start_verse_is_zero) {
  1176. end_obj.v = 0;
  1177. }
  1178. valid = this.validate_ref(passage.start_context.translations, start_obj, end_obj);
  1179. if (valid.valid) {
  1180. if (valid.messages.end_chapter_not_exist && this.options.end_range_digits_strategy === "verse" && !(start_obj.v != null) && (end.type === "integer" || end.type === "v")) {
  1181. temp_value = end.type === "v" ? this.pluck("integer", end.value) : end.value;
  1182. temp_valid = this.validate_ref(passage.start_context.translations, {
  1183. b: start_obj.b,
  1184. c: start_obj.c,
  1185. v: temp_value
  1186. });
  1187. if (temp_valid.valid) {
  1188. return this.range_change_integer_end(passage, accum);
  1189. }
  1190. }
  1191. if (valid.messages.end_chapter_not_exist && this.options.end_range_digits_strategy === "verse" && (start_obj.v != null) && end.type === "cv") {
  1192. temp_valid = this.validate_ref(passage.start_context.translations, {
  1193. b: end_obj.b,
  1194. c: start_obj.c,
  1195. v: end_obj.c
  1196. });
  1197. if (temp_valid.valid) {
  1198. temp_valid = this.validate_ref(passage.start_context.translations, {
  1199. b: end_obj.b,
  1200. c: start_obj.c,
  1201. v: end_obj.v
  1202. });
  1203. }
  1204. if (temp_valid.valid) {
  1205. return this.range_change_cv_end(passage, accum);
  1206. }
  1207. }
  1208. this.range_validate(valid, start_obj, end_obj, passage);
  1209. } else {
  1210. if ((valid.messages.end_chapter_before_start || valid.messages.end_verse_before_start) && (end.type === "integer" || end.type === "v") || (valid.messages.end_chapter_before_start && end.type === "cv")) {
  1211. new_end = this.range_check_new_end(passage.start_context.translations, start_obj, end_obj, valid);
  1212. if (new_end > 0) {
  1213. return this.range_change_end(passage, accum, new_end);
  1214. }
  1215. }
  1216. if (this.options.end_range_digits_strategy === "verse" && start_obj.v === void 0 && (end.type === "integer" || end.type === "v")) {
  1217. temp_value = end.type === "v" ? this.pluck("integer", end.value) : end.value;
  1218. temp_valid = this.validate_ref(passage.start_context.translations, {
  1219. b: start_obj.b,
  1220. c: start_obj.c,
  1221. v: temp_value
  1222. });
  1223. if (temp_valid.valid) {
  1224. return this.range_change_integer_end(passage, accum);
  1225. }
  1226. }
  1227. _ref5 = [passage.type, "sequence"], passage.original_type = _ref5[0], passage.type = _ref5[1];
  1228. _ref6 = [[start, end], [[start], [end]]], passage.original_value = _ref6[0], passage.value = _ref6[1];
  1229. return this.handle_obj(passage, accum, passage.start_context);
  1230. }
  1231. if ((_ref7 = passage.absolute_indices) == null) {
  1232. passage.absolute_indices = this.get_absolute_indices(passage.indices);
  1233. }
  1234. passage.passages = [
  1235. {
  1236. start: start_obj,
  1237. end: end_obj,
  1238. valid: valid
  1239. }
  1240. ];
  1241. if (passage.start_context.translations != null) {
  1242. passage.passages[0].translations = passage.start_context.translations;
  1243. }
  1244. accum.push(passage);
  1245. return [accum, context];
  1246. };
  1247. bcv_passage.prototype.range_change_end = function(passage, accum, new_end) {
  1248. var end, new_obj, start, _ref;
  1249. _ref = passage.value, start = _ref[0], end = _ref[1];
  1250. if (end.type === "integer") {
  1251. end.original_value = end.value;
  1252. end.value = new_end;
  1253. } else if (end.type === "v") {
  1254. new_obj = this.pluck("integer", end.value);
  1255. new_obj.original_value = new_obj.value;
  1256. new_obj.value = new_end;
  1257. } else if (end.type === "cv") {
  1258. new_obj = this.pluck("c", end.value);
  1259. new_obj.original_value = new_obj.value;
  1260. new_obj.value = new_end;
  1261. }
  1262. return this.handle_obj(passage, accum, passage.start_context);
  1263. };
  1264. bcv_passage.prototype.range_change_integer_end = function(passage, accum) {
  1265. var end, start, _ref;
  1266. _ref = passage.value, start = _ref[0], end = _ref[1];
  1267. passage.original_type = passage.type;
  1268. passage.original_value = [start, end];
  1269. passage.type = start.type === "integer" ? "cv" : start.type + "v";
  1270. if (start.type === "integer") {
  1271. passage.value[0] = {
  1272. type: "c",
  1273. value: [start],
  1274. indices: start.indices
  1275. };
  1276. }
  1277. if (end.type === "integ…

Large files files are truncated, but you can click here to view the full file