diff --git a/md/learn/classes/anonymous.md b/md/learn/classes/anonymous.md index 44798ab..86f4135 100644 --- a/md/learn/classes/anonymous.md +++ b/md/learn/classes/anonymous.md @@ -14,7 +14,8 @@ class Logger setLogger(Logger()) // Using an anonymous class -setLogger(class { +setLogger(class +{ pub fun log(String msg) { print(msg) @@ -23,7 +24,8 @@ setLogger(class { ``` ```thp -setLogger(class(Int param1) -> SomeClass(param1), SomeInterface { +setLogger(class(Int param1) -> SomeClass(param1), SomeInterface +{ pub fun method() { // code diff --git a/md/learn/classes/definition.md b/md/learn/classes/definition.md index 7ffec60..215dbb3 100644 --- a/md/learn/classes/definition.md +++ b/md/learn/classes/definition.md @@ -2,8 +2,6 @@ Basically kotlin syntax. -Methods have to have a first parameter `$`. - ## Create a new instance of a class @@ -29,19 +27,19 @@ val instance = SimpleClass() class SimpleClass { // Properties are private by default - var String? name; + var String? name = ... // Made public with `pub` - pub var String? surname; + pub var String? surname = ... // Methods are private by default - fun display_name($) + fun display_name() { // `$` is used instead of $this print($name) } - pub fun get_name($) -> String? + pub fun get_name() -> String? { $name } @@ -61,7 +59,7 @@ Kotlin style ```thp class Cat(val String name) { - pub fun get_name($) -> String + pub fun get_name() -> String { $name } @@ -71,6 +69,21 @@ val michifu = Cat("Michifu") print(michifu.get_name()) ``` +With kotlin's `init` block. + +```thp +class Dog(val String name) +{ + val Int name_length + + init + { + print("Dog has been instantiated") + $name_length = name.length() + } +} +``` + ## Inheritance Kotlin style @@ -78,7 +91,7 @@ Kotlin style ```thp class Animal(val String name) { - pub fun say_name($) + pub fun say_name() { print($name) } diff --git a/md/learn/classes/interfaces.md b/md/learn/classes/interfaces.md index ec4242c..c3968c6 100644 --- a/md/learn/classes/interfaces.md +++ b/md/learn/classes/interfaces.md @@ -6,14 +6,14 @@ interface Serializable { // Methods are always public in interfaces - fun serialize($) -> String + fun serialize() -> String } class Cat -> Serializable { - pub fun Serializable($) -> String + pub fun Serializable() -> String { // code } diff --git a/package.json b/package.json index 8cb9fc4..1d09ec6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "generate": "md-docs", - "watch": "concurrently -k \"pnpm tailwind:watch\" \"serve ./static/ -l 3333\"", + "dev": "concurrently -k \"pnpm tailwind:watch\" \"serve ./static/ -l 3333\"", "tailwind:watch": "tailwindcss -i ./tailwind.css -o ./static/css/out.css --watch", "tailwind:build": "tailwindcss -i ./tailwind.css -o ./static/css/out.css --minify" }, diff --git a/static/js/prism.thp.js b/static/js/prism.thp.js index caac184..2805980 100644 --- a/static/js/prism.thp.js +++ b/static/js/prism.thp.js @@ -15,7 +15,7 @@ Prism.languages.thp = { pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, greedy: true, }, - "keyword": /\b(?:static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|val|var|type|match|with|of|abstract|class|interface|private|pub|obj|override|open)\b/, + "keyword": /\b(?:static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|val|var|type|match|with|of|abstract|class|interface|private|pub|obj|override|open|init)\b/, "number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, "operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/, "punctuation": /[{}[\];(),.]/, diff --git a/tailwind.config.js b/tailwind.config.js index b837429..98afe6e 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,28 +1,28 @@ /** @type {import('tailwindcss').Config} */ module.exports = { - content: ["./static/**/*.html"], - theme: { - extend: { - colors: { - "c-bg": "var(--c-bg)", - "c-text": "var(--c-text)", - "c-purple": "var(--c-purple)", - "c-purple-light": "var(--c-purple-light)", - "c-box-shadow": "var(--c-box-shadow)", - "c-ping": "var(--c-pink)", - "c-background-2": "var(--c-background-2)", - "c-primary": "var(--c-primary)", - "c-secondary": "var(--c-secondary)", - "c-nav-bg": "var(--c-nav-bg)", - } + content: ["./static/**/*.html"], + theme: { + extend: { + colors: { + "c-bg": "var(--c-bg)", + "c-text": "var(--c-text)", + "c-purple": "var(--c-purple)", + "c-purple-light": "var(--c-purple-light)", + "c-box-shadow": "var(--c-box-shadow)", + "c-ping": "var(--c-pink)", + "c-background-2": "var(--c-background-2)", + "c-primary": "var(--c-primary)", + "c-secondary": "var(--c-secondary)", + "c-nav-bg": "var(--c-nav-bg)", + } + }, + fontFamily: { + "mono": ["'Fira Code'", "Inconsolata", "Iosevka", "monospace"], + "display": ["'Josefin Sans'", "'Fugaz One'", "sans-serif"], + "body": ["'Fira Sans Condensed'", "Inter", "sans-serif"], + "nav-title": ["'Josefin Sans'", "'Fugaz One'", "sans-serif"], + }, }, - fontFamily: { - "mono": ["'Fira Code'", "Inconsolata", "Iosevka", "monospace"], - "display": ["'Josefin Sans'", "'Fugaz One'", "sans-serif"], - "body": ["'Fira Sans Condensed'", "Inter", "sans-serif"], - "nav-title": ["'Josefin Sans'", "'Fugaz One'", "sans-serif"], - }, - }, - plugins: [], + plugins: [], }