Skip to content

Commit

Permalink
make the hljs syntax a little more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
randomdude999 committed Feb 2, 2024
1 parent 556826c commit 0b95a5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
28 changes: 13 additions & 15 deletions docs/newbook/hljs-asar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ hljsAsar = {
};
const asarOperatorsMode = {
scope: "operator",
begin: /\(|\)|\+|\-|\*|\/|\%|\<\<|\>\>|\&|\||\^|\~|\*\*/,
begin: /\(|\)|\+|\-|\*|\/|\%|\<|\>|\&|\||\^|\~|#=|:=|\?=|!=|=/,
};

const asarFunctionCallMode = {
scope: "title.function",
begin: /[a-zA-Z0-9_]+(?=\()/,
}

// trying to highlight labels separately is more trouble than it's worth,
// the syntax conflicts with like everything else lol
const asarLabelReferenceMode = {
scope: "label",
variants: [
Expand All @@ -36,19 +34,16 @@ hljsAsar = {
],
};

/*const asarLabelDefinitionMode = {
const asarLabelDefinitionMode = {
scope: "label",
variants: [
// sublabels, macro labels, # labels - optional :
{ begin: /#?\??\.+[a-zA-Z0-9_]+:?/ },
{ begin: /#\??\.*[a-zA-Z0-9_]+:?/ },
// all other kinds of labels are already handled by asarLabelReferenceMode
// # labels - optional :
{ begin: /#?\?\.*[a-zA-Z0-9_]+:?/ },
// main labels - require :
{ begin: /[a-zA-Z0-9_]+:/ },
// +- labels
{ begin: /\??(-+|\++):?/ },
]
};*/
};

const asarSimpleDefineInMacroArg = {
scope: "variable.define",
Expand Down Expand Up @@ -123,10 +118,6 @@ hljsAsar = {
},
//hljs.QUOTE_STRING_MODE,
//hljs.APOS_STRING_MODE,
{
scope: "keyword",
begin: asarKeywords.join('\\b|').concat('\\b')
},
// hack for macro definitions
{
begin: /\b(?=macro )/,
Expand All @@ -143,9 +134,16 @@ hljsAsar = {
// stuff a lot more readable in those cases.
begin: /(%|!)[a-zA-Z0-9_]+(?=\()/,
},
// checking this earlier because otherwise, functions that are named like builtins would be highlighted wrong
asarFunctionCallMode,
asarLabelDefinitionMode,
{
scope: "keyword",
begin: asarKeywords.join('\\b|') + "\\b"
},
{
scope: "built_in",
begin: asarOpcodes.join('(\\.[bwl]|\\b)|').concat('(\\.[bwl]|\\b)')
begin: asarOpcodes.join('(\\.[bwl]|\\b)|') + '(\\.[bwl]|\\b)'
},
//asarLabelDefinitionMode,
asarBracedDefineOutsideMacro,
Expand Down
28 changes: 13 additions & 15 deletions docs/newbook/theme/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,14 @@ hljsAsar = {
};
const asarOperatorsMode = {
scope: "operator",
begin: /\(|\)|\+|\-|\*|\/|\%|\<\<|\>\>|\&|\||\^|\~|\*\*/,
begin: /\(|\)|\+|\-|\*|\/|\%|\<|\>|\&|\||\^|\~|#=|:=|\?=|!=|=/,
};

const asarFunctionCallMode = {
scope: "title.function",
begin: /[a-zA-Z0-9_]+(?=\()/,
}

// trying to highlight labels separately is more trouble than it's worth,
// the syntax conflicts with like everything else lol
const asarLabelReferenceMode = {
scope: "label",
variants: [
Expand All @@ -446,19 +444,16 @@ hljsAsar = {
],
};

/*const asarLabelDefinitionMode = {
const asarLabelDefinitionMode = {
scope: "label",
variants: [
// sublabels, macro labels, # labels - optional :
{ begin: /#?\??\.+[a-zA-Z0-9_]+:?/ },
{ begin: /#\??\.*[a-zA-Z0-9_]+:?/ },
// all other kinds of labels are already handled by asarLabelReferenceMode
// # labels - optional :
{ begin: /#?\?\.*[a-zA-Z0-9_]+:?/ },
// main labels - require :
{ begin: /[a-zA-Z0-9_]+:/ },
// +- labels
{ begin: /\??(-+|\++):?/ },
]
};*/
};

const asarSimpleDefineInMacroArg = {
scope: "variable.define",
Expand Down Expand Up @@ -533,10 +528,6 @@ hljsAsar = {
},
//hljs.QUOTE_STRING_MODE,
//hljs.APOS_STRING_MODE,
{
scope: "keyword",
begin: asarKeywords.join('\\b|').concat('\\b')
},
// hack for macro definitions
{
begin: /\b(?=macro )/,
Expand All @@ -553,9 +544,16 @@ hljsAsar = {
// stuff a lot more readable in those cases.
begin: /(%|!)[a-zA-Z0-9_]+(?=\()/,
},
// checking this earlier because otherwise, functions that are named like builtins would be highlighted wrong
asarFunctionCallMode,
asarLabelDefinitionMode,
{
scope: "keyword",
begin: asarKeywords.join('\\b|') + "\\b"
},
{
scope: "built_in",
begin: asarOpcodes.join('(\\.[bwl]|\\b)|').concat('(\\.[bwl]|\\b)')
begin: asarOpcodes.join('(\\.[bwl]|\\b)|') + '(\\.[bwl]|\\b)'
},
//asarLabelDefinitionMode,
asarBracedDefineOutsideMacro,
Expand Down

0 comments on commit 0b95a5a

Please sign in to comment.