Skip to content

Commit

Permalink
Tweak syntax highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
okaxaki committed Nov 25, 2023
1 parent a26e20a commit 7e2e068
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 63 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msxplay-js",
"version": "1.7.0",
"version": "1.7.1",
"description": "",
"type": "module",
"engines": {
Expand Down
146 changes: 86 additions & 60 deletions public/js/ace-defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const commonMMLRules = [
{
token: "mml.loop",
regex: /(\[[0-9]?|\||\][0-9]?)/,
regex: /(\[[0-9]*|\||\][0-9]*)/,
},
{
token: "mml.jump",
Expand All @@ -15,7 +15,6 @@
{
token: "mml.macro",
regex: /\*[a-z]?[0-9]*/,
caseInsensitive: true,
},
{
token: "mml.rel-volume",
Expand All @@ -24,12 +23,10 @@
{
token: "mml.command",
regex: /([tqlv]|@[lmof])\s*[0-9]+/,
caseInsensitive: true,
},
{
token: "mml.command",
regex: /(y)(s*[0-9]+)(\s*,\s*[0-9]+)/,
caseInsensitive: true,
},
{
token: "mml.ignore",
Expand All @@ -45,6 +42,10 @@
regex: /$/,
next: "root",
},
{
defaultToken: "text",
caseInsensitive: true,
},
];

function createCommonStates() {
Expand All @@ -54,52 +55,58 @@
token: "comment",
regex: /;.*$/,
},
{
token: "directive",
regex: /(^\s*)(#end)(\s*)/,
next: "ignored",
},
{
token: "directive",
regex: /(^\s*)(#[a-z_]+)(\s*)/,
caseInsensitive: true,
push: "directive_param",
},
{
token: "voice_def",
regex: /^(\s*)(@[ersv]?[0-9]+)(\s*)(=)(\s*)/,
caseInsensitive: true,
},
{
token: "macro_def",
regex: /^(\s*)(\*[a-z]?[0-9]*)(\s*)(=)(\s*)/,
caseInsensitive: true,
},
{ token: "string", start: '"', end: '"' },
{
token: "paren.lparen",
regex: "{",
next: "block",
},
],
block: [
{
token: "comment",
regex: /;.*$/,
},
{
token: "paren.rparen",
regex: "}",
next: "root",
push: "block",
},
{
defaultToken: "block_body",
defaultToken: "text",
caseInsensitive: true,
},
],
directive_param: [
{ token: "comment", regex: /;.*$/ },
{ token: "paren.lparen", regex: "{", push: "block" },
{ token: "constant.string", start: '"', end: '"' },
{ token: "constant.numeric", regex: /[0-9]+/ },
{ regex: "$", next: "pop" },
{ defaultToken: "block.body" },
],
block: [
{ token: "comment", regex: /;.*$/ },
{ token: "constant.string", start: '"', end: '"' },
{ token: "paren.rparen", regex: "}", next: "pop" },
{ defaultToken: "block.body" },
],
mml: [
...commonMMLRules,
{
token: "mml.note",
regex: /[a-gr](\+|\-)?(%?[0-9]+)?(\^%?[0-9]+)*/,
caseInsensitive: true,
},
{
token: "mml.voice",
regex: /@[ers]?[0-9]+/,
caseInsensitive: true,
},
{
token: "mml.rel-octave",
Expand All @@ -112,12 +119,10 @@
{
token: "mml.command",
regex: /(\\|@\\|@p)(\s*[+\-]\s*)?[0-9]+/,
caseInsensitive: true,
},
{
token: "mml.command",
regex: /v(\s*[+\-]\s*)?[0-9]+/,
caseInsensitive: true,
},
{
token: "mml.command",
Expand All @@ -143,12 +148,10 @@
{
token: "mml.note",
regex: /[bshcm]+(:|%?[0-9]+)?(\^:|\^%?[0-9]+)*/,
caseInsensitive: true,
},
{
token: "mml.command",
regex: /v[bshcm](\s*[+\-]\s*)?[0-9]+/,
caseInsensitive: true,
},
{
token: "mml.command",
Expand All @@ -163,16 +166,24 @@
}

function addStatePrefix(states, prefix) {
const _p = (s) => {
if (typeof s == "string" && s != "pop") {
return `${prefix}$${s}`;
}
return s;
};
const res = {};
for (const key in states) {
const rules = states[key];
const newRules = [];
for (const rule of rules) {
newRules.push({
...rule,
next: rule.next != null ? `${prefix}$${rule.next}` : undefined,
push: _p(rule.push),
next: _p(rule.next),
});
}
console.log(`${prefix}$${key}`);
res[`${prefix}$${key}`] = newRules;
}
return res;
Expand Down Expand Up @@ -205,37 +216,42 @@
return addStatePrefix(states, "mode1");
}

const startRules = [
{ token: "comment", regex: /;.*$/ },
{
token: ["text", "directive", "text"],
regex: /^(\s*)(#opll_mode)(\s+)/,
next: "mode_param",
},
{ defaultToken: "comment", caseInsensitive: true },
];

this.$rules = {
start: [
{
token: "comment",
regex: /;.*$/,
},
{
token: ["space", "directive", "space"],
regex: /^(\s*)(#opll_mode)(\s+)/,
caseInsensitive: true,
next: "mode_param",
},
{
defaultToken: "comment",
},
],
start: [{ token: "comment.meta", regex: /;\[.+\]/, next: "start1" }, ...startRules],
start1: startRules,
mode_param: [
{
token: "block",
token: "constant.numeric",
regex: "0",
next: "mode0$root",
},
{
token: "block",
token: "constant.numeric",
regex: "1",
next: "mode1$root",
},
{
token: "text",
regex: /.*/,
next: "ignored",
},
],
ignored: [{ defaultToken: "comment" }],
...createMode0States(),
...createMode1States(),
};
this.normalizeRules();
console.log(this.$rules);
};
oop.inherits(MGSCHighlightRules, TextHighlightRules);
exports.MGSCHighlightRules = MGSCHighlightRules;
Expand Down Expand Up @@ -278,20 +294,29 @@
.ace_mgsc .ace_comment {
color: #888;
}
.ace_mgsc .ace_comment.ace_meta {
color: #333;
}
.ace_mgsc .ace_directive {
color: #606;
}
.ace_mgsc .ace_constant {
color: #448;
}
.ace_mgsc .ace_variable {
color: #448;
}
.ace_mgsc .ace_voice_def {
color: #606;
}
.ace_mgsc .ace_block_body {
color: #643;
.ace_mgsc .ace_block {
color: #448;
}
.ace_mgsc .ace_macro_def {
color: #606;
}
.ace_mgsc .ace_paren {
color: #999;
color: #643;
}
.ace_mgsc .ace_channel {
color: #06c;
Expand All @@ -309,7 +334,7 @@
color: #606;
}
.ace_mgsc .ace_mml.ace_command {
color: #084;
color: #086;
}
.ace_mgsc .ace_mml.ace_voice {
color: #808;
Expand All @@ -320,7 +345,6 @@
.ace_mgsc .ace_mml.ace_ignore {
color: #d00;
}
.ace_mgsc .ace_selection {
background-color: #ACCEF7;
}
Expand Down Expand Up @@ -354,26 +378,28 @@
background-color: rgba(255,255,255,0.14);
}
.ace_mgsc_dark .ace_comment {
color: #aaa;
color: #999;
}
.ace_mgsc_dark .ace_comment.ace_meta {
color: #e8e8ef;
}
.ace_mgsc_dark .ace_directive {
color: #ee0;
}
.ace_mgsc_dark .ace_constant {
color: #e8e8ef;
}
.ace_mgsc_dark .ace_voice_def {
color: #fbf;
}
.ace_mgsc_dark .ace_block_body {
color: #ec8;
.ace_mgsc_dark .ace_block {
color: #e8e8ef;
}
.ace_mgsc_dark .ace_macro_def {
color: #e8e;
}
.ace_mgsc_dark .ace_paren.ace_lparen {
color: #aaa;
}
.ace_mgsc_dark .ace_paren.ace_rparen {
color: #aaa;
.ace_mgsc_dark .ace_paren {
color: #ccc;
}
.ace_mgsc_dark .ace_channel {
color: #4ef;
Expand All @@ -382,10 +408,10 @@
color: #4ce;
}
.ace_mgsc_dark .ace_mml.ace_rel-volume {
color: #999;
color: #aaa;
}
.ace_mgsc_dark .ace_mml.ace_rel-octave {
color: #999;
color: #aaa;
}
.ace_mgsc_dark .ace_mml.ace_macro {
color: #e8e;
Expand Down

0 comments on commit 7e2e068

Please sign in to comment.