diff --git a/.gitignore b/.gitignore index 24657b9..3b31662 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # will have compiled files and executables debug target +grammars # These are backup files generated by rustfmt **/*.rs.bk diff --git a/extension.toml b/extension.toml index d55b7a5..35aef30 100644 --- a/extension.toml +++ b/extension.toml @@ -1,6 +1,6 @@ id = "Marte" name = "MARTe" -version = "0.0.6" +version = "0.0.7" schema_version = 1 description = "MARTe language support for Zed" themes = [] @@ -11,8 +11,8 @@ kind = "Rust" version = "0.2.0" [grammars.marte] -repository = "https://github.com/MARTe-Community/tree-sitter-marte" -rev = "1edbdc955fe6c0cf5bccd33368f0eb03a62d2682" +repository = "https://github.com/Mandarancio/tree-sitter-marte" +rev = "f092e34c05412013534f98f0aa93a09b8ebe4d04" [language_servers.mdt] name = "mdt" diff --git a/grammars/marte.wasm b/grammars/marte.wasm index 84a1f08..493cd0c 100755 Binary files a/grammars/marte.wasm and b/grammars/marte.wasm differ diff --git a/languages/marte/folds.scm b/languages/marte/folds.scm new file mode 100644 index 0000000..ff95e85 --- /dev/null +++ b/languages/marte/folds.scm @@ -0,0 +1,10 @@ +; ── Fold directive blocks ────────────────────────────────────────── +(if_block) @fold +(else_if_clause) @fold +(else_clause) @fold +(foreach_block) @fold +(template_definition) @fold + +; ── Fold subnodes and array literals ─────────────────────────────── +(subnode) @fold +(array_literal) @fold diff --git a/languages/marte/highlights.scm b/languages/marte/highlights.scm index 6ad7955..42ded80 100644 --- a/languages/marte/highlights.scm +++ b/languages/marte/highlights.scm @@ -1,17 +1,118 @@ -(property) @property -(attribute) @attribute -(marte_common) @keyword -(app) @function -(string_literal) @string -(definition) @constructor -(builtintype) @type.builtin -(number) @number -(comment) @comment -(assign) @operator -(obrace) @punctuation.bracket -(cbrace) @punctuation.bracket -(opar) @punctuation.bracket -(cpar) @punctuation.bracket -(vbar) @operator -(comma) @punctuation.delimiter +; ── Keywords / Directives ────────────────────────────────────────────── +"package" @keyword +"var" @keyword +"let" @keyword +"if" @keyword.conditional +"else" @keyword.conditional +"end" @keyword +"foreach" @keyword.repeat +"in" @keyword +"template" @keyword +"use" @keyword +"as" @keyword +; ── Boolean ───────────────────────────────────────────────────────────── +"true" @boolean +"false" @boolean + +; ── Types ─────────────────────────────────────────────────────────────── +(builtin_type) @type.builtin +(type_bound) @type + +; ── Strings ───────────────────────────────────────────────────────────── +(string_literal) @string + +; ── Numbers ───────────────────────────────────────────────────────────── +(number) @number + +; ── Default identifier capture (overridden by specific rules below) ───── +(identifier) @variable + +; ── Variables ─────────────────────────────────────────────────────────── +(variable_reference) @variable + +; ── Comments ──────────────────────────────────────────────────────────── +(comment) @comment +(docstring) @comment.documentation +(pragma) @comment.note + +; ── Operators ─────────────────────────────────────────────────────────── +"=" @operator +"+" @operator +"-" @operator +"*" @operator +"/" @operator +"%" @operator +"^" @operator +"&" @operator +"|" @operator +"||" @operator +"&&" @operator +".." @operator +"==" @operator +"!=" @operator +"<" @operator +">" @operator +"<=" @operator +">=" @operator +"!" @operator + +; ── Objects ───────────────────────────────────────────────────────────── +(object_definition + name: (identifier) @constructor) +(object_definition + prefix: "$" @constructor) +(object_definition + prefix: "+" @constructor) + +; ── Punctuation ───────────────────────────────────────────────────────── +":" @punctuation.delimiter +"::" @punctuation.delimiter +"," @punctuation.delimiter +"." @punctuation.delimiter +"{" @punctuation.bracket +"}" @punctuation.bracket +"(" @punctuation.bracket +")" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket + +; ── Templates ─────────────────────────────────────────────────────────── +(template_definition + name: (identifier) @function) +(template_use + template: (identifier) @function) +(template_use + instance: (identifier) @variable) + +; ── Signal Shorthand ──────────────────────────────────────────────────── +(signal_shorthand + datasource: (identifier) @namespace) +(signal_shorthand + signal: (identifier) @variable) + +; ── Variables / Constants ─────────────────────────────────────────────── +(var_declaration + name: (identifier) @variable) +(let_declaration + name: (identifier) @constant) + +; ── Package ───────────────────────────────────────────────────────────── +(package_declaration + uri: (package_uri) @namespace) + +; ── Fields ────────────────────────────────────────────────────────────── +(field + name: (identifier) @property) + +; ── Parameters / Arguments ────────────────────────────────────────────── +(parameter + name: (identifier) @variable.parameter) +(argument + name: (identifier) @variable.parameter) + +; ── Type Expressions ──────────────────────────────────────────────────── +(type_expression + (identifier) @type) + +(dynamic_object) @constructor diff --git a/languages/marte/indents.scm b/languages/marte/indents.scm new file mode 100644 index 0000000..25b9ec1 --- /dev/null +++ b/languages/marte/indents.scm @@ -0,0 +1,33 @@ +; ── Indent after opening braces ───────────────────────────────────── +(subnode "{" @indent) @branch +(array_literal "{" @indent) @branch + +; ── Dedent on closing braces ─────────────────────────────────────── +"}" @dedent + +; ── Indent block bodies (if, foreach, template) ──────────────────── +(if_block + "if" @branch + (_) @indent) @branch + +(else_if_clause + "if" @branch + (_) @indent) @branch + +(else_clause + "else" @branch + (_) @indent) @branch + +(foreach_block + "foreach" @branch + (_) @indent) @branch + +(template_definition + "template" @branch + (_) @indent) @branch + +; ── Dedent on end keywords ───────────────────────────────────────── +"end" @dedent + +; ── Dedent on else/else if (close previous block, open new) ──────── +"else" @dedent diff --git a/languages/marte/locals.scm b/languages/marte/locals.scm new file mode 100644 index 0000000..e4af373 --- /dev/null +++ b/languages/marte/locals.scm @@ -0,0 +1,28 @@ +; ── Variable declarations: define the name as a local ────────────── +(var_declaration + name: (identifier) @local.definition) + +; ── Constant declarations ────────────────────────────────────────── +(let_declaration + name: (identifier) @local.definition) + +; ── Foreach loop variable ────────────────────────────────────────── +(foreach_block + value: (identifier) @local.definition) + +; ── Foreach key variable (when present) ──────────────────────────── +(foreach_block + key: (identifier) @local.definition) + +; ── Template parameters ──────────────────────────────────────────── +(parameter + name: (identifier) @local.definition) + +; ── Variable references: point back to definitions ───────────────── +(variable_reference + (identifier) @local.reference) + +; ── Scope blocks for locals ──────────────────────────────────────── +; (file-level variables are global; foreach/template create scopes) +(foreach_block) @local.scope +(template_definition) @local.scope diff --git a/languages/marte/tags.scm b/languages/marte/tags.scm new file mode 100644 index 0000000..3e3d735 --- /dev/null +++ b/languages/marte/tags.scm @@ -0,0 +1,41 @@ +; ── Object definitions (prefixed with + or $) ────────────────────── +(object_definition + prefix: "+" + name: (identifier) @name) @definition.class + +(object_definition + prefix: "$" + name: (identifier) @name) @definition.interface + +; ── Signal shorthand entries ─────────────────────────────────────── +(signal_shorthand + signal: (identifier) @name) @definition.field + +; ── Top-level fields (configuration values) ──────────────────────── +(source_file + (definition + (field + name: (identifier) @name))) @definition.property + +; ── Variable declarations ────────────────────────────────────────── +(var_declaration + name: (identifier) @name) @definition.variable + +; ── Constants ────────────────────────────────────────────────────── +(let_declaration + name: (identifier) @name) @definition.constant + +; ── Template definitions ─────────────────────────────────────────── +(template_definition + name: (identifier) @name) @definition.function + +; ── Template instantiations ──────────────────────────────────────── +(template_use + instance: (identifier) @name) @definition.variable + +; ── Package declaration ──────────────────────────────────────────── +(package_declaration + uri: (package_uri) @name) @definition.module + +; ── Docstrings attach to next definition ─────────────────────────── +(docstring) @documentation