This commit is contained in:
2026-06-29 15:56:30 +02:00
commit 6fe57399c4
152 changed files with 32122 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import mode
pub type Line {
Line(List(Inline))
}
pub type Inline {
Text(String)
Push(Feeling)
//pop ignores the number
Pop(mode.Type)
}
pub type Feeling {
Hirachy(Int)
Truth(Int)
Marking(Int)
Quote(Int)
}
pub type State {
State(
hirachystate: List(Int),
truthstate: List(Int),
markingstate: List(Int),
quotestate: List(Int),
)
}
+75
View File
@@ -0,0 +1,75 @@
import mode
import gleam/io
import gleam/list
import definition
import gleam/json
import gleam/int
import parser
pub fn main() -> Nil {
let input = "ljiosfgdjiosdfgj
@2! A slightly important statement !1 I believe is wrong, !- quoted inside another quote.
!3 A slightly important statement I believe is wrong, quoted inside another quote.
#3!2@2 A slightly important statement I believe is wrong, quoted inside another quote.
!2@3 important trusted but @- important !5 more important !- 2 important and !- normal"
io.print(line_to_json(parser.handler(input)))
Nil
}
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")
}
),
])
}
}
fn line_to_json(line: definition.Line) -> String {
let definition.Line(inlines) = line
json.array(inlines, inline_to_json)
|> json.to_string}
pub fn testing(input: String) -> String {
line_to_json(parser.handler(input))
}
+6
View File
@@ -0,0 +1,6 @@
pub type Type {
Hirachy
Truth
Marking
Quote
}
+71
View File
@@ -0,0 +1,71 @@
import definition
import mode
import gleam/int
import gleam/result
import gleam/list
import gleam/dict
import gleam/string
pub fn handler(line: String) -> definition.Line {
let result = parse(line)
let result = echo 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)),
])
case string.pop_grapheme(mod) {
Ok(#(prefix, rest)) -> {
case dict.get(modes, prefix) {
Ok(#(m, make_definition)) -> {
case rest {
"-" -> definition.Pop(m)
_ -> {
let value = int.parse(rest) |> result.unwrap(1)
definition.Push(make_definition(value))
}
}
}
Error(_) -> definition.Text(mod)
}
}
Error(_) -> definition.Text(mod)
}
}fn parse(modificators: String) -> List(String) {
modificators
// 1. Target the tags + their trailing space, wrapping them in "|"
|> string.replace(each: "#", with: " |#")
|> string.replace(each: "@", with: " |@")
|> string.replace(each: "!", with: " |!")
|> string.replace(each: ">", with: " |>")
// 2. Split by the space-marker combination
|> string.split(on: " |")
// 3. For each block, split out the tag itself from any trailing words
|> list.flat_map(fn(block) {
case
string.starts_with(block, "#")
|| string.starts_with(block, "@")
|| string.starts_with(block, "!")
|| string.starts_with(block, ">")
{
True -> {
// Separate the tag from the text following it
case string.split_once(block, on: " ") {
Ok(#(tag, rest)) -> [tag, rest]
Error(_) -> [block]
}
}
False -> [block]
}
})
// 4. Clean up padding and drop empty elements
|> list.map(string.trim)
|> list.filter(fn(x) { x != "" })
}