Skip to content

Commit 91fdad2

Browse files
Add VS Code extension (minimal)
1 parent 730b3ee commit 91fdad2

File tree

6 files changed

+206
-1
lines changed

6 files changed

+206
-1
lines changed

spec.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ which match the reference lexer implementation:
109109
- Uppercase letters 'A'–'Z'
110110
- Decimal digits '0'–'9'
111111
- The punctuation and symbol characters
112-
'; . / ! @ $ % & ~ _ + | < > ?'
112+
'; / ! @ $ % & ~ _ + | < > ?'
113113

114114
As noted above, non-ASCII characters remain disallowed, and the
115115
delimiter characters '{', '}', '[', ']', '(', ')', '=', ',', and '#'

vscode/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ASM-Lang VS Code extension (local)
2+
3+
This extension provides minimal language support and run commands for ASM-Lang (ASMLN) bundled with this repository.
4+
5+
Features:
6+
- Registers the `asmln` language and associates `.asmln` files.
7+
- Basic syntax highlighting for comments, strings, binary integer literals, keywords and builtins.
8+
- Two commands:
9+
- `ASM-Lang: Run File` — runs the current file using the workspace `asmln.py` in an integrated terminal.
10+
- `ASM-Lang: Start REPL` — starts the REPL by launching the interpreter with no file.
11+
12+
Configuration:
13+
- `asmln.pythonPath` — path to the Python interpreter executable (default: `python`).
14+
15+
Usage:
16+
1. Open the workspace root (this repository) in VS Code.
17+
2. Open an `.asmln` file.
18+
3. Run the command palette (Ctrl+Shift+P) and pick `ASM-Lang: Run File` or `ASM-Lang: Start REPL`.
19+
20+
Notes:
21+
- The extension expects `asmln.py` to live in the workspace root. If your workspace layout differs, update the command or set a full path in `asmln.pythonPath`.

vscode/extension.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const vscode = require('vscode');
2+
const path = require('path');
3+
4+
function getWorkspaceRoot() {
5+
const ws = vscode.workspace.workspaceFolders;
6+
if (!ws || ws.length === 0) return undefined;
7+
return ws[0].uri.fsPath;
8+
}
9+
10+
function resolveInterpreterPath() {
11+
const config = vscode.workspace.getConfiguration();
12+
const py = config.get('asmln.pythonPath');
13+
return py || 'python';
14+
}
15+
16+
function ensureSaved(editor) {
17+
if (!editor) return Promise.resolve(true);
18+
if (!editor.document.isDirty) return Promise.resolve(true);
19+
return editor.document.save();
20+
}
21+
22+
function runCommandInTerminal(command, cwd) {
23+
const term = vscode.window.createTerminal({ cwd: cwd });
24+
term.show(true);
25+
term.sendText(command);
26+
}
27+
28+
function runFile() {
29+
const editor = vscode.window.activeTextEditor;
30+
if (!editor) {
31+
vscode.window.showInformationMessage('No active editor to run');
32+
return;
33+
}
34+
ensureSaved(editor).then((ok) => {
35+
if (!ok) return;
36+
const filePath = editor.document.uri.fsPath;
37+
const root = getWorkspaceRoot() || path.dirname(filePath);
38+
const interp = resolveInterpreterPath();
39+
const asmlnPath = path.join(root, 'asmln.py');
40+
const cmd = `${interp} "${asmlnPath}" "${filePath}"`;
41+
runCommandInTerminal(cmd, root);
42+
});
43+
}
44+
45+
function runRepl() {
46+
const root = getWorkspaceRoot() || process.cwd();
47+
const interp = resolveInterpreterPath();
48+
const asmlnPath = path.join(root, 'asmln.py');
49+
const cmd = `${interp} "${asmlnPath}"`;
50+
runCommandInTerminal(cmd, root);
51+
}
52+
53+
/** @param {vscode.ExtensionContext} context */
54+
function activate(context) {
55+
context.subscriptions.push(
56+
vscode.commands.registerCommand('asmln.runFile', runFile),
57+
vscode.commands.registerCommand('asmln.runRepl', runRepl)
58+
);
59+
}
60+
61+
function deactivate() {}
62+
63+
module.exports = { activate, deactivate };

