From e9125e571c4ac6216c87ee40dbc47c7d2c564803 Mon Sep 17 00:00:00 2001 From: nub31 Date: Thu, 22 May 2025 19:45:02 +0200 Subject: [PATCH] syntax highlighting --- .gitignore | 3 +- build.sh | 2 +- clean.sh | 4 +- debug.sh | 2 +- run.sh | 2 +- src/tooling/syntax-highlighting/code/build.sh | 2 + .../code/language-configuration.json | 29 ++ .../syntax-highlighting/code/package.json | 35 +++ .../code/syntaxes/nub.tmLanguage.json | 259 ++++++++++++++++++ 9 files changed, 332 insertions(+), 6 deletions(-) create mode 100644 src/tooling/syntax-highlighting/code/build.sh create mode 100644 src/tooling/syntax-highlighting/code/language-configuration.json create mode 100644 src/tooling/syntax-highlighting/code/package.json create mode 100644 src/tooling/syntax-highlighting/code/syntaxes/nub.tmLanguage.json diff --git a/.gitignore b/.gitignore index c585e19..3d46c66 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -out \ No newline at end of file +out +src/tooling/syntax-highlighting/code/nub-lang-*.vsix \ No newline at end of file diff --git a/build.sh b/build.sh index 88e5648..ec564b4 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e mkdir -p out diff --git a/clean.sh b/clean.sh index 5d94bd7..552d583 100755 --- a/clean.sh +++ b/clean.sh @@ -1,2 +1,2 @@ -#!/bin/sh -rm -rf out \ No newline at end of file +#!/bin/bash +rm -rf out diff --git a/debug.sh b/debug.sh index 17f8778..5b44083 100755 --- a/debug.sh +++ b/debug.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e ./clean.sh ./build.sh diff --git a/run.sh b/run.sh index 385090b..d6e850f 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ./clean.sh ./build.sh ./out/program diff --git a/src/tooling/syntax-highlighting/code/build.sh b/src/tooling/syntax-highlighting/code/build.sh new file mode 100644 index 0000000..6c4343f --- /dev/null +++ b/src/tooling/syntax-highlighting/code/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +npx vsce package diff --git a/src/tooling/syntax-highlighting/code/language-configuration.json b/src/tooling/syntax-highlighting/code/language-configuration.json new file mode 100644 index 0000000..538ffc1 --- /dev/null +++ b/src/tooling/syntax-highlighting/code/language-configuration.json @@ -0,0 +1,29 @@ +{ + "comments": { + "lineComment": "//", + "blockComment": ["/*", "*/"] + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ], + "indentationRules": { + "increaseIndentPattern": "^((?!\\/\\*).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$", + "decreaseIndentPattern": "^((?!.*?\\/\\*).*\\*/)?\\s*[\\}\\]\\)].*$" + } +} diff --git a/src/tooling/syntax-highlighting/code/package.json b/src/tooling/syntax-highlighting/code/package.json new file mode 100644 index 0000000..e4b08d5 --- /dev/null +++ b/src/tooling/syntax-highlighting/code/package.json @@ -0,0 +1,35 @@ +{ + "name": "nub-lang", + "displayName": "Nub Language Support", + "description": "Syntax highlighting for Nub programming language", + "version": "0.1.0", + "publisher": "nub31", + "engines": { + "vscode": "^1.74.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [ + { + "id": "nub", + "aliases": [ + "Nub", + "nub" + ], + "extensions": [ + ".nub" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "nub", + "scopeName": "source.nub", + "path": "./syntaxes/nub.tmLanguage.json" + } + ] + } +} diff --git a/src/tooling/syntax-highlighting/code/syntaxes/nub.tmLanguage.json b/src/tooling/syntax-highlighting/code/syntaxes/nub.tmLanguage.json new file mode 100644 index 0000000..9c1c874 --- /dev/null +++ b/src/tooling/syntax-highlighting/code/syntaxes/nub.tmLanguage.json @@ -0,0 +1,259 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "Nub", + "scopeName": "source.nub", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#keywords" + }, + { + "include": "#modifiers" + }, + { + "include": "#types" + }, + { + "include": "#strings" + }, + { + "include": "#numbers" + }, + { + "include": "#operators" + }, + { + "include": "#function-definition" + }, + { + "include": "#struct-definition" + }, + { + "include": "#function-call" + }, + { + "include": "#identifiers" + } + ], + "repository": { + "comments": { + "patterns": [ + { + "name": "comment.line.double-slash.nub", + "begin": "//", + "end": "$" + }, + { + "name": "comment.block.nub", + "begin": "/\\*", + "end": "\\*/" + } + ] + }, + "keywords": { + "patterns": [ + { + "name": "keyword.control.nub", + "match": "\\b(if|else|while|for|break|continue|return)\\b" + }, + { + "name": "keyword.other.nub", + "match": "\\b(import|func|struct|new)\\b" + } + ] + }, + "modifiers": { + "patterns": [ + { + "name": "storage.modifier.nub", + "match": "\\b(global|extern)\\b" + } + ] + }, + "types": { + "patterns": [ + { + "name": "storage.type.primitive.nub", + "match": "\\b(int|float|double|char|bool|string|void)\\b" + }, + { + "name": "storage.type.array.nub", + "match": "\\[\\]" + }, + { + "name": "storage.type.pointer.nub", + "match": "\\^" + } + ] + }, + "strings": { + "patterns": [ + { + "name": "string.quoted.double.nub", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.nub", + "match": "\\\\(n|t|r|\\\\|\"|')" + }, + { + "name": "constant.character.escape.nub", + "match": "\\\\[0-7]{1,3}" + }, + { + "name": "constant.character.escape.nub", + "match": "\\\\x[0-9A-Fa-f]{1,2}" + } + ] + }, + { + "name": "string.quoted.single.nub", + "begin": "'", + "end": "'", + "patterns": [ + { + "name": "constant.character.escape.nub", + "match": "\\\\(n|t|r|\\\\|\"|')" + } + ] + } + ] + }, + "numbers": { + "patterns": [ + { + "name": "constant.numeric.float.nub", + "match": "\\b\\d+\\.\\d*([eE][+-]?\\d+)?[fF]?\\b" + }, + { + "name": "constant.numeric.integer.decimal.nub", + "match": "\\b\\d+\\b" + }, + { + "name": "constant.numeric.integer.hexadecimal.nub", + "match": "\\b0[xX][0-9A-Fa-f]+\\b" + }, + { + "name": "constant.numeric.integer.binary.nub", + "match": "\\b0[bB][01]+\\b" + } + ] + }, + "operators": { + "patterns": [ + { + "name": "keyword.operator.assignment.nub", + "match": "=" + }, + { + "name": "keyword.operator.comparison.nub", + "match": "(==|!=|<=|>=|<|>)" + }, + { + "name": "keyword.operator.arithmetic.nub", + "match": "(\\+|\\-|\\*|/)" + }, + { + "name": "keyword.operator.logical.nub", + "match": "(&&|\\|\\||!)" + }, + { + "name": "keyword.operator.address.nub", + "match": "&" + }, + { + "name": "keyword.operator.dereference.nub", + "match": "\\^" + }, + { + "name": "keyword.operator.member-access.nub", + "match": "\\." + } + ] + }, + "function-definition": { + "patterns": [ + { + "begin": "\\b(global\\s+|extern\\s+)?(func)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\(", + "beginCaptures": { + "1": { + "name": "storage.modifier.nub" + }, + "2": { + "name": "keyword.other.nub" + }, + "3": { + "name": "entity.name.function.nub" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "#function-parameters" + } + ] + } + ] + }, + "struct-definition": { + "patterns": [ + { + "match": "\\b(struct)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "captures": { + "1": { + "name": "keyword.other.nub" + }, + "2": { + "name": "entity.name.type.struct.nub" + } + } + } + ] + }, + "function-parameters": { + "patterns": [ + { + "match": "\\.\\.\\.", + "name": "keyword.operator.variadic.nub" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*:\\s*", + "captures": { + "1": { + "name": "variable.parameter.nub" + } + } + }, + { + "include": "#types" + }, + { + "include": "#identifiers" + } + ] + }, + "function-call": { + "patterns": [ + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=\\()", + "captures": { + "1": { + "name": "entity.name.function.call.nub" + } + } + } + ] + }, + "identifiers": { + "patterns": [ + { + "name": "variable.other.nub", + "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b" + } + ] + } + } +}