a gleam implementation of a CS assignment originally written in cpp

docs: update readme

Changed files
+94 -12
+94 -12
README.md
···
-
# bible_search_gleam
+
# Lab 6 - Gleamified
-
[![Package Version](https://img.shields.io/hexpm/v/bible_search_gleam)](https://hex.pm/packages/bible_search_gleam)
-
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/bible_search_gleam/)
+
[![Package Version](https://img.shields.io/hexpm/v/bible_search)](https://hex.pm/packages/bible_search)
+
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/bible_search/)
-
```sh
-
gleam add bible_search_gleam@1
-
```
```gleam
-
import bible_search_gleam
+
pub fn bible_scan(
+
reference reference: Reference,
+
bible bible: String,
+
) -> ScanResult {
+
let inital_state =
+
ScanState(
+
phase: Book,
+
ref: reference,
+
found_book: False,
+
found_chapter: False,
+
verse_text: Error("Verse not found"),
+
)
+
+
let bible_lines = string.split(bible, "\n")
-
pub fn main() -> Nil {
-
// TODO: An example of the project in use
+
let result =
+
list.fold(bible_lines, inital_state, fn(state, line) -> ScanState {
+
case state.phase {
+
Done -> state
+
Book ->
+
case line {
+
"THE BOOK OF " <> book ->
+
case book == state.ref.book {
+
True -> ScanState(..state, phase: Chapter, found_book: True)
+
False -> state
+
}
+
_ -> state
+
}
+
Chapter ->
+
case line {
+
"CHAPTER " <> chapter ->
+
case result.unwrap(int.parse(chapter), 0) == state.ref.chapter {
+
True -> ScanState(..state, phase: Verse, found_chapter: True)
+
False -> state
+
}
+
_ -> state
+
}
+
Verse ->
+
fn() {
+
let parts = string.split(line, " ")
+
case parts {
+
[first, ..rest] ->
+
case result.unwrap(int.parse(first), 0) == state.ref.verse {
+
True ->
+
ScanState(
+
..state,
+
phase: Done,
+
verse_text: Ok(string.join(rest, " ")),
+
)
+
False -> state
+
}
+
_ -> state
+
}
+
}()
+
}
+
})
+
+
ScanResult(ref: reference, verse: result.verse_text)
}
```
-
Further documentation can be found at <https://hexdocs.pm/bible_search_gleam>.
+
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.
+
+
```text
+
THE BOOK OF GENESIS
+
+
CHAPTER 1
+
1 In the beginning God created the heaven and the earth.
+
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.
+
3 And God said, Let there be light: and there was light.
+
4 And God saw the light, that [it was] good: and God divided the light from the darkness.
+
+
THE BOOK OF PSALMS
+
+
PSALM 1
+
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.
+
2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night.
+
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.
+
```
## Development
+
+
You need to have the [gleam runtime](https://gleam.run/getting-started/installing/) installed as well as erlang for the beam runtime.
```sh
-
gleam run # Run the project
-
gleam test # Run the tests
+
gleam run
+
gleam test # runs all the test functions in /tests postfixed with _test
```
+
+
<p align="center">
+
<img src="https://raw.githubusercontent.com/taciturnaxolotl/carriage/main/.github/images/line-break.svg" />
+
</p>
+
+
<p align="center">
+
<i><code>&copy 2025-present <a href="https://github.com/taciturnaxololt">Kieran Klukas</a></code></i>
+
</p>
+
+
<p align="center">
+
<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>
+
</p>