This commit is contained in:
Araozu 2024-05-16 10:00:46 -05:00
parent 9fa2d8caa3
commit 253e4bbb48
10 changed files with 172 additions and 12 deletions

View File

@ -30,4 +30,5 @@ Only these two:
*/ */
``` ```
TBD: Doc comments use triple slash `///`? or `/** */`?

View File

@ -5,7 +5,10 @@ title: Datatypes
# Datatypes # Datatypes
Datatypes's first character are always uppercase. THP requires that all datatypes start their name with an
uppercase letter.
The following are basic datatypes.
## Int ## Int
@ -13,8 +16,17 @@ Same as php int
```thp ```thp
Int age = 32 Int age = 32
// Hexadecimal numbers start with 0x
Int red = 0xff0000 Int red = 0xff0000
// Octal numbers start with 0o
Int permissions = 0o775
// Binary numbers start with 0b
Int char_code = 0b01000110 Int char_code = 0b01000110
// IMPORTANT!
// Since Octal starts with `0o`, using just a leading 0
// will result in a decimal!
Int not_octal = 032 // This is 32, not 26
``` ```
@ -25,26 +37,35 @@ Same as php float
```thp ```thp
Float pi = 3.141592 Float pi = 3.141592
Float light = 2.99e+8
``` ```
## String ## String
Same as php string THP strings use **only** double quotes. Single quotes are
used elsewhere.
```thp ```thp
String name = "Rose" String name = "Rose"
``` ```
Strings have interpolation with `{}`.
## Bool
Same as php bool
```thp ```thp
Bool is_true = true print("Hello, {name}") // Hello, Rose
``` ```
## Bool
THP booleans are `true` and `false`. They are case sensitive,
**only lowercase.**
```thp
Bool is_true = true
Bool is_false = false
// This is a compile error
val invalid = TRUE
```

View File

@ -1,10 +1,120 @@
--- ---
layout: ../../../layouts/PagesLayout.astro layout: ../../../layouts/PagesLayout.astro
title: Install title: Operators
--- ---
# Operators # Operators
Some common operators
Most of the PHP operators are present in THP.
## Numbers
```thp
var number = 322
number + 1
number - 1
number * 1
number / 1
number % 2
number += 1
number -= 1
number *= 1
number /= 1
number %= 2
```
**There are no prefix/postfix increment**, use `+=` or `-=`.
```thp
// Use
number += 1
// instead of
number++ // This is a compile error
```
### Comparison
These operators will not do implicit type conversion. They can
only be used with same datatypes.
```thp
v1 < v2
v1 <= v2
v1 > v2
v1 >= v2
```
There is only `==` and `!=`. They are equivalent to `===` and `!==`.
```thp
v1 == v2
v1 != v2
```
### Bitwise
TBD
```thp
number and 1
number or 2
number xor 1
number xand 1
```
## Strings
TBD.
Strings **do not use `.`** for concatenation. They use `+`.
```thp
"Hello " + "world."
```
However, the plus operator `+` does not implicitly convert types.
```thp
"Hello " + 322 // This is an error
```
## Boolean
These operators work **only with booleans**, they do not perform
type coercion.
```thp
c1 && c2
c1 || c2
```
## Ternary
There is no ternary operator. See [Conditionals](/learn/flow-control/conditionals) for alternatives.
## Null
These are detailed in their section: [Nullable types](/learn/error-handling/null)
```thp
val person = some_fun()
person?.name
person?.name ?? "Jane"
person?.greet?.()
if person?
{
person.name
}
```

View File

@ -8,6 +8,11 @@ title: Variables
thp distinguishes between mutable and immutable variables. thp distinguishes between mutable and immutable variables.
Variables have to be declared in THP, to avoid issues with scopes.
It is a compile error to use undeclared variables.
Variable names **must** begin with a lowercase letter.
## Immutable variables ## Immutable variables
Defined with `val`, followed by a variable name and a value. Defined with `val`, followed by a variable name and a value.

View File

@ -5,6 +5,8 @@ title: Maps
# Maps # Maps
TBD.
Also known as Associative Arrays, or Objects in other languages. Also known as Associative Arrays, or Objects in other languages.
All maps must have a definition, which define their fields and datatypes. All maps must have a definition, which define their fields and datatypes.

View File

@ -5,5 +5,19 @@ title: Blocks
# Blocks # Blocks
Blocks :D Blocks of code are denoted with brackets `{}`.
Blocks can be assigned to variables, in which case
they are executed and their last expression is
returned.
```thp
val result = {
val temp = 161
temp * 2 // This will be assigned to `result`
}
print(result) // 322
```

View File

@ -44,6 +44,8 @@ if variable is Datatype
## If variable is of enum ## If variable is of enum
TBD
```thp ```thp
val user_id = POST::get("user_id") val user_id = POST::get("user_id")

View File

@ -7,6 +7,8 @@ title: Loops
## For loop ## For loop
This is simmilar to PHP's `foreach`. There is no equivalent to PHP's `for`.
Braces are required. Braces are required.
```thp ```thp
@ -51,7 +53,7 @@ for value in collection
```thp ```thp
val colors = ["red", "green", "blue"] val colors = ["red", "green", "blue"]
val mut index = 0 var index = 0
while index < colors.size() while index < colors.size()
{ {

View File

@ -5,6 +5,8 @@ title: Declaration
# Declaration # Declaration
Function names **must** begin with a lowercase letter.
## No parameters, no return ## No parameters, no return

View File

@ -11,13 +11,14 @@ pagesLayout:
- path: variables - path: variables
- path: datatypes - path: datatypes
- path: comments - path: comments
- path: operators
- path: flow-control - path: flow-control
title: Flow control title: Flow control
children: children:
- path: blocks
- path: conditionals - path: conditionals
- path: loops - path: loops
- path: match - path: match
- path: blocks
- path: data-structures - path: data-structures
title: Data structures title: Data structures
children: children: