feat(hirachy) hirachy now converts to markdown
Build and Bundle Gleam App / format (push) Successful in 9s

Signed-off-by: Jason Pochanke <handyjason053@gmail.com>
This commit is contained in:
2026-07-18 03:25:02 +02:00
parent c866682338
commit 0f0939550c
2 changed files with 101 additions and 52 deletions
+51
View File
@@ -0,0 +1,51 @@
import gleam/list
import luma/definition
pub type Information {
Information(lowesthirachy: Int, highesthirachy: Int)
}
pub fn gather(instructions: List(definition.Instruction)) -> Information {
let pushes =
instructions
|> list.filter_map(fn(instruction) {
case instruction {
definition.Push(pusher) ->
case pusher {
definition.Hirachy(push) -> Ok(push)
_ -> Error(Nil)
}
_ -> Error(Nil)
}
})
echo pushes
let min_max = case pushes {
[] -> Error(Nil)
[first, ..rest] ->
Ok(
list.fold(rest, #(first, first), fn(acc, n) {
let #(min, max) = acc
#(
case n < min {
True -> n
False -> min
},
case n > max {
True -> n
False -> max
},
)
}),
)
}
case min_max {
Ok(#(min, max)) -> {
Information(min, max)
}
Error(_) -> {
Information(0, 0)
}
}
}
+49 -51
View File
@@ -1,57 +1,53 @@
import luma/definition
import gleam/list
import gleam/io
import argv
import gleam/io
import gleam/list
import gleam/string
import helpers
import luma/definition
import luma/parser
import simplifile
type Information {
Information(lowesthirachy: Int,
highesthirachy: Int)
}
fn gather(instructions: List(definition.Instruction))-> Information {
let pushes =
instructions
|> list.filter_map(fn(instruction) {
pub fn luma_markdown(
information: helpers.Information,
contents: String,
) -> String {
echo contents
echo information
let lines = string.split(contents, "\n")
let parsed =
list.map(lines, fn(line) -> String {
case parser.handler(line) {
definition.TextInstructions(instruction) ->
string.join(
list.map(instruction, fn(instruction) -> String {
case instruction {
definition.Push(pusher) -> case pusher {
definition.Hirachy(push) -> Ok(push)
_ -> Error(Nil)
}
_ -> Error(Nil)
}
})
echo pushes
let min_max =
case pushes {
[] -> Error(Nil)
[first, ..rest] ->
Ok(
list.fold(rest, #(first, first), fn(acc, n) {
let #(min, max) = acc
#(
case n < min {
True -> n
False -> min
},
case n > max {
True -> n
False -> max
},
definition.Text(instruction) -> instruction
definition.Push(instruction) ->
case instruction {
definition.Hirachy(instruction) ->
string.repeat(
"#",
instruction - information.lowesthirachy + 1,
)
})
definition.Marking(instruction) ->
string.repeat("*", instruction)
definition.Quote(instruction) ->
string.repeat(">", instruction)
definition.Truth(instruction) ->
string.repeat("__", instruction)
}
definition.Pop(instruction) -> "##"
}
}),
"",
)
}
case min_max {
Ok(#(min, max)) -> {
Information(min, max)
}
Error(_) -> {
Information(0, 0)
}
}
})
string.join(parsed, "\n")
}
pub fn main() -> Nil {
case argv.load().arguments {
[filename] -> {
@@ -59,11 +55,14 @@ pub fn main() -> Nil {
Ok(contents) -> {
//programm goes here
let instructins = parser.handler(contents)
let result = case instructins {
definition.TextInstructions(instruction) -> gather(instruction)
_ -> Information(-124, 41234)
let information = case instructins {
// get informations
definition.TextInstructions(instruction) ->
helpers.gather(instruction)
}
echo result
echo information
let result = luma_markdown(information, contents)
io.println(result)
Nil
}
Error(_) -> io.println("Couldn't read file")
@@ -71,5 +70,4 @@ pub fn main() -> Nil {
}
_ -> io.println("Usage: gleam run <file>")
}
}