@felixtensor/tree-sitter-mlir 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +279 -0
- package/README.md +17 -0
- package/binding.gyp +35 -0
- package/bindings/node/binding.cc +19 -0
- package/bindings/node/binding_test.js +11 -0
- package/bindings/node/index.d.ts +60 -0
- package/bindings/node/index.js +37 -0
- package/grammar.js +506 -0
- package/package.json +67 -0
- package/prebuilds/darwin-arm64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/darwin-x64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/linux-arm64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/linux-x64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/win32-arm64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/prebuilds/win32-x64/@felixtensor+tree-sitter-mlir.node +0 -0
- package/queries/highlights.scm +83 -0
- package/queries/injections.scm +11 -0
- package/queries/locals.scm +7 -0
- package/src/grammar.json +5037 -0
- package/src/node-types.json +2284 -0
- package/src/parser.c +69777 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +330 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-mlir.wasm +0 -0
- package/tree-sitter.json +38 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
;; ---------------------------------------------------------------------------
|
|
2
|
+
;; MLIR Syntax Highlighting
|
|
3
|
+
;; For Neovim (nvim-treesitter), Helix, and other tree-sitter-compatible
|
|
4
|
+
;; editors. Uses standard tree-sitter capture names.
|
|
5
|
+
;; ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
(comment) @comment
|
|
8
|
+
|
|
9
|
+
;; ── Operations (Tiered) ─────────────────────────────────────────────────────
|
|
10
|
+
;; Builtin/Standard operations
|
|
11
|
+
(func_operation name: _ @function.builtin)
|
|
12
|
+
(module_operation name: _ @function.builtin)
|
|
13
|
+
(func_operation ["private" "public" "attributes"] @keyword)
|
|
14
|
+
(module_operation "attributes" @keyword)
|
|
15
|
+
|
|
16
|
+
;; Dialect operations (e.g., arith.addi)
|
|
17
|
+
(custom_op_name) @function.builtin
|
|
18
|
+
(generic_operation (string_literal) @function.builtin)
|
|
19
|
+
|
|
20
|
+
;; Symbols (@name)
|
|
21
|
+
(symbol_ref_id) @string.special.symbol
|
|
22
|
+
(func_operation sym_name: (symbol_ref_id) @function)
|
|
23
|
+
(module_operation sym_name: (symbol_ref_id) @function)
|
|
24
|
+
|
|
25
|
+
;; ── Types & Attributes ──────────────────────────────────────────────────────
|
|
26
|
+
;; Individual builtin type nodes — captures nested types inside dim_list
|
|
27
|
+
;; (e.g. vector inside memref<256 x 256 x vector<8 x f32>>) which are
|
|
28
|
+
;; reached through the hidden _prim_type rule, not through builtin_type.
|
|
29
|
+
[(builtin_type)
|
|
30
|
+
(memref_type) (vector_type) (tensor_type) (complex_type) (tuple_type)
|
|
31
|
+
(opaque_type) (integer_type) (float_type) (index_type) (none_type)] @type.builtin
|
|
32
|
+
[(type_alias) (type_alias_def) (dialect_type)] @type
|
|
33
|
+
|
|
34
|
+
;; Dimension sizes inside type dimension lists (256, 8, etc.)
|
|
35
|
+
(dimension_size) @number
|
|
36
|
+
|
|
37
|
+
;; 'x' separator inside dimension lists — render as delimiter rather than
|
|
38
|
+
;; inheriting the outer @type.builtin highlight (e.g. tensor<?x?x16xbf16>).
|
|
39
|
+
;; @cap binds to the "x" literal (parent-internal anonymous token), not the
|
|
40
|
+
;; whole dim_list — placing @cap outside an alternation would capture the
|
|
41
|
+
;; parent node instead.
|
|
42
|
+
(dim_list "x" @punctuation.delimiter)
|
|
43
|
+
(dimension_separator) @punctuation.delimiter
|
|
44
|
+
(vector_dim_list "x" @punctuation.delimiter)
|
|
45
|
+
|
|
46
|
+
[(attribute_alias) (attribute_alias_def) (dialect_attribute) (builtin_attribute) (dictionary_attribute)] @attribute
|
|
47
|
+
|
|
48
|
+
;; Specific attribute content
|
|
49
|
+
(affine_map ["max" "min" "symbol"] @keyword)
|
|
50
|
+
(affine_set ["max" "min" "symbol"] @keyword)
|
|
51
|
+
(strided_layout "offset" @keyword)
|
|
52
|
+
["ceildiv" "floordiv" "mod"] @keyword.operator
|
|
53
|
+
|
|
54
|
+
;; ── Literals ────────────────────────────────────────────────────────────────
|
|
55
|
+
[(integer_literal) (float_literal) (complex_literal)] @number
|
|
56
|
+
(bool_literal) @boolean
|
|
57
|
+
[(tensor_literal) (dense_resource_literal) (array_literal) (unit_literal) (uninitialized_literal)] @constant.builtin
|
|
58
|
+
(string_literal) @string
|
|
59
|
+
|
|
60
|
+
;; ── SSA Variables (%name) ───────────────────────────────────────────────────
|
|
61
|
+
;; General uses and results (catch-all, overridden by more specific rules below)
|
|
62
|
+
(op_result) @variable
|
|
63
|
+
(value_use) @variable
|
|
64
|
+
|
|
65
|
+
;; Formal Parameters override the general variable rule above
|
|
66
|
+
(func_arg_list (value_use) @variable.parameter)
|
|
67
|
+
(block_arg_list (value_use) @variable.parameter)
|
|
68
|
+
|
|
69
|
+
;; ── Control Flow ────────────────────────────────────────────────────────────
|
|
70
|
+
(caret_id) @label
|
|
71
|
+
(trailing_location "loc" @keyword)
|
|
72
|
+
(variadic) @punctuation.special
|
|
73
|
+
|
|
74
|
+
;; ── Punctuation ─────────────────────────────────────────────────────────────
|
|
75
|
+
["(" ")" "{" "}" "[" "]" "<" ">"] @punctuation.bracket
|
|
76
|
+
["," ":"] @punctuation.delimiter
|
|
77
|
+
["=" "->" "::"] @operator
|
|
78
|
+
|
|
79
|
+
;; Catch-all for bare keywords in Op bodies (ins, outs, etc.)
|
|
80
|
+
(bare_id) @keyword
|
|
81
|
+
|
|
82
|
+
;; Dictionary attribute keys override the bare_id catch-all above
|
|
83
|
+
(attribute_entry (bare_id) @attribute)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
; MLIR typically doesn't contain standard language injections inside its own files.
|
|
2
|
+
; However, if you are working with C++ code that embeds MLIR via raw string literals,
|
|
3
|
+
; you can add the following snippet to your editor's `cpp` injections
|
|
4
|
+
; (e.g., `languages/cpp/injections.scm` in Zed, or equivalent Neovim config)
|
|
5
|
+
; to automatically highlight MLIR inside `R"mlir(...)mlir"`:
|
|
6
|
+
|
|
7
|
+
; (raw_string_literal
|
|
8
|
+
; delimiter: (raw_string_delimiter) @delim
|
|
9
|
+
; (#eq? @delim "mlir")
|
|
10
|
+
; content: (raw_string_content) @injection.content
|
|
11
|
+
; (#set! injection.language "mlir"))
|