-
-
Save wilmoore/addda46b5e888790e759f98717ac8ea5 to your computer and use it in GitHub Desktop.
Bible Reference Tokenizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // const reference = 'Song of Solomon 7 NLT' | |
| // const reference = 'Song of Solomon NLT' | |
| // const reference = 'Song of Solomon' | |
| // const reference = 'Proverbs 3:21-26 NLT' | |
| // const reference = 'Proverbs 3 NLT' | |
| // const reference = 'Proverbs 3: NLT' | |
| const reference = 'Proverbs 3:1 NLT' | |
| const LINE = '@' | |
| const TOKEN_TYPES = [ | |
| ['BOOK', /\b(song of solomon|song of songs|psalms|proverbs)\b/ui], | |
| ['PASSAGE', /(\b([\d]+[:]?[\d]?[-]?[\d]?)\b)/ui], | |
| ['TRANSLATION', /\b(NLT|NKJV|NIV)\b/ui], | |
| ] | |
| const tokenizer = (source) => { | |
| let reference = source | |
| console.log({ reference }) | |
| TOKEN_TYPES.forEach((tokenType, iteration) => { | |
| console.log(LINE.repeat(10), iteration, LINE.repeat(50)) | |
| const [type, rule] = tokenType | |
| console.log({type, rule}) | |
| const matched = reference.match(rule) | |
| console.log({ matched }) | |
| if (matched) { | |
| let value = matched[1] | |
| reference = reference.slice(value.length).trim() | |
| let token = { type, value } | |
| console.log({ token, reference}) | |
| } | |
| }) | |
| } | |
| tokenizer(reference) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment