some cleanup
Build and Bundle Gleam App / build-and-bundle (push) Successful in 15s

This commit is contained in:
2026-07-09 20:30:16 +02:00
parent 1daef9645e
commit 5bcae0e0d6
3 changed files with 73 additions and 61 deletions
+49
View File
@@ -1,3 +1,4 @@
import gleam/json
import mode
pub type Line {
@@ -26,3 +27,51 @@ pub type State {
quotestate: List(Int),
)
}
pub fn inline_to_json(inline: Inline) -> json.Json {
case inline {
Text(text) ->
json.object([
#("type", json.string("text")),
#("value", json.string(text)),
])
Push(feeling) ->
case feeling {
Marking(level) ->
json.object([
#("type", json.string("marking")),
#("value", json.int(level)),
])
Hirachy(level) ->
json.object([
#("type", json.string("hirachy")),
#("value", json.int(level)),
])
Truth(level) ->
json.object([
#("type", json.string("truth")),
#("value", json.int(level)),
])
Quote(level) ->
json.object([
#("type", json.string("quote")),
#("value", json.int(level)),
])
}
Pop(text) ->
json.object([
#("type", json.string("pop")),
#("value", case text {
mode.Hirachy -> json.string("Hirachy")
mode.Truth -> json.string("Truth")
mode.Marking -> json.string("Marking")
mode.Quote -> json.string("Quote")
}),
])
}
}
+8 -49
View File
@@ -1,61 +1,20 @@
import mode
import definition
import gleam/io
import gleam/json
import parser
fn inline_to_json(inline: definition.Inline) -> json.Json {
case inline {
definition.Text(text) ->
json.object([
#("type", json.string("text")),
#("value", json.string(text)),
])
definition.Push(feeling) ->
case feeling {
definition.Marking(level) ->
json.object([
#("type", json.string("marking")),
#("value", json.int(level)),
])
definition.Hirachy(level) ->
json.object([
#("type", json.string("hirachy")),
#("value", json.int(level)),
])
definition.Truth(level) ->
json.object([
#("type", json.string("truth")),
#("value", json.int(level)),
])
definition.Quote(level) ->
json.object([
#("type", json.string("quote")),
#("value", json.int(level)),
])
}
definition.Pop(text) ->
json.object([
#("type", json.string("pop")),
#("value", case text {
mode.Hirachy -> json.string("Hirachy")
mode.Truth -> json.string("Truth")
mode.Marking -> json.string("Marking")
mode.Quote -> json.string("Quote")
}
),
])
}
pub fn main() -> Nil {
io.print("This is a debug function only used for testing")
io.print(parse_to_json("!2 @3 important >1 quoted"))
}
fn line_to_json(line: definition.Line) -> String {
let definition.Line(inlines) = line
json.array(inlines, inline_to_json)
|> json.to_string}
json.array(inlines, definition.inline_to_json)
|> json.to_string
}
pub fn parse(input: String) -> definition.Line {
parser.handler(input)
}
+16 -12
View File
@@ -1,23 +1,25 @@
import definition
import mode
import gleam/int
import gleam/result
import gleam/list
import gleam/dict
import gleam/int
import gleam/list
import gleam/result
import gleam/string
import mode
pub fn handler(line: String) -> definition.Line {
let result = parse(line)
let result = echo list.map(result, whatsthat)
let result = list.map(result, whatsthat)
definition.Line(result)
}
fn whatsthat(mod: String) -> definition.Inline {
let modes = dict.from_list([
#("!", #(mode.Marking, definition.Marking)),
#("@", #(mode.Truth, definition.Truth)),
#(">", #(mode.Quote, definition.Quote)),
#("#", #(mode.Hirachy, definition.Hirachy)),
])
let modes =
dict.from_list([
#("!", #(mode.Marking, definition.Marking)),
#("@", #(mode.Truth, definition.Truth)),
#(">", #(mode.Quote, definition.Quote)),
#("#", #(mode.Hirachy, definition.Hirachy)),
])
case string.pop_grapheme(mod) {
Ok(#(prefix, rest)) -> {
@@ -38,7 +40,9 @@ fn whatsthat(mod: String) -> definition.Inline {
Error(_) -> definition.Text(mod)
}
}fn parse(modificators: String) -> List(String) {
}
fn parse(modificators: String) -> List(String) {
modificators
// 1. Target the tags + their trailing space, wrapping them in "|"
|> string.replace(each: "#", with: " |#")