diff --git a/wacc-compiler b/wacc-compiler new file mode 100755 index 0000000..a23eea8 Binary files /dev/null and b/wacc-compiler differ diff --git a/wacc-syntax/.vscodeignore b/wacc-syntax/.vscodeignore new file mode 100644 index 0000000..f369b5e --- /dev/null +++ b/wacc-syntax/.vscodeignore @@ -0,0 +1,4 @@ +.vscode/** +.vscode-test/** +.gitignore +vsc-extension-quickstart.md diff --git a/wacc-syntax/CHANGELOG.md b/wacc-syntax/CHANGELOG.md new file mode 100644 index 0000000..67bbfbe --- /dev/null +++ b/wacc-syntax/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/wacc-syntax/README.md b/wacc-syntax/README.md new file mode 100644 index 0000000..dc45cd0 --- /dev/null +++ b/wacc-syntax/README.md @@ -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 \ No newline at end of file diff --git a/wacc-syntax/README.pdf b/wacc-syntax/README.pdf new file mode 100644 index 0000000..4a9d852 Binary files /dev/null and b/wacc-syntax/README.pdf differ diff --git a/wacc-syntax/extension.js b/wacc-syntax/extension.js new file mode 100644 index 0000000..0c3f3ec --- /dev/null +++ b/wacc-syntax/extension.js @@ -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 +}; diff --git a/wacc-syntax/language-configuration.json b/wacc-syntax/language-configuration.json new file mode 100644 index 0000000..7c24c88 --- /dev/null +++ b/wacc-syntax/language-configuration.json @@ -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": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ] +} \ No newline at end of file diff --git a/wacc-syntax/package-lock.json b/wacc-syntax/package-lock.json new file mode 100644 index 0000000..714af4d --- /dev/null +++ b/wacc-syntax/package-lock.json @@ -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" + } + } + } +} diff --git a/wacc-syntax/package.json b/wacc-syntax/package.json new file mode 100644 index 0000000..debe1de --- /dev/null +++ b/wacc-syntax/package.json @@ -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" +} diff --git a/wacc-syntax/syntaxes/wacc.tmLanguage.json b/wacc-syntax/syntaxes/wacc.tmLanguage.json new file mode 100644 index 0000000..6093503 --- /dev/null +++ b/wacc-syntax/syntaxes/wacc.tmLanguage.json @@ -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" + } + + ] + +} \ No newline at end of file diff --git a/wacc-syntax/vsc-extension-quickstart.md b/wacc-syntax/vsc-extension-quickstart.md new file mode 100644 index 0000000..9d2ddf4 --- /dev/null +++ b/wacc-syntax/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/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 `/.vscode/extensions` folder and restart Code. +* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension. diff --git a/wacc-syntax/wacc-syntax-0.0.1.vsix b/wacc-syntax/wacc-syntax-0.0.1.vsix new file mode 100644 index 0000000..0889722 Binary files /dev/null and b/wacc-syntax/wacc-syntax-0.0.1.vsix differ