From a45e622bb3ab7ff1de50960a71c8e3c5392d3ae0 Mon Sep 17 00:00:00 2001 From: Jason Pochanke Date: Fri, 10 Jul 2026 00:23:48 +0200 Subject: [PATCH] ops: added a lint rule and adjusted the build workflow --- .gitea/workflows/build.yml | 21 ++++++++++++++++++--- .gitea/workflows/lint.yml | 8 ++++++++ LICENSE | 20 ++++++++++++++++++++ markdown2.example => example.luma | 2 +- gleam.toml | 11 +++-------- package-lock.json | 2 +- src/luma.gleam | 20 ++++++++++++++++++++ src/{ => luma}/definition.gleam | 24 +++++++++++++++--------- src/{ => luma}/mode.gleam | 0 src/{ => luma}/parser.gleam | 12 +++++++----- src/markdown2.gleam | 24 ------------------------ 11 files changed, 93 insertions(+), 51 deletions(-) create mode 100644 .gitea/workflows/lint.yml create mode 100644 LICENSE rename markdown2.example => example.luma (95%) create mode 100644 src/luma.gleam rename src/{ => luma}/definition.gleam (72%) rename src/{ => luma}/mode.gleam (100%) rename src/{ => luma}/parser.gleam (86%) delete mode 100644 src/markdown2.gleam diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 6c563b2..056aa55 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -7,6 +7,21 @@ on: - "**" # Triggers on every commit to any branch jobs: + format: + runs-on: ubuntu-latest + container: + image: jaypoch/lumabuilder:latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Checking the format + run: gleam format --check + publish: + runs-on: ubuntu-latest + container: + image: jaypoch/lumabuilder:latest + build-and-bundle: runs-on: ubuntu-latest container: @@ -16,13 +31,13 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Build Gleam to JavaScript run: gleam build --target javascript - name: Build bundle run: | - esbuild build/dev/javascript/markdown2/markdown2.mjs \ + esbuild build/dev/javascript/luma/luma.mjs \ --bundle \ --outfile=parser.js \ --format=iife \ @@ -31,4 +46,4 @@ jobs: uses: https://gitea.com/actions/upload-artifact@v3 with: name: parser-js - path: parser.js \ No newline at end of file + path: parser.js diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..28e9037 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,8 @@ +name: formatcheck + +on: + pull_request: + push: + branches: [main] + +jobs: diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..aaed585 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2026 Jaypoch +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/markdown2.example b/example.luma similarity index 95% rename from markdown2.example rename to example.luma index 145590b..52af16f 100644 --- a/markdown2.example +++ b/example.luma @@ -1,4 +1,4 @@ -ljiosfgdjiosdfgj +some text about cats @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. diff --git a/gleam.toml b/gleam.toml index 9a362f7..da26334 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,16 +1,11 @@ -name = "markdown2" +name = "luma" version = "1.0.0" # Fill out these fields if you intend to generate HTML documentation or publish # your project to the Hex package manager. # -# description = "" -# licences = ["Apache-2.0"] -# repository = { type = "github", user = "", repo = "" } -# links = [{ title = "Website", href = "" }] -# -# For a full reference of all the available options, you can have a look at -# https://gleam.run/writing-gleam/gleam-toml/. +description = "A parser for a made up markup language" +licences = ["MIT"] [dependencies] gleam_stdlib = ">= 1.0.0 and < 2.0.0" diff --git a/package-lock.json b/package-lock.json index 307fca1..852b5a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "markdown2", + "name": "luma", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/src/luma.gleam b/src/luma.gleam new file mode 100644 index 0000000..4e6f9f5 --- /dev/null +++ b/src/luma.gleam @@ -0,0 +1,20 @@ +//// The Main function definitions + +import luma/definition +import gleam/io +import gleam/json +import luma/parser + +/// example main function that parses some text into json +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")) +} + +/// same as parse but formats The text instructions as a json string for easier use with javascript +pub fn parse_to_json(input: String) -> String { + let definition.TextInstructions(inlines) = parser.handler(input) + + json.array(inlines, definition.inline_to_json) + |> json.to_string +} diff --git a/src/definition.gleam b/src/luma/definition.gleam similarity index 72% rename from src/definition.gleam rename to src/luma/definition.gleam index ccf2a58..4385060 100644 --- a/src/definition.gleam +++ b/src/luma/definition.gleam @@ -1,24 +1,30 @@ -import gleam/json -import mode +////Main definitions used throughout the programm -pub type Line { - Line(List(Inline)) +import gleam/json +import luma/mode + +/// A list of single instructions +pub type TextInstructions { + TextInstructions(List(Instruction)) } -pub type Inline { +/// a single Instruction on how to change the state or to render text +pub type Instruction { Text(String) - Push(Feeling) - //pop ignores the number + Push(StateObject) + ///pop ignores the number Pop(mode.Type) } -pub type Feeling { +/// A single primitive and its modifier +pub type StateObject { Hirachy(Int) Truth(Int) Marking(Int) Quote(Int) } +/// The main state of the parser with a list of each primitives and there state lists pub type State { State( hirachystate: List(Int), @@ -28,7 +34,7 @@ pub type State { ) } -pub fn inline_to_json(inline: Inline) -> json.Json { +pub fn inline_to_json(inline: Instruction) -> json.Json { case inline { Text(text) -> json.object([ diff --git a/src/mode.gleam b/src/luma/mode.gleam similarity index 100% rename from src/mode.gleam rename to src/luma/mode.gleam diff --git a/src/parser.gleam b/src/luma/parser.gleam similarity index 86% rename from src/parser.gleam rename to src/luma/parser.gleam index 71aea40..74925aa 100644 --- a/src/parser.gleam +++ b/src/luma/parser.gleam @@ -1,18 +1,20 @@ -import definition +import luma/definition import gleam/dict import gleam/int import gleam/list import gleam/result import gleam/string -import mode +import luma/mode -pub fn handler(line: String) -> definition.Line { +/// main parse function +/// takes in some input text and returns instructions on how to parse it +pub fn handler(line: String) -> definition.TextInstructions { let result = parse(line) let result = list.map(result, whatsthat) - definition.Line(result) + definition.TextInstructions(result) } -fn whatsthat(mod: String) -> definition.Inline { +fn whatsthat(mod: String) -> definition.Instruction { let modes = dict.from_list([ #("!", #(mode.Marking, definition.Marking)), diff --git a/src/markdown2.gleam b/src/markdown2.gleam deleted file mode 100644 index aa1cfa4..0000000 --- a/src/markdown2.gleam +++ /dev/null @@ -1,24 +0,0 @@ -import definition -import gleam/io -import gleam/json -import parser - -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, definition.inline_to_json) - |> json.to_string -} - -pub fn parse(input: String) -> definition.Line { - parser.handler(input) -} - -pub fn parse_to_json(input: String) -> String { - line_to_json(parser.handler(input)) -}