Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ version = $(strip $(shell grep version package.json | tr -s ' ' | cut -d' ' -f3

build: out/extension/main.js

out/extension/main.js: $(src) $(bin) $(grammar) package.json
out/extension/main.js: $(src) $(bin) $(grammar) package.json fix-syntax.cjs
npm install
npm run langium:generate
npm run fix-syntax
npm run build

update_submodules:
Expand Down
81 changes: 81 additions & 0 deletions fix-syntax.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
console.log("Fixing syntax hihglighting...")

const fs = require('fs');
const path = require('path');

const jsonpath = path.join(__dirname, "syntaxes", "r-check.tmLanguage.json");

fs.readFile(jsonpath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
const jsonData = JSON.parse(data);
let oldPatterns = [];
jsonData.patterns.forEach(element => {
const match = (element.match ?? "")
.split("|")
.map(s => s.trim()
.replace(/\\b/g, "").replace(/\\B/g, "")
.replace("(", "").replace(")", ""))
.filter(s => s.length > 0);
oldPatterns.push(...match);
});
// const oldPatterns = jsonData.patterns;
console.log("Old patterns:", oldPatterns);


jsonData.patterns = [
{
include: "#comments"
},
{
name: "keyword.control.r-check",
match: "\\b(SPEC|enum|channels|property-variables|exists|false|forall|guard|init|local|message-structure|receive-guard|relabel|rep|repeat|system)\\b|\\B(-automaton-state)\\b|\\b(GET@|SUPPLY@)\\B"
},
{
match: "\\b(agent)\\b\\s+([^\\s]+)",
captures: {
1: { name: "keyword.other.agent.r-check" },
2: { name: "entity.name.agent.r-check" }
}
},
{
name: "keyword.operator.r-check",
match: "\\b(F|G|R|U|W|X|exists|forall)\\b"
},
{
name: "constant.language.r-check",
match: "\\b(false|true|any)\\b"
},
{
name: "constant.numeric.r-check",
match: "\\b([0-9]+)\\b"
},
{
name: "variable.language.r-check",
match: "\\b(myself|chan|sender|getter|supplier|p2p)\\b"
},
{
name: "storage.type.r-check",
match: "\\b(bool|channel|int|Agent|location)\\b"
}
];

// Careful, this can still have false positives
oldPatterns.forEach(pattern => {
if (!jsonData.patterns.some(p => p.match !== undefined && p.match.includes(pattern))) {
console.warn(`Pattern "${pattern}" is missing in the new patterns.`);
}
});


fs.writeFile(jsonpath, JSON.stringify(jsonData, null, 2), 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('Syntax file updated successfully');
});
});

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"bundle:serve": "http-server ./dist --port 5175",
"dev": "vite",
"dev:debug": "vite --debug --force",
"fix-syntax": "node fix-syntax.cjs",
"serve": "npm run dev",
"test": "vitest run"
},
Expand Down