master
Araozu 2023-10-23 20:39:34 -05:00
parent 540f9c41e5
commit 45bbfa0ebd
8 changed files with 46 additions and 16 deletions

View File

@ -31,8 +31,8 @@ class SimpleClass
// Properties are private by default
var String? name;
// Made public with `public`
public var String? surname;
// Made public with `pub`
pub var String? surname;
// Methods are private by default
fun display_name($)
@ -41,7 +41,7 @@ class SimpleClass
print($name)
}
public fun get_name($) -> String?
pub fun get_name($) -> String?
{
$name
}
@ -61,7 +61,7 @@ Kotlin style
```thp
class Cat(val String name)
{
public fun get_name($) -> String
pub fun get_name($) -> String
{
$name
}
@ -78,7 +78,7 @@ Kotlin style
```thp
class Animal(val String name)
{
public fun say_name($)
pub fun say_name($)
{
print($name)
}

View File

@ -11,7 +11,7 @@ interface Serializable
class Cat -> Serializable,
class Cat -> Serializable
{
pub fun Serializable($) -> String
{

View File

@ -1,6 +1,6 @@
# Magic methods
Are always public
Don't get special treatment.
```thp
@ -14,3 +14,7 @@ class Cat
```
```thp
```

View File

@ -4,7 +4,13 @@
## Class constants
```thp
static Cat {
class Cat
{
// Stateful code
}
static Cat
{
const CONSTANT = "constant value"
}
@ -18,8 +24,10 @@ aka. plain, old functions
```thp
static Cat {
fun static_method() -> Int {
static Cat
{
fun static_method() -> Int
{
// ...
}
}
@ -34,8 +42,9 @@ aka. global variables
```thp
static Cat {
public var access_count = 0
static Cat
{
pub var access_count = 0
}
print(Cat::access_count) // 0

View File

@ -58,7 +58,7 @@ while index < colors.size()
## Infinite loop
Basically Rust's loop.
Basically Rust*'s loop.
```thp
loop
@ -72,7 +72,8 @@ loop
}
```
* Rust is a trademark of the Rust Foundation. THP is not affiliated,
endorsed or supported by the Rust Foundation.

View File

@ -78,7 +78,20 @@ fun html_special_chars(
html_special_chars(input, double_encode: false)
```
## Named arguments with different names
```thp
fun replace(
String in: input,
String each: pattern,
String with: replacement,
) -> String
{
// Use input, pattern and replacement
}
replace(each: " ", in: "my name", with: "-")
```

View File

@ -17,6 +17,9 @@ fun map[A, B](Array[A] input, (A) -> B function) -> Array[B]
fun generate_generator() -> () -> Int
{
// code...
return fun() {
322
}
}

View File

@ -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|public|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)\b/,
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
"operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/,
"punctuation": /[{}[\];(),.]/,