├── .vscode └── launch.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── examples └── example.tengo ├── language-configuration.json ├── logo.png ├── package.json └── syntaxes └── tengo.tmLanguage.json /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | .gitignore 4 | vsc-extension-quickstart.md 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "tengo" extension will be documented in this file. 4 | 5 | ## [Unreleased] 6 | 7 | - Initial release 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Copyright 2022 Sebastien Lacoste 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vscode-tengo 2 | 3 | This extension provides syntax highlighting for the [tengo](https://github.com/d5/tengo) scripting language. 4 | 5 | ## Usage 6 | 7 | - Install the [tengo](https://marketplace.visualstudio.com/items?itemName=graphman.tengo) extension in vscode. 8 | - Enjoy your syntax highlighting 9 | 10 | ## Bugs 11 | 12 | If you find any bugs / wrong highlighting, just fill an issue or a pull request if you already fixed it. 13 | -------------------------------------------------------------------------------- /examples/example.tengo: -------------------------------------------------------------------------------- 1 | /* 2 | Tengo Language 3 | */ 4 | 5 | // module import 6 | fmt := import("fmt") 7 | 8 | // variable definition and primitive types 9 | a := "foo" // string 10 | b := -19.84 // floating point 11 | c := 5 // integer 12 | d := true // boolean 13 | e := '九' // char 14 | fmt.println("a: ", a) 15 | fmt.println("b: ", b) 16 | fmt.println("c: ", c) 17 | fmt.println("d: ", d) 18 | fmt.println("e: ", e) 19 | 20 | // assignment 21 | b = "bar" // can assign value of different type 22 | fmt.println("b: ", b) 23 | 24 | // map and array 25 | m := {a: {b: {c: [1, 2, 3]}}} 26 | fmt.println("m: ", m) 27 | 28 | // slicing 29 | str := "hello world" 30 | fmt.println(str[1:5]) // "ello" 31 | arr := [1, 2, 3, 4, 5] 32 | fmt.println(arr[2:4]) // [3, 4] 33 | 34 | // functions 35 | each := func(seq, fn) { 36 | // array iteration 37 | for x in seq { 38 | fn(x) 39 | } 40 | } 41 | 42 | sum := func(seq) { 43 | s := 0 44 | each(seq, func(x) { 45 | s += x // closure: capturing variable 's' 46 | }) 47 | return s 48 | } 49 | fmt.println("sum: ", sum([1, 2, 3])) // 6 50 | 51 | map_to_array := func(m) { 52 | arr := [] 53 | // map iteration 54 | for key, value in m { 55 | arr = append(arr, key, value) // builtin function 'append' 56 | } 57 | return arr 58 | } 59 | 60 | m_arr := map_to_array(m) 61 | fmt.println(m_arr, " (len: ", len(m_arr), ")") 62 | 63 | // tail-call optimization: faster and enables loop via recursion 64 | count_odds := func(n, c) { 65 | if n == 0 { 66 | return c 67 | } else if n % 2 == 1 { 68 | c++ 69 | } 70 | return count_odds(n-1, c) 71 | } 72 | num_odds := count_odds(100000, 0) 73 | fmt.println(num_odds) // 50000 74 | 75 | // type coercion 76 | s1 := string(1984) // "1984" 77 | i2 := int("-999") // -999 78 | f3 := float(-51) // -51.0 79 | b4 := bool(1) // true 80 | c5 := char(88) // 'X' 81 | 82 | // if statement 83 | if three := 3; three > 2 { // optional init statement 84 | fmt.println("three > 2") 85 | } else if three == 2 { 86 | fmt.println("three = 2") 87 | } else { 88 | fmt.println("three < 2") 89 | } 90 | 91 | // for statement 92 | seven := 0 93 | arr2 := [1, 2, 3, 1] 94 | for i:=0; i>=|=|:=|--|\\+\\+)" 47 | }, 48 | { 49 | "comment": "Arithmetic operator", 50 | "name": "keyword.operator.arithmetic.tengo", 51 | "match": "(!|\\+|-|/|\\*|%|\\^|&|\\||<<|>>|&^)" 52 | }, 53 | { 54 | "comment": "Comparison operator (second group because of regex precedence)", 55 | "name": "keyword.operator.comparison.tengo", 56 | "match": "(<=|>=|<|>)" 57 | }, 58 | { 59 | "comment": "Function call", 60 | "match": "\\b([A-Za-z][A-Za-z0-9_]*|_[A-Za-z0-9_]+)\\s*\\(", 61 | "captures": { 62 | "1": { 63 | "name": "entity.name.function.tengo" 64 | } 65 | } 66 | }, 67 | { 68 | "comment": "Miscellaneous operator", 69 | "name": "keyword.operator.misc.tengo" 70 | } 71 | ], 72 | "repository": { 73 | "keywords": { 74 | "patterns": [ 75 | { 76 | "name": "keyword.control.tengo", 77 | "match": "\\b(if|else|for|return|import|func|export|in|var)\\b" 78 | } 79 | ] 80 | }, 81 | "strings": { 82 | "name": "string.quoted.double.tengo", 83 | "begin": "\"", 84 | "end": "\"", 85 | "patterns": [ 86 | { 87 | "name": "constant.character.escape.tengo", 88 | "match": "\\\\." 89 | } 90 | ] 91 | }, 92 | "raw_strings": { 93 | "name": "string.quoted.double.tengo", 94 | "begin": "`", 95 | "end": "`", 96 | "patterns": [ 97 | { 98 | "name": "constant.character.escape.tengo", 99 | "match": "\\\\." 100 | } 101 | ] 102 | }, 103 | "chars": { 104 | "name": "string.quoted.simple.tengo", 105 | "begin": "'", 106 | "end": "'", 107 | "patterns": [ 108 | { 109 | "name": "constant.character.escape.tengo", 110 | "match": "\\\\." 111 | } 112 | ] 113 | }, 114 | 115 | "comments": { 116 | "name": "comment.line.tengo", 117 | "begin": "//", 118 | "end": "\n" 119 | }, 120 | "block_comment": { 121 | "comment": "Block comment", 122 | "name": "comment.block.tengo", 123 | "begin": "/\\*", 124 | "end": "\\*/" 125 | } 126 | }, 127 | "scopeName": "source.tengo" 128 | } 129 | --------------------------------------------------------------------------------