From 4498b0e3e49acc8ee8991ddc44922c823b6c9d01 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 6 Aug 2025 18:32:34 +0200 Subject: [PATCH 1/3] feat: highlight declare directive --- Pluto.tmbundle/Syntaxes/Pluto.tmLanguage | 214 ++++++++++++++++------- test.js | 29 +++ 2 files changed, 175 insertions(+), 68 deletions(-) diff --git a/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage b/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage index be012ed..042c09b 100644 --- a/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage +++ b/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage @@ -25,31 +25,36 @@ patterns - begin - \b(function)(?:\s+(?:[a-zA-Z_][a-zA-Z0-9_]*([.:]))?([a-zA-Z_][a-zA-Z0-9_]*))?\s*(\() - beginCaptures - - 1 - - name - storage.type.function.pluto - - 2 - - name - punctuation.separator.parameter.pluto - - 3 - - name - entity.name.function.pluto - - 4 - - name - punctuation.section.group.begin.pluto - - + begin + (?:(\$declare)\s+)?\b(function)(?:\s+(?:[a-zA-Z_][a-zA-Z0-9_]*([.:]))?([a-zA-Z_][a-zA-Z0-9_]*))?\s*(\() + beginCaptures + + 1 + + name + storage.modifier.pluto + + 2 + + name + storage.type.function.pluto + + 3 + + name + punctuation.separator.parameter.pluto + + 4 + + name + entity.name.function.pluto + + 5 + + name + punctuation.section.group.begin.pluto + + end (\))(?:(:)\s+(void|\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*|\{[^}]*\})\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*|\{[^}]*\})\??))?(\s*<nodiscard>)? endCaptures @@ -539,7 +544,7 @@ match - \+|-|%|#|\*|\/|\^|==|~=|!=|<=?|>=?|(?<!\.)\.{2}(?!\.)|\$|\||~|& + \+|-|%|#|\*|\/|\^|==|~=|!=|<=?|>=?|(?<!\.)\.{2}(?!\.)|\$(?![a-zA-Z_])|\||~|& name keyword.operator.logical.pluto @@ -726,9 +731,9 @@ name keyword.control.pluto - - begin - \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) + + begin + \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) beginCaptures 1 @@ -770,45 +775,118 @@ include #table_type_body - - - - include - #function_type - - - match - \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) - captures - - 1 - - name - storage.modifier.pluto - - 2 - - name - invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto - - 3 - - name - punctuation.separator.colon.pluto - - 4 - - name - storage.type.primitive.pluto - - - - - match - \b(?<![.\:])(local|global|export|pluto_export)\b - name - storage.modifier.pluto - + + + + begin + (? + beginCaptures + + 1 + + name + storage.modifier.pluto + + 2 + + name + invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto + + 3 + + name + punctuation.separator.colon.pluto + + 4 + + name + punctuation.section.table.begin.pluto + + + end + \} + endCaptures + + 0 + + name + punctuation.section.table.end.pluto + + + name + meta.typehint.table.pluto + patterns + + + include + #table_type_body + + + + + include + #function_type + + + match + \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) + captures + + 1 + + name + storage.modifier.pluto + + 2 + + name + invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto + + 3 + + name + punctuation.separator.colon.pluto + + 4 + + name + storage.type.primitive.pluto + + + + + match + (? + captures + + 1 + + name + storage.modifier.pluto + + 2 + + name + invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto + + 3 + + name + punctuation.separator.colon.pluto + + 4 + + name + storage.type.primitive.pluto + + + + + match + \b(?<![.\:])(local|global|export|pluto_export)\b + name + storage.modifier.pluto + match \b(?<![.\:])(static)(?!\s*\()\b diff --git a/test.js b/test.js index e5f8f7d..0f8076f 100644 --- a/test.js +++ b/test.js @@ -270,6 +270,35 @@ async function main() ` - punctuation.separator.colon.pluto`, ` -------- storage.type.primitive.pluto` ); + checkClassification( + `$declare _PVERSION: string`, + `-------- storage.modifier.pluto`, + ` - punctuation.separator.colon.pluto`, + ` ------ storage.type.primitive.pluto` + ); + checkClassification( + `$declare function tonumber(str: string, base: ?number): number`, + `-------- storage.modifier.pluto`, + ` - meta.function.pluto`, + ` -------- storage.type.function.pluto`, + ` - meta.function.pluto`, + ` -------- entity.name.function.pluto`, + ` - punctuation.section.group.begin.pluto`, + ` --- variable.parameter.function.pluto`, + ` - punctuation.separator.colon.pluto`, + ` - meta.typehint.pluto`, + ` ------ storage.type.primitive.pluto`, + ` - punctuation.separator.comma.pluto`, + ` - meta.function.pluto`, + ` ---- variable.parameter.function.pluto`, + ` - punctuation.separator.colon.pluto`, + ` - meta.typehint.pluto`, + ` ------- storage.type.primitive.pluto`, + ` - punctuation.section.group.end.pluto`, + ` - punctuation.separator.colon.pluto`, + ` - meta.function.pluto`, + ` ------ storage.type.primitive.pluto` + ); const langConfig = JSON.parse( fs.readFileSync(path.join(__dirname, "language-config.json"), "utf8").replace(/\/\/.*$/gm, "") From e548c5b13e997b95f230bc1ae78f19f5387b0c84 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 6 Aug 2025 18:44:31 +0200 Subject: [PATCH 2/3] fix: escape lookbehind operators --- Pluto.tmbundle/Syntaxes/Pluto.tmLanguage | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage b/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage index 042c09b..87b00ad 100644 --- a/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage +++ b/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage @@ -779,7 +779,7 @@ begin - (? + (?<!\S)(\$declare)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) beginCaptures 1 @@ -856,7 +856,7 @@ match - (? + (?<!\S)(\$declare)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) captures 1 From 2f85ec417cb3e937bcf03241348ba5129d3e57a4 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 6 Aug 2025 18:45:25 +0200 Subject: [PATCH 3/3] Reindent --- Pluto.tmbundle/Syntaxes/Pluto.tmLanguage | 292 +++++++++++------------ 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage b/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage index 87b00ad..036ef1a 100644 --- a/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage +++ b/Pluto.tmbundle/Syntaxes/Pluto.tmLanguage @@ -25,36 +25,36 @@ patterns - begin - (?:(\$declare)\s+)?\b(function)(?:\s+(?:[a-zA-Z_][a-zA-Z0-9_]*([.:]))?([a-zA-Z_][a-zA-Z0-9_]*))?\s*(\() - beginCaptures - - 1 - - name - storage.modifier.pluto - - 2 - - name - storage.type.function.pluto - - 3 - - name - punctuation.separator.parameter.pluto - - 4 - - name - entity.name.function.pluto - - 5 - - name - punctuation.section.group.begin.pluto - - + begin + (?:(\$declare)\s+)?\b(function)(?:\s+(?:[a-zA-Z_][a-zA-Z0-9_]*([.:]))?([a-zA-Z_][a-zA-Z0-9_]*))?\s*(\() + beginCaptures + + 1 + + name + storage.modifier.pluto + + 2 + + name + storage.type.function.pluto + + 3 + + name + punctuation.separator.parameter.pluto + + 4 + + name + entity.name.function.pluto + + 5 + + name + punctuation.section.group.begin.pluto + + end (\))(?:(:)\s+(void|\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*|\{[^}]*\})\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*|\{[^}]*\})\??))?(\s*<nodiscard>)? endCaptures @@ -544,7 +544,7 @@ match - \+|-|%|#|\*|\/|\^|==|~=|!=|<=?|>=?|(?<!\.)\.{2}(?!\.)|\$(?![a-zA-Z_])|\||~|& + \+|-|%|#|\*|\/|\^|==|~=|!=|<=?|>=?|(?<!\.)\.{2}(?!\.)|\$(?![a-zA-Z_])|\||~|& name keyword.operator.logical.pluto @@ -731,9 +731,55 @@ name keyword.control.pluto - - begin - \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) + + begin + \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) + beginCaptures + + 1 + + name + storage.modifier.pluto + + 2 + + name + invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto + + 3 + + name + punctuation.separator.colon.pluto + + 4 + + name + punctuation.section.table.begin.pluto + + + end + \} + endCaptures + + 0 + + name + punctuation.section.table.end.pluto + + + name + meta.typehint.table.pluto + patterns + + + include + #table_type_body + + + + + begin + (?<!\S)(\$declare)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) beginCaptures 1 @@ -775,118 +821,72 @@ include #table_type_body - - - - begin - (?<!\S)(\$declare)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)\s*(:)\s*(\{) - beginCaptures - - 1 - - name - storage.modifier.pluto - - 2 - - name - invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto - - 3 - - name - punctuation.separator.colon.pluto - - 4 - - name - punctuation.section.table.begin.pluto - - - end - \} - endCaptures - - 0 - - name - punctuation.section.table.end.pluto - - - name - meta.typehint.table.pluto - patterns - - - include - #table_type_body - - - - - include - #function_type - - - match - \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) - captures - - 1 - - name - storage.modifier.pluto - - 2 - - name - invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto - - 3 - - name - punctuation.separator.colon.pluto - - 4 - - name - storage.type.primitive.pluto - - - - - match - (?<!\S)(\$declare)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) - captures - - 1 - - name - storage.modifier.pluto - - 2 - - name - invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto - - 3 - - name - punctuation.separator.colon.pluto - - 4 - - name - storage.type.primitive.pluto - - - - - match - \b(?<![.\:])(local|global|export|pluto_export)\b - name - storage.modifier.pluto - + + + + include + #function_type + + + match + \b(?<!\.)(local|global)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) + captures + + 1 + + name + storage.modifier.pluto + + 2 + + name + invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto + + 3 + + name + punctuation.separator.colon.pluto + + 4 + + name + storage.type.primitive.pluto + + + + + match + (?<!\S)(\$declare)\s+(?!class)(?!pluto_class)(?!function)(?:(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|pluto_use|pluto_switch|pluto_continue|pluto_enum|pluto_new|pluto_class|pluto_export|pluto_try|pluto_catch|switch|continue|enum|new|class|export|try|catch|return|then|true|until|while)\b|\w+)(?:\s*(:)\s+(?!function\s*\()(\??(?:(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\|)*(?:string|number|int|float|bool(?:ean)?|function|table|userdata|any|nil|[a-zA-Z_][a-zA-Z0-9_]*)\??))?(?!\s*=\s*\|[a-zA-Z0-9_,\s]*\|\s*->) + captures + + 1 + + name + storage.modifier.pluto + + 2 + + name + invalid.name.reserved.not-narrow.not-overridable.not-optional.not-special.pluto + + 3 + + name + punctuation.separator.colon.pluto + + 4 + + name + storage.type.primitive.pluto + + + + + match + \b(?<![.\:])(local|global|export|pluto_export)\b + name + storage.modifier.pluto + match \b(?<![.\:])(static)(?!\s*\()\b