From b301c2f60881e09d9a79b91f966d7b1f6356fc30 Mon Sep 17 00:00:00 2001 From: Joshua Raphael Date: Tue, 2 Sep 2025 11:09:18 -0700 Subject: [PATCH] add highlightjs definition --- .github/workflows/release.yaml | 3 +- README.md | 4 +- rascript.js | 75 ++++++++++++++++++++++++++++++++++ scripts/generate.sh | 3 +- 4 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 rascript.js diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b524c65..04b09b3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,4 +21,5 @@ jobs: files: | gen/rascript.tmLanguage.json gen/rascript.tmLanguage - gen/RAScript.xml \ No newline at end of file + gen/RAScript.xml + gen/rascript.js \ No newline at end of file diff --git a/README.md b/README.md index d2ba9c5..3ca54ec 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ run `make generate` to create the grammar files in the `gen` folder. The current * rascript.tmLanguage.json -- vscode, linguist * rascript.tmLanguage -- sublime * RAScript.xml -- Notepad++ +* rascript.js -- highlight.js ## Download @@ -19,4 +20,5 @@ Grab the latest generated files on the [release](https://github.com/joshraphael/ ## Projects Using rascript-syntax - [vscode-rascript](https://github.com/joshraphael/vscode-rascript) - VSCode language client for RAScript. - [sublime-rascript](https://github.com/joshraphael/sublime-rascript) - SublimeText language client for RAScript. -- [npp-rascript](https://github.com/joshraphael/npp-rascript) - Notepad++ language client for RAScript. \ No newline at end of file +- [npp-rascript](https://github.com/joshraphael/npp-rascript) - Notepad++ language client for RAScript. +- [highlightjs-rascript](https://github.com/joshraphael/highlightjs-rascript) - highlight.js grammar definition for RAScript. \ No newline at end of file diff --git a/rascript.js b/rascript.js new file mode 100644 index 0000000..5a378f7 --- /dev/null +++ b/rascript.js @@ -0,0 +1,75 @@ +/* +Language: RAScript +Author: Joshua Raphael +Description: Syntax grammar for RAScript, a RetroAchievements.org DSL +Category: syntax +Version: +*/ +export default function(hljs) { + return { + case_insensitive: false, + contains: [ + hljs.C_LINE_COMMENT_MODE, + hljs.QUOTE_STRING_MODE, + hljs.C_NUMBER_MODE, + hljs.COMMENT( + '/\\*', + '\\*/', + ), + { + className: 'variable.language', + begin: /\b(this)\b/ + }, + { + className: 'keyword', + begin: /\b(function|class|else|for|if|in|return)\b/ + }, + { + className: 'literal', + begin: /\b(true|false)\b/ + }, + { + className: 'operator', + begin: /(\|\||\&\&|\=\=|\!\=|\>\=|\<\=|\=\>)/ + }, + { + scope: 'operator', + match: /[\+\-\*\/\%\^\&\^\~\>\<\!\|]/, + relevance: 0 + }, + { + begin: [ + /function[\t ]+/, + /[a-zA-Z_][\w]*/, + /\(/ + ], + beginScope: { + 2: "title.function" + } + }, + { + begin: [ + /class[\t ]+/, + /[a-zA-Z_][\w]*/ + ], + beginScope: { + 2: "title.class" + } + }, + { + begin: [ + /[a-zA-Z_][\w]*/, + /\(/ + ], + beginScope: { + 1: "title.function.invoke" + } + }, + { + className: 'variable', + begin: /[a-zA-Z_][\w]*/, + relevance: 0 + } + ] + } +} \ No newline at end of file diff --git a/scripts/generate.sh b/scripts/generate.sh index 18a806c..a43dcba 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -8,4 +8,5 @@ fi sed "s//$VERSION/g" rascript.tmLanguage.json > gen/rascript.tmLanguage.json plistutil -f xml -i gen/rascript.tmLanguage.json -o gen/rascript.tmLanguage -sed "s//$VERSION/g" RAScript.xml > gen/RAScript.xml \ No newline at end of file +sed "s//$VERSION/g" RAScript.xml > gen/RAScript.xml +sed "s//$VERSION/g" rascript.js > gen/rascript.js \ No newline at end of file