diff options
| author | Amaan Qureshi <amaanq12@gmail.com> | 2023-07-06 21:42:51 -0400 |
|---|---|---|
| committer | Amaan Qureshi <amaanq12@gmail.com> | 2023-07-08 04:29:57 -0400 |
| commit | f45ea99454ccf28b0d614ae2f3a309f78a9f6698 (patch) | |
| tree | d810ca0134cff7b8141f73fcb842900b5352158c /queries/cairo | |
| parent | feat(pug): improve syntax highlighting (diff) | |
| download | nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.tar nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.tar.gz nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.tar.bz2 nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.tar.lz nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.tar.xz nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.tar.zst nvim-treesitter-f45ea99454ccf28b0d614ae2f3a309f78a9f6698.zip | |
feat: add Cairo
Diffstat (limited to 'queries/cairo')
| -rw-r--r-- | queries/cairo/folds.scm | 31 | ||||
| -rw-r--r-- | queries/cairo/highlights.scm | 338 | ||||
| -rw-r--r-- | queries/cairo/indents.scm | 45 | ||||
| -rw-r--r-- | queries/cairo/injections.scm | 3 | ||||
| -rw-r--r-- | queries/cairo/locals.scm | 68 |
5 files changed, 485 insertions, 0 deletions
diff --git a/queries/cairo/folds.scm b/queries/cairo/folds.scm new file mode 100644 index 000000000..1c7af9fcf --- /dev/null +++ b/queries/cairo/folds.scm @@ -0,0 +1,31 @@ +[ + (mod_item) + (struct_item) + (trait_item) + (enum_item) + (impl_item) + (type_item) + + (use_declaration) + (let_declaration) + (namespace_definition) + + (arguments) + (implicit_arguments) + (tuple_type) + + (import_statement) + (attribute_statement) + (with_statement) + (if_statement) + + (function_definition) + (struct_definition) + (loop_expression) + (if_expression) + (match_expression) + (call_expression) + (tuple_expression) + + (attribute_item) +] @fold diff --git a/queries/cairo/highlights.scm b/queries/cairo/highlights.scm new file mode 100644 index 000000000..0f68121ae --- /dev/null +++ b/queries/cairo/highlights.scm @@ -0,0 +1,338 @@ +; Preproc + +[ + "%builtins" + "%lang" +] @preproc + +; Includes + +(import_statement [ "from" "import" ] @include module_name: (dotted_name (identifier) @namespace . )) + +[ + "as" + "use" + "mod" +] @include + +; Variables + +(identifier) @variable + +; Namespaces + +(namespace_definition (identifier) @namespace) + +(mod_item + name: (identifier) @namespace) + +(use_list (self) @namespace) + +(scoped_use_list (self) @namespace) + +(scoped_identifier + path: (identifier) @namespace) + +(scoped_identifier + (scoped_identifier + name: (identifier) @namespace)) + +(scoped_type_identifier + path: (identifier) @namespace) + +((scoped_identifier + path: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((scoped_identifier + name: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((scoped_identifier + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +((scoped_identifier + path: (identifier) @type + name: (identifier) @constant) + (#lua-match? @type "^[A-Z]") + (#lua-match? @constant "^[A-Z]")) + +((scoped_type_identifier + path: (identifier) @type + name: (type_identifier) @constant) + (#lua-match? @type "^[A-Z]") + (#lua-match? @constant "^[A-Z]")) + +(scoped_use_list + path: (identifier) @namespace) + +(scoped_use_list + path: (scoped_identifier + (identifier) @namespace)) + +(use_list (scoped_identifier (identifier) @namespace . (_))) + +(use_list (identifier) @type (#lua-match? @type "^[A-Z]")) + +(use_as_clause alias: (identifier) @type (#lua-match? @type "^[A-Z]")) + +; Keywords + +[ + ; 0.x + "using" + "namespace" + "struct" + "let" + "const" + "local" + "rel" + "abs" + "dw" + "alloc_locals" + (inst_ret) + "with_attr" + "with" + "call" + "nondet" + + ; 1.0 + "type" + "impl" + "implicits" + "of" + "ref" + "mut" + "trait" + "enum" +] @keyword + +[ + "func" + "fn" + "end" +] @keyword.function + +"return" @keyword.return + +[ + "cast" + "new" + "and" +] @keyword.operator + +[ + "tempvar" + "extern" +] @storageclass + +[ + "if" + "else" + "match" +] @conditional + +[ + "loop" +] @repeat + +[ + "assert" + "static_assert" + "nopanic" +] @exception + +; Fields + +(implicit_arguments (typed_identifier (identifier) @field)) + +(member_expression "." (identifier) @field) + +(call_expression (assignment_expression left: (identifier) @field)) + +(tuple_expression (assignment_expression left: (identifier) @field)) + +(field_identifier) @field + +(shorthand_field_initializer (identifier) @field) + +; Parameters + +(arguments (typed_identifier (identifier) @parameter)) + +(call_expression (tuple_expression (assignment_expression left: (identifier) @parameter))) + +(return_type (tuple_type (named_type . (identifier) @parameter))) + +(parameter (identifier) @parameter) + +; Builtins + +(builtin_directive (identifier) @variable.builtin) +(lang_directive (identifier) @variable.builtin) + +[ + "ap" + "fp" + (self) +] @variable.builtin + +; Functions + +(function_definition "func" (identifier) @function) +(function_definition "fn" (identifier) @function) +(function_signature "fn" (identifier) @function) +(extern_function_statement (identifier) @function) + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (scoped_identifier + (identifier) @function.call .)) + +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) + +[ + "jmp" +] @function.builtin + +; Types + +(struct_definition . (identifier) @type (typed_identifier (identifier) @field)?) + +(named_type (identifier) @type .) + +[ + (builtin_type) + (primitive_type) +] @type.builtin + +((identifier) @type + (#lua-match? @type "^[A-Z][a-zA-Z0-9_]*$")) + +(type_identifier) @type + +; Constants + +((identifier) @constant + (#lua-match? @constant "^[A-Z_][A-Z0-9_]*$")) + +(enum_variant + name: (identifier) @constant) + +(call_expression + function: (scoped_identifier + "::" + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z]")) + +((match_arm + pattern: (match_pattern (identifier) @constant)) + (#lua-match? @constant "^[A-Z]")) + +((match_arm + pattern: (match_pattern + (scoped_identifier + name: (identifier) @constant))) + (#lua-match? @constant "^[A-Z]")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin "Some" "None" "Ok" "Err")) + +; Constructors + +(unary_expression "new" (call_expression . (identifier) @constructor)) + +((call_expression . (identifier) @constructor) + (#lua-match? @constructor "^%u")) + +; Attributes + +(decorator "@" @attribute (identifier) @attribute) + +(attribute_item (identifier) @function.macro) + +(attribute_item (scoped_identifier (identifier) @function.macro .)) + +; Labels + +(label . (identifier) @label) + +(inst_jmp_to_label "jmp" . (identifier) @label) + +(inst_jnz_to_label "jmp" . (identifier) @label) + +; Operators + +[ + "+" + "-" + "*" + "/" + "**" + "==" + "!=" + "&" + "=" + "++" + "+=" + "@" + "!" + "~" + ".." + "&&" + "||" + "^" + "<" + "<=" + ">" + ">=" + "<<" + ">>" + "%" + "-=" + "*=" + "/=" + "%=" + "&=" + "|=" + "^=" + "<<=" + ">>=" + "?" +] @operator + +; Literals + +(number) @number + +(boolean) @boolean + +[ + (string) + (short_string) +] @string + +; Punctuation + +(attribute_item "#" @punctuation.special) + +[ "." "," ":" ";" "->" "=>" "::" ] @punctuation.delimiter + +[ "{" "}" "(" ")" "[" "]" "%{" "%}" ] @punctuation.bracket + +(type_parameters [ "<" ">" ] @punctuation.bracket) + +(type_arguments [ "<" ">" ] @punctuation.bracket) + +; Comment + +(comment) @comment @spell + +; Errors + +(ERROR) @error diff --git a/queries/cairo/indents.scm b/queries/cairo/indents.scm new file mode 100644 index 000000000..76a22e705 --- /dev/null +++ b/queries/cairo/indents.scm @@ -0,0 +1,45 @@ +[ + (mod_item) + (struct_item) + (enum_item) + (impl_item) + (struct_expression) + (match_expression) + (tuple_expression) + (match_arm) + (match_block) + (call_expression) + (assignment_expression) + (arguments) + (block) + (use_list) + (field_declaration_list) + (enum_variant_list) + (tuple_pattern) +] @indent.begin + +(import_statement "(") @indent.begin + +(block "}" @indent.end) +(enum_item + body: (enum_variant_list "}" @indent.end)) +(match_expression + body: (match_block "}" @indent.end)) +(mod_item + body: (declaration_list "}" @indent.end)) +(struct_item + body: (field_declaration_list "}" @indent.end)) +(trait_item + body: (declaration_list "}" @indent.end)) + +[ + ")" + "]" + "}" +] @indent.branch + +[ + (comment) + (string) + (short_string) +] @indent.ignore diff --git a/queries/cairo/injections.scm b/queries/cairo/injections.scm new file mode 100644 index 000000000..675a81a76 --- /dev/null +++ b/queries/cairo/injections.scm @@ -0,0 +1,3 @@ +(python_code) @python + +(comment) @comment diff --git a/queries/cairo/locals.scm b/queries/cairo/locals.scm new file mode 100644 index 000000000..53b33c01d --- /dev/null +++ b/queries/cairo/locals.scm @@ -0,0 +1,68 @@ +; References + +(identifier) @reference +((type_identifier) @reference + (#set! reference.kind "type")) +((field_identifier) @reference + (#set! reference.kind "field")) + +; Scopes + +[ + (program) + (block) + (function_definition) + (loop_expression) + (if_expression) + (match_expression) + (match_arm) + + (struct_item) + (enum_item) + (impl_item) +] @scope + +(use_declaration + argument: (scoped_identifier + name: (identifier) @definition.import)) + +(use_as_clause + alias: (identifier) @definition.import) + +(use_list + (identifier) @definition.import) ; use std::process::{Child, Command, Stdio}; + +; Functions + +(function_definition + (identifier) @definition.function) + +(function_definition + (identifier) @definition.method + (parameter (self))) + +; Function with parameters, defines parameters + +(parameter + [ (identifier) (self) ] @definition.parameter) + +; Types + +(struct_item + name: (type_identifier) @definition.type) + +(constrained_type_parameter + left: (type_identifier) @definition.type) ; the P in remove_file<P: AsRef<Path>>(path: P) + +(enum_item + name: (type_identifier) @definition.type) + +; Module + +(mod_item + name: (identifier) @definition.namespace) + +; Variables + +(assignment_expression + left: (identifier) @definition.var) |
