intelliwacc ide

Merge request lab2425_spring/WACC_37!43

Co-authored-by: Guy C <gc1523@ic.ac.uk>
This commit is contained in:
Connolly, Guy
2025-03-14 13:22:52 +00:00
12 changed files with 257 additions and 0 deletions

BIN
wacc-compiler Executable file

Binary file not shown.

View File

@@ -0,0 +1,4 @@
.vscode/**
.vscode-test/**
.gitignore
vsc-extension-quickstart.md

9
wacc-syntax/CHANGELOG.md Normal file
View File

@@ -0,0 +1,9 @@
# Change Log
All notable changes to the "wacc-syntax" 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

7
wacc-syntax/README.md Normal file
View File

@@ -0,0 +1,7 @@
### INTELLIWACC
This is the IntelliWACC extension for WACC code development; featuring syntax highlighting, error messages/highlighting and imports.
This extension was developed as a part of the "WACC Extensions" milestone 2025.
Authored by Alex L, Gleb K, Guy C and Jonny T

BIN
wacc-syntax/README.pdf Normal file

Binary file not shown.

71
wacc-syntax/extension.js Normal file
View File

@@ -0,0 +1,71 @@
// Developed using the VSC language extension tutorial
// https://code.visualstudio.com/api/language-extensions/overview
const vscode = require('vscode');
const { execSync } = require('child_process');
const { parse } = require('path');
function activate(context) {
console.log('IntelliWACC is now active!');
let diagnosticCollection = vscode.languages.createDiagnosticCollection('wacc');
context.subscriptions.push(diagnosticCollection);
vscode.workspace.onDidSaveTextDocument((document) => {
if (document.languageId !== 'wacc') return;
let diagnostics = [];
let errors = generateErrors(document.getText(), document.fileName);
errors.forEach(error => {
console.log(error);
let range = new vscode.Range(error.line - 1 , error.column - 1, error.line - 1, error.column + error.size);
let diagnostic = new vscode.Diagnostic(range, error.errorMessage, vscode.DiagnosticSeverity.Error);
diagnostics.push(diagnostic);
});
diagnosticCollection.set(document.uri, diagnostics);
});
}
function deactivate() {
console.log('IntelliWACC is deactivating...');
}
function generateErrors(code, filePath) {
try {
console.log("generating errors")
const fs = require('fs');
const tmpFilePath = parse(filePath).dir + '/.temp_wacc_file.wacc';
fs.writeFileSync(tmpFilePath, code);
let output;
try {
const waccExePath = `${__dirname}/../wacc-compiler`;
output = execSync(`${waccExePath} ${tmpFilePath}`, { encoding: 'utf8', stdio: 'pipe' });
} catch (err) {
console.log("Error running compiler");
output = err.stdout;
console.log(output);
}
let errors = [];
errorRegex = /\(line ([\d]+), column ([\d]+)\):\n([^>]+)([^\^]+)([\^]+)\n([^\n]+)([^\(]*)/g
while((match = errorRegex.exec(output)) !== null) {
console.log(match[5]);
errors.push({
line: parseInt(match[1], 10),
column: parseInt(match[2], 10),
errorMessage: match[3].trim(),
size: match[5].length - 1
});
}
return errors;
} catch (err) {
console.error('Error running compiler:', err);
return [];
}
}
module.exports = {
activate,
deactivate
};

View File

@@ -0,0 +1,28 @@
{
"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": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}

15
wacc-syntax/package-lock.json generated Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "wacc-syntax",
"version": "0.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wacc-syntax",
"version": "0.0.1",
"engines": {
"vscode": "^1.97.0"
}
}
}
}

38
wacc-syntax/package.json Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "wacc-syntax",
"displayName": "intelliWACC",
"description": "WACC language support features",
"version": "0.0.1",
"engines": {
"vscode": "^1.97.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "wacc",
"aliases": ["WACC", "wacc"],
"extensions": [".wacc"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "wacc",
"scopeName": "source.wacc",
"path": "./syntaxes/wacc.tmLanguage.json"
}],
"properties": {
"files.exclude": {
"type": "object",
"default": {
"**/.temp_wacc_file.*": true
},
"description": "Configure patterns for excluding files and folders."
}
}
},
"scripts": {
"build": "vsce package"
},
"main": "./extension.js"
}

View File

@@ -0,0 +1,56 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "WACC",
"scopeName": "source.wacc",
"fileTypes": [
"wacc"
],
"patterns": [
{
"match": "\\b(true|false)\\b",
"name": "keyword.constant.wacc"
},
{
"match": "\\b(int|bool|char|string|pair|null)\\b",
"name": "storage.type.wacc"
},
{
"match": "\".*?\"",
"name": "string.quoted.double.mylang"
},
{
"match": "\\b(begin|end)\\b",
"name": "keyword.other.unit"
},
{
"match": "\\b(if|then|else|fi|while|do|done|skip|is)\\b",
"name": "keyword.control.wacc"
},
{
"match": "\\b(read|free|print|println|newpair|call|fst|snd|ord|chr|len)\\b",
"name": "keyword.operator.function.wacc"
},
{
"match": "\\b(return|exit)\\b",
"name": "keyword.operator.wacc"
},
{
"match": "'[^']{1}'",
"name": "constant.character.wacc"
},
{
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=\\()",
"name": "variable.function.wacc"
},
{
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"name": "variable.other.wacc"
},
{
"match": "#.*$",
"name": "comment.line"
}
]
}

View File

@@ -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/wacc.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 `<user home>/.vscode/extensions` folder and restart Code.
* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension.

Binary file not shown.