Skip to content
Merged
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
130 changes: 114 additions & 16 deletions rascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,97 @@ Description: Syntax grammar for RAScript, a RetroAchievements.org DSL
Category: syntax
Version: <GRAMMAR_VERSION>
*/

function ImportantWordRegex() {
let words = [
"byte",
"word",
"tbyte",
"dword",
"bit0",
"bit1",
"bit2",
"bit3",
"bit4",
"bit5",
"bit6",
"bit7",
"bit",
"low4",
"high4",
"bitcount",
"word_be",
"tbyte_be",
"dword_be",
"float",
"float_be",
"mbf32",
"mbf32_le",
"double32",
"double32_be",
"prev",
"prior",
"bcd",
"identity_transform",
"ascii_string_equals",
"unicode_string_equals",
"repeated",
"once",
"tally",
"deduct",
"never",
"unless",
"measured",
"trigger_when",
"disable_when",
"always_true",
"always_false",
"format",
"substring",
"length",
"range",
"array_push",
"array_pop",
"array_map",
"array_contains",
"array_reduce",
"array_filter",
"dictionary_contains_key",
"any_of",
"all_of",
"none_of",
"sum_of",
"tally_of",
"max_of",
"assert",
"achievement",
"rich_presence_display",
"rich_presence_value",
"rich_presence_lookup",
"rich_presence_ascii_string_lookup",
"rich_presence_macro",
"rich_presence_conditional_display",
"leaderboard",
"__ornext",
]
return "\\b(" + words.join("|") + ")\\b";
}

export default function(hljs) {
return {
case_insensitive: false,
contains: [
// This block helps highlight.js auto detect RAScript syntax
{
begin: [
new RegExp(ImportantWordRegex()),
/\(/
],
beginScope: {
1: "title.function.invoke"
},
relevance: 10
},
hljs.C_LINE_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE,
Expand All @@ -17,20 +104,24 @@ export default function(hljs) {
'\\*/',
),
{
className: 'variable.language',
begin: /\b(this)\b/
scope: 'variable.language',
begin: /\b(this)\b/,
relevance: 0
},
{
className: 'keyword',
begin: /\b(function|class|else|for|if|in|return)\b/
scope: 'keyword',
begin: /\b(else|for|if|in|return)\b/,
relevance: 0
},
{
className: 'literal',
begin: /\b(true|false)\b/
scope: 'literal',
begin: /\b(true|false)\b/,
relevance: 0
},
{
className: 'operator',
begin: /(\|\||\&\&|\=\=|\!\=|\>\=|\<\=|\=\>)/
scope: 'operator',
begin: /(\|\||\&\&|\=\=|\!\=|\>\=|\<\=|\=\>)/,
relevance: 0
},
{
scope: 'operator',
Expand All @@ -39,22 +130,28 @@ export default function(hljs) {
},
{
begin: [
/function[\t ]+/,
/\b(function)\b/,
/[\t ]+/,
/[a-zA-Z_][\w]*/,
/\(/
],
beginScope: {
2: "title.function"
}
1: "keyword",
3: "title.function"
},
relevance: 0
},
{
begin: [
/class[\t ]+/,
/\b(class)\b/,
/[\t ]+/,
/[a-zA-Z_][\w]*/
],
beginScope: {
2: "title.class"
}
1: "keyword",
3: "title.class"
},
relevance: 0
},
{
begin: [
Expand All @@ -63,10 +160,11 @@ export default function(hljs) {
],
beginScope: {
1: "title.function.invoke"
}
},
relevance: 0
},
{
className: 'variable',
scope: 'variable',
begin: /[a-zA-Z_][\w]*/,
relevance: 0
}
Expand Down