vscode/language-configuration.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"comments": {
3+
"lineComment": "#"
4+
},
5+
"brackets": [
6+
["[", "]"],
7+
["{", "}"],
8+
["(", ")"]
9+
],
10+
"autoClosingPairs": [
11+
{ "open": "\"", "close": "\"", "notIn": ["string"] },
12+
{ "open": "(", "close": ")" },
13+
{ "open": "[", "close": "]" },
14+
{ "open": "{", "close": "}" }
15+
],
16+
"surroundingPairs": [
17+
{ "open": "\"", "close": "\"" },
18+
{ "open": "(", "close": ")" },
19+
{ "open": "[", "close": "]" },
20+
{ "open": "{", "close": "}" }
21+
],
22+
"wordPattern": "[a-zA-Z_/.!@$%&~+|<>?\\\\-]+|[01]+",
23+
"folding": {
24+
"markers": {
25+
"start": "^\\s*\\[",
26+
"end": "^\\s*\\]"
27+
}
28+
}
29+
}

vscode/package.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "asmln-language",
3+
"displayName": "ASM-Lang",
4+
"description": "Language support and helper commands for ASM-Lang (ASMLN)",
5+
"version": "0.1.0",
6+
"publisher": "python-processing-unit",
7+
"engines": {
8+
"vscode": "^1.60.0"
9+
},
10+
"categories": [
11+
"Programming Languages"
12+
],
13+
"activationEvents": [
14+
"onCommand:asmln.runFile",
15+
"onCommand:asmln.runRepl",
16+
"onLanguage:asmln"
17+
],
18+
"main": "extension.js",
19+
"contributes": {
20+
"commands": [
21+
{
22+
"command": "asmln.runFile",
23+
"title": "ASM-Lang: Run File"
24+
},
25+
{
26+
"command": "asmln.runRepl",
27+
"title": "ASM-Lang: Start REPL"
28+
}
29+
],
30+
"languages": [
31+
{
32+
"id": "asmln",
33+
"aliases": ["ASM-Lang", "asmln"],
34+
"extensions": [".asmln"],
35+
"configuration": "language-configuration.json"
36+
}
37+
],
38+
"grammars": [
39+
{
40+
"language": "asmln",
41+
"scopeName": "source.asmln",
42+
"path": "syntaxes/asmln.tmLanguage.json"
43+
}
44+
],
45+
"configuration": {
46+
"type": "object",
47+
"title": "ASM-Lang",
48+
"properties": {
49+
"asmln.pythonPath": {
50+
"type": "string",
51+
"default": "python",
52+
"description": "Path to Python executable used to run the bundled interpreter. Can be 'python' or full path to interpreter."
53+
}
54+
}
55+
}
56+
}
57+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"scopeName": "source.asmln",
3+
"name": "ASM-Lang",
4+
"patterns": [
5+
{
6+
"name": "comment.line.number-sign.asmln",
7+
"match": "#.*$"
8+
},
9+
{
10+
"name": "string.quoted.double.asmln",
11+
"begin": "\"",
12+
"end": "\"",
13+
"patterns": [
14+
{ "match": "[^\\\"]+", "name": "string.content.asmln" }
15+
]
16+
},
17+
{
18+
"name": "constant.numeric.binary.asmln",
19+
"match": "-?[01]+\b"
20+
},
21+
{
22+
"name": "keyword.control.asmln",
23+
"match": "\b(IF|ELSIF|ELSE|WHILE|FOR|FUNC|RETURN|BREAK|CONTINUE|GOTO|GOTOPOINT)\b"
24+
},
25+
{
26+
"name": "support.function.builtin.asmln",
27+
"match": "\b(INPUT|PRINT|IMPORT|READFILE|WRITEFILE|EXISTFILE|EXIT|INT|STR|LEN|SLEN|ILEN|JOIN|AND|OR|XOR|NOT|EQ|MAX|MIN|SUM|PROD|UPPER|LOWER|ASSERT|CL|MAIN)\b"
28+
},
29+
{
30+
"name": "variable.other.asmln",
31+
"match": "[a-zA-Z_/.!@$%&~+|<>?][a-zA-Z0-9_/.!@$%&~+|<>?]*"
32+
}
33+
],
34+
"repository": {}
35+
}

0 commit comments

Comments
 (0)