a gleam implementation of a CS assignment originally written in cpp

docs: update readme

Changed files
+94 -12
+94 -12
README.md
··· 1 - # bible_search_gleam 1 + # Lab 6 - Gleamified 2 2 3 - [![Package Version](https://img.shields.io/hexpm/v/bible_search_gleam)](https://hex.pm/packages/bible_search_gleam) 4 - [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/bible_search_gleam/) 3 + [![Package Version](https://img.shields.io/hexpm/v/bible_search)](https://hex.pm/packages/bible_search) 4 + [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/bible_search/) 5 5 6 - ```sh 7 - gleam add bible_search_gleam@1 8 - ``` 9 6 ```gleam 10 - import bible_search_gleam 7 + pub fn bible_scan( 8 + reference reference: Reference, 9 + bible bible: String, 10 + ) -> ScanResult { 11 + let inital_state = 12 + ScanState( 13 + phase: Book, 14 + ref: reference, 15 + found_book: False, 16 + found_chapter: False, 17 + verse_text: Error("Verse not found"), 18 + ) 19 + 20 + let bible_lines = string.split(bible, "\n") 11 21 12 - pub fn main() -> Nil { 13 - // TODO: An example of the project in use 22 + let result = 23 + list.fold(bible_lines, inital_state, fn(state, line) -> ScanState { 24 + case state.phase { 25 + Done -> state 26 + Book -> 27 + case line { 28 + "THE BOOK OF " <> book -> 29 + case book == state.ref.book { 30 + True -> ScanState(..state, phase: Chapter, found_book: True) 31 + False -> state 32 + } 33 + _ -> state 34 + } 35 + Chapter -> 36 + case line { 37 + "CHAPTER " <> chapter -> 38 + case result.unwrap(int.parse(chapter), 0) == state.ref.chapter { 39 + True -> ScanState(..state, phase: Verse, found_chapter: True) 40 + False -> state 41 + } 42 + _ -> state 43 + } 44 + Verse -> 45 + fn() { 46 + let parts = string.split(line, " ") 47 + case parts { 48 + [first, ..rest] -> 49 + case result.unwrap(int.parse(first), 0) == state.ref.verse { 50 + True -> 51 + ScanState( 52 + ..state, 53 + phase: Done, 54 + verse_text: Ok(string.join(rest, " ")), 55 + ) 56 + False -> state 57 + } 58 + _ -> state 59 + } 60 + }() 61 + } 62 + }) 63 + 64 + ScanResult(ref: reference, verse: result.verse_text) 14 65 } 15 66 ``` 16 67 17 - Further documentation can be found at <https://hexdocs.pm/bible_search_gleam>. 68 + For this lab the program must parse `OT.txt` (format below) to find specific references and produce scoped errors if the reference isn't found. 69 + 70 + ```text 71 + THE BOOK OF GENESIS 72 + 73 + CHAPTER 1 74 + 1 In the beginning God created the heaven and the earth. 75 + 2 And the earth was without form, and void; and darkness [was] upon the face of the deep. And the Spirit of God moved upon the face of the waters. 76 + 3 And God said, Let there be light: and there was light. 77 + 4 And God saw the light, that [it was] good: and God divided the light from the darkness. 78 + 79 + THE BOOK OF PSALMS 80 + 81 + PSALM 1 82 + 1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful. 83 + 2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night. 84 + 3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper. 85 + ``` 18 86 19 87 ## Development 88 + 89 + You need to have the [gleam runtime](https://gleam.run/getting-started/installing/) installed as well as erlang for the beam runtime. 20 90 21 91 ```sh 22 - gleam run # Run the project 23 - gleam test # Run the tests 92 + gleam run 93 + gleam test # runs all the test functions in /tests postfixed with _test 24 94 ``` 95 + 96 + <p align="center"> 97 + <img src="https://raw.githubusercontent.com/taciturnaxolotl/carriage/main/.github/images/line-break.svg" /> 98 + </p> 99 + 100 + <p align="center"> 101 + <i><code>&copy 2025-present <a href="https://github.com/taciturnaxololt">Kieran Klukas</a></code></i> 102 + </p> 103 + 104 + <p align="center"> 105 + <a href="https://github.com/cu-cs1210/lab-6-kieranklukas/blob/main/LICENSE.md"><img src="https://img.shields.io/static/v1.svg?style=for-the-badge&label=License&message=MIT&logoColor=d9e0ee&colorA=363a4f&colorB=b7bdf8"/></a> 106 + </p>