Blog RSS Feed

A Javascript Bible Passage Reference Parser

Browse the Github repository of a new Bible-reference parser written in Coffeescript / Javascript (it understands text like “John 3:16”), try a demo, or review the annotated source. You can use the parser as-is or as a starting point for building your own–the source code includes 200,000 real-world passage references to give you a head start. It’s designed to handle how people actually type Bible references (typos and all) and tries hard to make sense of any input you give it.

From the readme:

This is the fourth complete Bible reference parser that I’ve written. It’s how I try out new programming languages: the first one was in PHP (2002), which saw production usage on a Bible search website from 2002-2011; the second in Perl (2007), which saw production usage on a Bible-related site starting in 2007; and the third in Ruby (2009), which never saw production usage because it was way too slow. This Coffeescript parser (at least on V8) is faster than the Perl one and 100 times faster than the Ruby one.

I chose Coffeescript out of curiosity–does it make Javascript that much more pleasant to work with? From a programming perspective, the easy loops and array comprehensions alone practically justify its use. From a readability perspective, the code is easier to follow (and come back to months later) than the equivalent Javascript–the tests, in particular, are much easier to follow without all the Javascript punctuation.

My main interest in open-sourcing and thoroughly documenting this code lies in giving future programmers data and code that they can use to build better parsers. While this code reflects my experience, it’s hardly the last word on the subject.

Comments are closed.