From f16b121c8dc1d0c6a629044c09d886cfe92db507 Mon Sep 17 00:00:00 2001 From: Elyan Date: Fri, 8 Nov 2024 23:11:29 +0100 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 2 + .vscode/launch.json | 17 +++ .vscodeignore | 4 + README.md | 3 + examples/hello.s | 70 +++++++++ language-configuration.json | 67 +++++++++ package.json | 49 +++++++ syntaxes/central-asm.tmLanguage.json | 212 +++++++++++++++++++++++++++ 9 files changed, 426 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscodeignore create mode 100644 README.md create mode 100644 examples/hello.s create mode 100644 language-configuration.json create mode 100644 package.json create mode 100644 syntaxes/central-asm.tmLanguage.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..70e63ff --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Set default behavior to automatically normalize line endings. +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67dfeb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*.vsix \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..44a86ab --- /dev/null +++ b/.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}" + ] + } + ] +} diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..f369b5e --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,4 @@ +.vscode/** +.vscode-test/** +.gitignore +vsc-extension-quickstart.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8446905 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# VSCode Central(ASM) + +This extension provides basic syntax highlighting for the Central(ASM) language. diff --git a/examples/hello.s b/examples/hello.s new file mode 100644 index 0000000..89bdc9d --- /dev/null +++ b/examples/hello.s @@ -0,0 +1,70 @@ +@@ text.start +.g hello + //Set HELLO variable to 1234 +%% set var="HELLO", +%- to=1234, +%% set var="RC_SUCCESS",to=0 + mov r1, %(HELLO) + ldr.eq r0, [r1] + nop +.l world + //Include other file +%% include member="myfile" + //Use the alloc macro +%* alloc size=r0, align=0x1000, +%- out=r1, + svc 0x7b + + adr r2, .my_fd.def +%* nextrec "OK",fd=r2, +%- out=.my_fd.out.data +%* endprocess rc=%(RC_SUCCESS) + +@@ rodata +.l value + //Defaults to dd(2) +dd 0x1234 +dd 0x01'1, 0x02'1, 0xFFEE'2 +.l value.other +dd "Hello, world!\0" + + //File descriptor +@@ data +.l my_fd.def +%* filedesc ddname="HELLO",recfm="FB",lrecl=200 + +@@ bss +.l my_fd.out + //Array of 4 integers +ds int(4) + //Named array of characters with last label prepended. 200 bytes in length. +.. data +ds char(200) + +/////////////////////////////////////////////////////////////////////////////// +%% macro name="nextrec" +%% param name="ok",type="(OK,KO)" +%% kwparam name="fd",type="label|reg" +%% kwparam name="out",type="label|reg" + +%% if val="ok",neq="OK" +%% abort msg="Error: param 'ok' of macro 'nextrec' must be OK" +%% endif + + //Handle fd +%% if type="fd",is="label" + add r0, pc, %(fd) +%% elif val="fd",neq=r0 + mov r0, %(fd) +%% endif + + //Handle out +%% if type="out",is="label" + add r1, pc, %(out) +%% elif val="fd",neq=r0 + mov r1, %(out) +%% endif + //Call the privileged service + svc 0x10 +%% endmacro +/////////////////////////////////////////////////////////////////////////////// diff --git a/language-configuration.json b/language-configuration.json new file mode 100644 index 0000000..164d35d --- /dev/null +++ b/language-configuration.json @@ -0,0 +1,67 @@ +{ + "comments": { + // symbol used for single line comment. Remove this entry if your language does not support line comments + "lineComment": "//" + }, + // 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/package.json b/package.json new file mode 100644 index 0000000..febb523 --- /dev/null +++ b/package.json @@ -0,0 +1,49 @@ +{ + "name": "central-asm", + "displayName": "Central(ASM)", + "description": "Syntax highlighting for Central(ASM)", + "version": "1.0.0", + "engines": { + "vscode": "^1.95.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [ + { + "id": "central-asm", + "aliases": [ + "Central(ASM)", + "central-asm" + ], + "extensions": [ + ".s", + ".S", + ".m", + ".M" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "central-asm", + "scopeName": "source.central-asm", + "path": "./syntaxes/central-asm.tmLanguage.json" + } + ], + "configurationDefaults": { + "[central-asm]": { + "editor.guides.indentation": false, + "editor.detectIndentation": false, + "editor.insertSpaces": true, + "editor.rulers": [ + 2, + 4, + 120 + ] + } + } + } +} \ No newline at end of file diff --git a/syntaxes/central-asm.tmLanguage.json b/syntaxes/central-asm.tmLanguage.json new file mode 100644 index 0000000..1466d47 --- /dev/null +++ b/syntaxes/central-asm.tmLanguage.json @@ -0,0 +1,212 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "Central(ASM)", + "patterns": [ + { + "include": "#strings" + }, + { + "include": "#comments" + }, + { + "include": "#sections" + }, + { + "include": "#labels" + }, + { + "include": "#numerics" + }, + { + "include": "#registers" + }, + { + "include": "#preprocessor-lines" + }, + { + "include": "#preprocessor-variables" + }, + { + "include": "#assembly" + } + ], + "repository": { + "strings": { + "name": "string.quoted.double.central-asm", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.central-asm", + "match": "\\\\." + } + ] + }, + "comments": { + "name": "comment.line.double-slash", + "match": "^.{2}//.*$" + }, + "sections": { + "patterns": [ + { + "name": "storage.section.named.central-asm", + "match": "^@{2}\\s{2,}[a-zA-Z][a-zA-Z0-9]*(\\.[a-zA-Z][a-zA-Z0-9]*)+\\s*$" + }, + { + "name": "storage.section.auto-named.central-asm", + "match": "^@{2}\\s{2,}([a-zA-Z][a-zA-Z0-9]*)\\s*$", + "captures": { + "1": { + "name": "emphasis" + } + } + } + ] + }, + "labels": { + "patterns": [ + { + "name": "entity.name.function.label.local.central-asm", + "match": "^\\.l\\s{2,}([a-zA-Z_][a-zA-Z_0-9]*(\\.[a-zA-Z_][a-zA-Z_0-9]*)*)\\s*$", + "captures": { + "1": { + "name": "emphasis" + } + } + }, + { + "name": "entity.name.function.label.local.prepend-last.central-asm", + "match": "^\\.{2}\\s{2,}([a-zA-Z_][a-zA-Z_0-9]*(\\.[a-zA-Z_][a-zA-Z_0-9]*)*)\\s*$", + "captures": { + "1": { + "name": "emphasis" + } + } + }, + { + "name": "entity.name.function.label.global.central-asm", + "match": "^\\.g\\s{2,}([a-zA-Z_][a-zA-Z_0-9]*(\\.[a-zA-Z_][a-zA-Z_0-9]*)*)\\s*$", + "captures": { + "1": { + "name": "strong" + } + } + }, + { + "name": "entity.name.function.label.ref.relative.central-asm", + "match": "\\.[a-zA-Z_][a-zA-Z_0-9]*(\\.[a-zA-Z_][a-zA-Z_0-9]*)*" + }, + { + "name": "entity.name.function.label.ref.absolute.central-asm", + "match": "&[a-zA-Z_][a-zA-Z_0-9]*(\\.[a-zA-Z_][a-zA-Z_0-9]*)*" + } + ] + }, + "numerics": { + "match": "((0x[0-9a-fA-F]+(_[0-9a-fA-F]+)*)|([0-9]+(_[0-9]+)*))('[0-9]+)?", + "captures": { + "1": { + "name": "constant.numeric.central-asm" + }, + "6": { + "name": "storage.modifier.width.central-asm" + } + } + }, + "registers": { + "patterns": [ + { + "name": "variable.other.central-asm", + "match": "\\b((r[0-9]+)|lr|pc|sp|pc_user|sp_user|pc_svc|sp_svc|pc_fault|sp_fault)\\b" + }, + { + "name": "variable.other.central-asm", + "match": "(ss[0-9]+)|(sr[0-9]+)" + } + ] + }, + "preprocessor-lines": { + "patterns": [ + { + "name": "meta.preprocessor.line.central-asm", + "patterns": [ + { + "name": "meta.preprocessor.directive.central-asm", + "match": "^%%\\s{2,}([a-zA-Z_][a-zA-Z_0-9]*)", + "captures": { + "1": { + "name": "emphasis" + } + } + }, + { + "name": "meta.preprocessor.macro-call.central-asm", + "match": "^%\\*\\s{2,}([a-zA-Z_][a-zA-Z_0-9]*)", + "captures": { + "1": { + "name": "strong" + } + } + }, + { + "name": "meta.preprocessor.continuation.central-asm", + "match": "^%-" + }, + { + "include": "#preprocessor-key-value-args" + } + ] + } + ] + }, + "preprocessor-key-value-args": { + "name": "meta.preprocessor.arg-key.central-asm", + "match": "\\b([a-zA-Z_][a-zA-Z_0-9]*)=", + "captures": { + "1": { + "name": "variable.parameter.central-asm" + } + } + }, + "preprocessor-variables": { + "name": "meta.preprocessor.variable-substitution.central-asm", + "match": "%\\(([a-zA-Z_][a-zA-Z_0-9]*)\\)", + "captures": { + "1": { + "name": "variable.name.central-asm" + } + } + }, + "assembly": { + "patterns": [ + { + "match": "^\\s{4,}(nop|svc|ldr|str|add|adr|mov|movn|b|bx|ssr|ssw)(\\.(al|eq|neq|uge|cs|ult|cc|neg|pos|vs|vc|ugt|ule|sge|slt|sgt|sle))?\\b", + "captures": { + "1": { + "name": "keyword.control.instructions.central-asm" + }, + "2": { + "name": "keyword.other.conditions.central-asm" + } + } + }, + { + "name": "keyword.other.data-definition.central-asm", + "match": "^dd\\s{2,}" + }, + { + "match": "^(ds)\\s{2,}(int|short|char|ptr)", + "captures": { + "1": { + "name": "keyword.other.data-space.central-asm" + }, + "2": { + "name": "entity.name.type.data-space.central-asm" + } + } + } + ] + } + }, + "scopeName": "source.central-asm" +} \ No newline at end of file