Add Finnish cases and syntax cheatsheet
This commit is contained in:
@@ -6,19 +6,15 @@ Tampiorama provides working, annotated examples and documentation to help you ex
|
|||||||
|
|
||||||
## Quickstart (Docker)
|
## Quickstart (Docker)
|
||||||
|
|
||||||
The easiest way to try Tampio, no manual `libvoikko` setup required:
|
The easiest way to try Tampio, no manual `libvoikko` setup required.
|
||||||
|
|
||||||
|
Compile all examples to HTML (the `.html` files are not committed — they're generated from the `.itp` sources):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker compose run --rm tampio
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
This drops you into a shell with `tampio` available. Compile an example to HTML:
|
Then serve locally and open in your browser:
|
||||||
|
|
||||||
```sh
|
|
||||||
tampio -i -p examples/basics/hello.itp > examples/basics/hello.html
|
|
||||||
```
|
|
||||||
|
|
||||||
Then serve it locally and open it in your browser:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
python3 -m http.server 9994 --directory examples/basics
|
python3 -m http.server 9994 --directory examples/basics
|
||||||
|
|||||||
@@ -0,0 +1,184 @@
|
|||||||
|
# Tampio Cheatsheet
|
||||||
|
|
||||||
|
Tampio uses Finnish grammatical cases instead of syntax tokens like `(`, `)`, `,`, `.`.
|
||||||
|
The case of a word tells the compiler its role — parameter, argument, target, etc.
|
||||||
|
|
||||||
|
## Finnish Cases in Tampio
|
||||||
|
|
||||||
|
| Case (Finnish) | Suffix | Role in Tampio | Example |
|
||||||
|
|---|---|---|---|
|
||||||
|
| Nominatiivi | — | Function name; return value; variable base form | `kertoma`, `pieni luku` |
|
||||||
|
| Genetiivi | `-n` | Function parameter (in definitions and calls); field access | `pienen luvun kertoma` |
|
||||||
|
| Illatiivi | `-in/-iin/-aan/-ään` | Addend (`lisättynä`); remainder arg (`rajattuna`); assignment target (`luetaan luku`) | `lisättynä kaniin` |
|
||||||
|
| Adessiivi | `-lla/-llä` | Multiplicand (`kerrottuna`); subtrahend (`vähennettynä`); divisor (`jaettuna`); increment amount | `kerrottuna kertomalla` |
|
||||||
|
| Translatiivi | `-ksi` | Assignment lvalue (`asetetaan`) | `kuvaukseksi asetetaan` |
|
||||||
|
| Partitiivi | `-a/-ä/-ta/-tä` | Increment lvalue (`kasvatetaan`); some quantifiers | `laskuria kasvatetaan` |
|
||||||
|
| Essiivi | `-na/-nä` | Two-parameter function name; type conversion | `merkkijonona`, `kerrottuna` |
|
||||||
|
|
||||||
|
## Arithmetic Operators
|
||||||
|
|
||||||
|
These are essive functions — the first operand is the subject, the second follows the operator in the case shown.
|
||||||
|
|
||||||
|
| Operator | Second arg case | JavaScript | Example |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `lisättynä` | illative | `+` | `x lisättynä y:hin` |
|
||||||
|
| `ynnättynä` | illative | `+` | `x ynnättynä y:hin` |
|
||||||
|
| `kasvatettuna` | adessive | `+` | `x kasvatettuna y:llä` |
|
||||||
|
| `vähennettynä` | adessive | `-` | `x vähennettynä y:llä` |
|
||||||
|
| `kerrottuna` | adessive | `*` | `x kerrottuna y:llä` |
|
||||||
|
| `jaettuna` | adessive | `/` | `x jaettuna y:llä` |
|
||||||
|
| `rajattuna` | illative | `%` | `x rajattuna y:hin` |
|
||||||
|
| `yhdistettynä` | illative | `.concat` | `x yhdistettynä y:hin` |
|
||||||
|
|
||||||
|
Operator chaining is controlled by list separators (see Lists below):
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
x jaettuna y:llä vähennettynä z:lla lisättynä w:hen # x/(y-(z+w))
|
||||||
|
x jaettuna y:llä, vähennettynä z:lla ja lisättynä w:hen # ((x/y)-z)+w
|
||||||
|
```
|
||||||
|
|
||||||
|
## Function Definition
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
[parameter/genitive] [function name] on [expression].
|
||||||
|
```
|
||||||
|
|
||||||
|
The parameter must be two words: an adjective + class name. Use `se` to refer to it in the body.
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Pienen luvun kertoma on
|
||||||
|
riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi,
|
||||||
|
joko yksi
|
||||||
|
tai pieni luku kerrottuna pienen luvun edeltäjän kertomalla.
|
||||||
|
```
|
||||||
|
|
||||||
|
Or with unnamed parameter (`se` = `this`):
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Luvun edeltäjä on se vähennettynä yhdellä.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Function Call
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
[argument/genitive] [function name]
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
viiden kertoma # factorial(5)
|
||||||
|
neljän neliöjuuri # sqrt(4)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ternary Expression
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
riippuen siitä, [onko/eikö] [expr] [operator] [expr], joko [a] tai [b]
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi, joko yksi tai ...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comparison Operators
|
||||||
|
|
||||||
|
Used in ternaries and `jos` conditions.
|
||||||
|
|
||||||
|
| Tampio | JavaScript |
|
||||||
|
|---|---|
|
||||||
|
| `on` (empty) | `==` |
|
||||||
|
| `on yhtä suuri kuin` | `==` |
|
||||||
|
| `on sama kuin` | `===` |
|
||||||
|
| `on erisuuri kuin` | `!=` |
|
||||||
|
| `on pienempi kuin` | `<` |
|
||||||
|
| `on suurempi kuin` | `>` |
|
||||||
|
| `on pienempi tai yhtä suuri kuin` | `<=` |
|
||||||
|
| `on enintään` | `<=` |
|
||||||
|
| `on suurempi tai yhtä suuri kuin` | `>=` |
|
||||||
|
| `on vähintään` | `>=` |
|
||||||
|
|
||||||
|
Negate with `ei ole`: `se ei ole nolla` = `this !== 0`.
|
||||||
|
|
||||||
|
## Variable Declaration
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Olkoon [name] uusi [type], jonka [field] on [value].
|
||||||
|
Olkoon [name] [value].
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Olkoon pieni muuttuja uusi muuttuja, jonka arvo on nolla.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Method Definition (Procedures)
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Kun [self] [verb] [parameters],
|
||||||
|
[statement],
|
||||||
|
[statement]
|
||||||
|
ja [last statement].
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Kun nykyinen sivu avautuu,
|
||||||
|
pieneen muuttujaan luetaan luku
|
||||||
|
ja nykyinen sivu näyttää pienen muuttujan arvon kertoman.
|
||||||
|
```
|
||||||
|
|
||||||
|
## If Statement
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
, jos [condition], niin [statement list]
|
||||||
|
, jos taas [condition], niin ... # else if
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
jos listan koko ei ole nolla, niin
|
||||||
|
listan ensimmäinen alkio käsitellään
|
||||||
|
ja listan häntää iteroidaan.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Lists (Blocks)
|
||||||
|
|
||||||
|
Commas and `ja` replace `{` / `}`:
|
||||||
|
|
||||||
|
| Syntax | Meaning |
|
||||||
|
|---|---|
|
||||||
|
| `[a], [b], [c] ja [d]` | List of four items |
|
||||||
|
| `[a] eikä muuta` | List of one item |
|
||||||
|
| `[a].` | List of one item (at end of definition) |
|
||||||
|
|
||||||
|
## Class Definition
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
[class name/adessive] on [field list].
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
Vektorilla on komponentit. # class vektori { komponentit = [] }
|
||||||
|
Työntekijä on henkilö, jolla on työnantaja. # class Tyontekija extends Henkilö
|
||||||
|
```
|
||||||
|
|
||||||
|
## Assignment
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
[lvalue/translative] asetetaan [expression] # lvalue = expression
|
||||||
|
[lvalue/partitive] kasvatetaan [expression/adessive] # lvalue += expression
|
||||||
|
```
|
||||||
|
|
||||||
|
```tampio
|
||||||
|
kivan kaverin kuvaukseksi asetetaan teksti "Hän on kiva"
|
||||||
|
loistavaa laskuria kasvatetaan yhdellä
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Built-ins
|
||||||
|
|
||||||
|
| Tampio | JavaScript | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| `nykyinen sivu` | `document` | HTMLDocument |
|
||||||
|
| `nykyinen sivu näyttää X` | `document.write(X)` | |
|
||||||
|
| `teksti "..."` | `"..."` | String literal |
|
||||||
|
| `lause "..."` | `"..."` | String literal (alternative) |
|
||||||
|
| `muuttujaan luetaan luku` | `muuttuja.arvo = parseInt(prompt(...))` | Read number |
|
||||||
|
| `X näytetään käyttäjälle` | `alert(X)` | Browser alert |
|
||||||
|
| `se` | `this` | Self / first parameter |
|
||||||
|
| `nolla`…`kymmenen` | `0`…`10` | Number literals |
|
||||||
@@ -1,21 +1,12 @@
|
|||||||
/*
|
|
||||||
* Tampio Syntax Highlighting — Typography & Styling
|
|
||||||
*
|
|
||||||
* This stylesheet defines the visual presentation of Tampio source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ===== TYPE STYLES ===== */
|
|
||||||
span.type {
|
span.type {
|
||||||
font-variant: small-caps;
|
font-variant: small-caps;
|
||||||
font-size: large;
|
font-size: large;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== KEYWORDS ===== */
|
|
||||||
span.keyword {
|
span.keyword {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== VARIABLES & FIELDS ===== */
|
|
||||||
span.field {
|
span.field {
|
||||||
text-decoration: underline dotted;
|
text-decoration: underline dotted;
|
||||||
}
|
}
|
||||||
@@ -31,12 +22,10 @@ span.variable-or-field {
|
|||||||
font-size: large;
|
font-size: large;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== FUNCTIONS ===== */
|
|
||||||
span.function {
|
span.function {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== OPERATORS ===== */
|
|
||||||
span.operator {
|
span.operator {
|
||||||
text-decoration: underline dotted;
|
text-decoration: underline dotted;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -47,17 +36,19 @@ span.conditional-operator {
|
|||||||
color: #622;
|
color: #622;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== LITERALS ===== */
|
|
||||||
span.literal {
|
span.literal {
|
||||||
color: #622;
|
color: #622;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== COMMENTS ===== */
|
|
||||||
span.comment-inline, span.block-comment-inline {
|
span.comment-inline, span.block-comment-inline {
|
||||||
color: #226;
|
color: #226;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul:not(.syntax-root) {
|
||||||
|
list-style: disc;
|
||||||
|
}
|
||||||
|
|
||||||
span.comment-global {
|
span.comment-global {
|
||||||
color: black;
|
color: black;
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
@@ -68,11 +59,6 @@ span.block-comment-global {
|
|||||||
color: #226;
|
color: #226;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== LIST STYLES ===== */
|
|
||||||
ul:not(.syntax-root) {
|
|
||||||
list-style: disc;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul.syntax-root > li {
|
ul.syntax-root > li {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
|||||||
Reference in New Issue
Block a user