diff --git a/compiler/lexer.ts b/compiler/lexer.ts index f831e9f..8bd4f48 100644 --- a/compiler/lexer.ts +++ b/compiler/lexer.ts @@ -26,27 +26,27 @@ export class Lexer { value += this.current(); this.step(); } - switch (value) { - case "break": - return this.token("break", pos); - case "return": - return this.token("return", pos); - case "let": - return this.token("let", pos); - case "fn": - return this.token("fn", pos); - case "loop": - return this.token("loop", pos); - case "if": - return this.token("if", pos); - case "else": - return this.token("else", pos); - case "struct": - return this.token("struct", pos); - case "import": - return this.token("import", pos); - default: - return { ...this.token("ident", pos), identValue: value }; + const keywords = [ + "break", + "return", + "let", + "fn", + "loop", + "if", + "else", + "struct", + "import", + "false", + "true", + "null", + "or", + "and", + "not", + ]; + if (keywords.includes(value)) { + return this.token(value, pos); + } else { + return { ...this.token("ident", pos), identValue: value }; } } if (this.test(/[1-9]/)) { @@ -76,11 +76,12 @@ export class Lexer { if (this.done()) { break; } - value += { - "n": "\n", - "t": "\t", - "0": "\0", - }[this.current()] ?? this.current(); + value += + { + n: "\n", + t: "\t", + "0": "\0", + }[this.current()] ?? this.current(); } else { value += this.current(); } @@ -142,50 +143,7 @@ export class Lexer { } return this.token("/", pos); } - if (this.test("false")) { - this.step(); - return this.token("false", pos); - } - if (this.test("true")) { - this.step(); - return this.token("true", pos); - } - if (this.test("null")) { - this.step(); - return this.token("null", pos); - } - if (this.test("or")) { - this.step(); - return this.token("or", pos); - } - if (this.test("and")) { - this.step(); - return this.token("and", pos); - } - if (this.test("not")) { - this.step(); - return this.token("not", pos); - } - if (this.test("loop")) { - this.step(); - return this.token("loop", pos); - } - if (this.test("break")) { - this.step(); - return this.token("break", pos); - } - if (this.test("let")) { - this.step(); - return this.token("let", pos); - } - if (this.test("fn")) { - this.step(); - return this.token("fn", pos); - } - if (this.test("return")) { - this.step(); - return this.token("return", pos); - } + this.report(`illegal character '${this.current()}'`, pos); this.step(); return this.next(); diff --git a/editors/install_vscode.sh b/editors/install_vscode.sh new file mode 100644 index 0000000..c4b0404 --- /dev/null +++ b/editors/install_vscode.sh @@ -0,0 +1,4 @@ +# make sure to run this in repository root directory + +rm -r ~/.vscode/extensions/slige +cp -r vscode ~/.vscode/extensions/slige \ No newline at end of file diff --git a/editors/install_vscode_oss.sh b/editors/install_vscode_oss.sh new file mode 100644 index 0000000..1666742 --- /dev/null +++ b/editors/install_vscode_oss.sh @@ -0,0 +1,4 @@ +# make sure to run this in repository root directory + +rm -rf ~/.vscode-oss/extensions/slige +cp -r vscode ~/.vscode-oss/extensions/slige \ No newline at end of file diff --git a/editors/vscode/.vscode/launch.json b/editors/vscode/.vscode/launch.json new file mode 100644 index 0000000..0e191b5 --- /dev/null +++ b/editors/vscode/.vscode/launch.json @@ -0,0 +1,17 @@ +// A launch configuration that launches the extension inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ] + } + ] +} \ No newline at end of file diff --git a/editors/vscode/.vscodeignore b/editors/vscode/.vscodeignore new file mode 100644 index 0000000..f369b5e --- /dev/null +++ b/editors/vscode/.vscodeignore @@ -0,0 +1,4 @@ +.vscode/** +.vscode-test/** +.gitignore +vsc-extension-quickstart.md diff --git a/editors/vscode/CHANGELOG.md b/editors/vscode/CHANGELOG.md new file mode 100644 index 0000000..b1cdff3 --- /dev/null +++ b/editors/vscode/CHANGELOG.md @@ -0,0 +1,9 @@ +# Change Log + +All notable changes to the "slige" extension will be documented in this file. + +Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. + +## [Unreleased] + +- Initial release \ No newline at end of file diff --git a/editors/vscode/README.md b/editors/vscode/README.md new file mode 100644 index 0000000..ec1a2ce --- /dev/null +++ b/editors/vscode/README.md @@ -0,0 +1,65 @@ +# slige README + +This is the README for your extension "slige". After writing up a brief description, we recommend including the following sections. + +## Features + +Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file. + +For example if there is an image subfolder under your extension project workspace: + +\!\[feature X\]\(images/feature-x.png\) + +> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow. + +## Requirements + +If you have any requirements or dependencies, add a section describing those and how to install and configure them. + +## Extension Settings + +Include if your extension adds any VS Code settings through the `contributes.configuration` extension point. + +For example: + +This extension contributes the following settings: + +* `myExtension.enable`: Enable/disable this extension. +* `myExtension.thing`: Set to `blah` to do something. + +## Known Issues + +Calling out known issues can help limit users opening duplicate issues against your extension. + +## Release Notes + +Users appreciate release notes as you update your extension. + +### 1.0.0 + +Initial release of ... + +### 1.0.1 + +Fixed issue #. + +### 1.1.0 + +Added features X, Y, and Z. + +--- + +## Working with Markdown + +You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: + +* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux). +* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux). +* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets. + +## For more information + +* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) +* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) + +**Enjoy!** diff --git a/editors/vscode/language-configuration.json b/editors/vscode/language-configuration.json new file mode 100644 index 0000000..7fcbbe3 --- /dev/null +++ b/editors/vscode/language-configuration.json @@ -0,0 +1,29 @@ +{ + "comments": { + // symbol used for single line comment. Remove this entry if your language does not support line comments + "lineComment": "//", + // symbols used for start and end a block comment. Remove this entry if your language does not support block comments + "blockComment": [ "/*", "*/" ] + }, + // symbols used as brackets + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + // symbols that are auto closed when typing + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ], + // symbols that can be used to surround a selection + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""] + ] +} \ No newline at end of file diff --git a/editors/vscode/package.json b/editors/vscode/package.json new file mode 100644 index 0000000..a18410b --- /dev/null +++ b/editors/vscode/package.json @@ -0,0 +1,25 @@ +{ + "name": "slige", + "displayName": "slige", + "description": "", + "version": "0.0.1", + "engines": { + "vscode": "^1.96.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [{ + "id": "slige", + "aliases": ["Slige", "slige"], + "extensions": [".slg"], + "configuration": "./language-configuration.json" + }], + "grammars": [{ + "language": "slige", + "scopeName": "source.slige", + "path": "./syntaxes/slige.tmLanguage.json" + }] + } +} diff --git a/editors/vscode/syntaxes/slige.tmLanguage.json b/editors/vscode/syntaxes/slige.tmLanguage.json new file mode 100644 index 0000000..70c5dbc --- /dev/null +++ b/editors/vscode/syntaxes/slige.tmLanguage.json @@ -0,0 +1,99 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "Slige", + "patterns": [ + { "include": "#keywords" }, + { "include": "#strings" }, + { "include": "#numbers" }, + { "include": "#operators" }, + { "include": "#punctuation" }, + { "include": "#functions" }, + { "include": "#idents" } + ], + "repository": { + "keywords": { + "patterns": [ + { + "name": "keyword.control.slige", + "match": "\\b(break|return|let|fn|loop|if|else|struct|import|or|and|not)\\b" + }, + { + "name": "constant.language.slige", + "match": "\\b(null|false|true)\\b" + }, + { + "name": "storage.type.slige", + "match": "\\b(int|string|bool)\\b" + } + ] + }, + "strings": { + "name": "string.quoted.double.slige", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.slige", + "match": "\\\\." + } + ] + }, + "numbers": { + "patterns": [ + { + "name": "constant.numeric.slige", + "match": "\\b0\\b" + }, + { + "name": "constant.numeric.slige", + "match": "\\b[1-9][0-9]*(\\.[0-9]+)?\\b" + }, + { + "name": "constant.numeric.slige", + "match": "\\b0x[0-9a-fA-F]+?\\b" + }, + { + "name": "constant.numeric.slige", + "match": "\\b0b[01]+?\\b" + } + ] + }, + "operators": { + "patterns": [ + { + "match": "\\+|\\-|\\*|\\/|=|(==)|(!=)|<|>|(<=)|(>=)|\\.|:|(\\->)", + "name": "keyword.operator.slige" + } + ] + }, + "punctuation": { + "patterns": [ + { + "match": ";", + "name": "punctuation.terminator.statement.slige" + }, + { + "match": ",", + "name": "punctuation.separator.delimiter.slige" + } + ] + }, + "functions": { + "patterns": [ + { + "match": "(?>\\b[a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=(?>\\:\\:<.*?>)?\\()", + "name": "entity.name.function.slige" + } + ] + }, + "idents": { + "patterns": [ + { + "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b", + "name": "variable.other.slige" + } + ] + } + }, + "scopeName": "source.slige" +} \ No newline at end of file diff --git a/editors/vscode/vsc-extension-quickstart.md b/editors/vscode/vsc-extension-quickstart.md new file mode 100644 index 0000000..ef06bc7 --- /dev/null +++ b/editors/vscode/vsc-extension-quickstart.md @@ -0,0 +1,29 @@ +# Welcome to your VS Code Extension + +## What's in the folder + +* This folder contains all of the files necessary for your extension. +* `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension. +* `syntaxes/slige.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization. +* `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets. + +## Get up and running straight away + +* Make sure the language configuration settings in `language-configuration.json` are accurate. +* Press `F5` to open a new window with your extension loaded. +* Create a new file with a file name suffix matching your language. +* Verify that syntax highlighting works and that the language configuration settings are working. + +## Make changes + +* You can relaunch the extension from the debug toolbar after making changes to the files listed above. +* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. + +## Add more language features + +* To add features such as IntelliSense, hovers and validators check out the VS Code extenders documentation at https://code.visualstudio.com/docs + +## Install your extension + +* To start using your extension with Visual Studio Code copy it into the `/.vscode/extensions` folder and restart Code. +* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension.