diff --git a/src/lexer/highlighter.ts b/src/lexer/highlighter.ts index efcdba7..aeb2d44 100644 --- a/src/lexer/highlighter.ts +++ b/src/lexer/highlighter.ts @@ -191,10 +191,10 @@ function process_token_value_and_end(value: string, token_type: TokenType, first } function translate_token_type(tt: TokenType, value: string): string { - const keywords = ["throws", "extends", "constructor", "case", "static", "const", - "enum", "union", "loop", "use", "break", "catch", "continue", "as", "do", - "finally", "for", "fun", "in", "fn", "nil", "return", "throw", - "try", "while", "type", "match", "with", "of", "abstract", "class", "interface", + const keywords = ["throws", "extends", "constructor", "static", "const", + "enum", "union", "use", "break", "catch", "continue", "as", "do", + "finally", "fun", "fn", "nil", "return", "throw", + "try", "type", "with", "of", "abstract", "class", "interface", "private", "protected", "pub", "override", "open", "init", "val", "var", "mut", "clone"]; switch (tt) { @@ -222,6 +222,12 @@ function translate_token_type(tt: TokenType, value: string): string { case "FUN": case "IF": case "ELSE": + case "FOR": + case "IN": + case "WHILE": + case "LOOP": + case "MATCH": + case "CASE": return "keyword"; default: return tt; diff --git a/src/lexer/types.ts b/src/lexer/types.ts index 7837b5c..54f0d55 100644 --- a/src/lexer/types.ts +++ b/src/lexer/types.ts @@ -11,30 +11,37 @@ export interface Token { } export type TokenType = - "Identifier" | - "Datatype" | - "Int" | - "Float" | - "String" | - "Operator" | - "LeftParen" | - "RightParen" | - "LeftBracket" | - "RightBracket" | - "LeftBrace" | - "RightBrace" | - "NewLine" | - "Comment" | - "MultilineComment" | - "Comma" | - "INDENT" | - "DEDENT" | - "VAL" | - "VAR" | - "EOF" | - "FUN" | - "IF" | - "ELSE"; + | "Identifier" + | "Datatype" + | "Int" + | "Float" + | "String" + | "Operator" + | "LeftParen" + | "RightParen" + | "LeftBracket" + | "RightBracket" + | "LeftBrace" + | "RightBrace" + | "NewLine" + | "Comment" + | "MultilineComment" + | "Comma" + | "INDENT" + | "DEDENT" + | "VAL" + | "VAR" + | "EOF" + | "FUN" + | "IF" + | "ELSE" + | "ELSE" + | "FOR" + | "IN" + | "WHILE" + | "MATCH" + | "CASE" + ; export interface Err { Lex?: LexError diff --git a/src/pages/learn/basics/datatypes.mdx b/src/pages/learn/basics/datatypes.mdx index 6cef198..45ea586 100644 --- a/src/pages/learn/basics/datatypes.mdx +++ b/src/pages/learn/basics/datatypes.mdx @@ -60,6 +60,16 @@ Strings have interpolation with `{}`. print("Hello, {name}") // Hello, Rose `} /> +Unlike PHP, THP strings are concatenated with `++`, not with `.`. +This new operator implicitly converts any operator into a string. + + + +The plus operator `+` is reserved for numbers. + ## Bool diff --git a/src/pages/learn/basics/operators.mdx b/src/pages/learn/basics/operators.mdx index 32e47cf..96cf380 100644 --- a/src/pages/learn/basics/operators.mdx +++ b/src/pages/learn/basics/operators.mdx @@ -71,18 +71,16 @@ number xand 1 ## Strings -TBD. - -Strings **do not use `.`** for concatenation. They use `+`. +Strings **do not use `.`** for concatenation. They use `++`. -However, the plus operator `+` does not implicitly convert types. +This new operator **implicitly converts** types to string diff --git a/src/pages/learn/flow-control/loops.mdx b/src/pages/learn/flow-control/loops.mdx index 3dd53a7..7c1c88b 100644 --- a/src/pages/learn/flow-control/loops.mdx +++ b/src/pages/learn/flow-control/loops.mdx @@ -8,14 +8,16 @@ import Code from "../../../components/Code.astro" ## For loop -This is simmilar to PHP's `foreach`. There is no equivalent to PHP's `for`. +THP loops are similar to PHP's `foreach`. There is no equivalent to PHP's `for`. Braces are required. +### Loop over values + + + +### Loop over keys and values + + + + {value}") } `} /> - ## While loop -## Infinite loop - -Instead of doing `while true {}` use `loop`. - - - - ## Labelled loops +TBD + You can give labels to loops, allowing you to `break` and `continue` in nested loops.