feat(hirachy) hirachy now converts to markdown
Build and Bundle Gleam App / format (push) Successful in 9s
Build and Bundle Gleam App / format (push) Successful in 9s
Signed-off-by: Jason Pochanke <handyjason053@gmail.com>
This commit is contained in:
@@ -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
@@ -1,57 +1,53 @@
|
|||||||
import luma/definition
|
|
||||||
import gleam/list
|
|
||||||
import gleam/io
|
|
||||||
import argv
|
import argv
|
||||||
|
import gleam/io
|
||||||
|
import gleam/list
|
||||||
|
import gleam/string
|
||||||
|
import helpers
|
||||||
|
import luma/definition
|
||||||
import luma/parser
|
import luma/parser
|
||||||
import simplifile
|
import simplifile
|
||||||
type Information {
|
|
||||||
Information(lowesthirachy: Int,
|
pub fn luma_markdown(
|
||||||
highesthirachy: Int)
|
information: helpers.Information,
|
||||||
}
|
contents: String,
|
||||||
fn gather(instructions: List(definition.Instruction))-> Information {
|
) -> String {
|
||||||
let pushes =
|
echo contents
|
||||||
instructions
|
echo information
|
||||||
|> list.filter_map(fn(instruction) {
|
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 {
|
case instruction {
|
||||||
definition.Push(pusher) -> case pusher {
|
definition.Text(instruction) -> instruction
|
||||||
definition.Hirachy(push) -> Ok(push)
|
definition.Push(instruction) ->
|
||||||
_ -> Error(Nil)
|
case instruction {
|
||||||
}
|
definition.Hirachy(instruction) ->
|
||||||
_ -> Error(Nil)
|
string.repeat(
|
||||||
}
|
"#",
|
||||||
})
|
instruction - information.lowesthirachy + 1,
|
||||||
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.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)
|
string.join(parsed, "\n")
|
||||||
}
|
|
||||||
Error(_) -> {
|
|
||||||
Information(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() -> Nil {
|
pub fn main() -> Nil {
|
||||||
case argv.load().arguments {
|
case argv.load().arguments {
|
||||||
[filename] -> {
|
[filename] -> {
|
||||||
@@ -59,11 +55,14 @@ pub fn main() -> Nil {
|
|||||||
Ok(contents) -> {
|
Ok(contents) -> {
|
||||||
//programm goes here
|
//programm goes here
|
||||||
let instructins = parser.handler(contents)
|
let instructins = parser.handler(contents)
|
||||||
let result = case instructins {
|
let information = case instructins {
|
||||||
definition.TextInstructions(instruction) -> gather(instruction)
|
// get informations
|
||||||
_ -> Information(-124, 41234)
|
definition.TextInstructions(instruction) ->
|
||||||
|
helpers.gather(instruction)
|
||||||
}
|
}
|
||||||
echo result
|
echo information
|
||||||
|
let result = luma_markdown(information, contents)
|
||||||
|
io.println(result)
|
||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
Error(_) -> io.println("Couldn't read file")
|
Error(_) -> io.println("Couldn't read file")
|
||||||
@@ -71,5 +70,4 @@ pub fn main() -> Nil {
|
|||||||
}
|
}
|
||||||
_ -> io.println("Usage: gleam run <file>")
|
_ -> io.println("Usage: gleam run <file>")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user