[Mlir-commits] [mlir] 86f5cae - [mlir] Significantly overhaul the textmate grammar
River Riddle
llvmlistbot at llvm.org
Thu May 12 15:50:46 PDT 2022
Author: River Riddle
Date: 2022-05-12T15:50:32-07:00
New Revision: 86f5caeee955660e6faf71e5efd2ae24a335a0cc
URL: https://github.com/llvm/llvm-project/commit/86f5caeee955660e6faf71e5efd2ae24a335a0cc
DIFF: https://github.com/llvm/llvm-project/commit/86f5caeee955660e6faf71e5efd2ae24a335a0cc.diff
LOG: [mlir] Significantly overhaul the textmate grammar
The current grammar is really crusty, only supports a handful of
cases, and is also out-of-date after various refactorings. This commit
refactors the textmate grammar to handle significantly more cases,
and now provides proper coloring for a majority of cases (including
dialect attributes, operations, types, etc.)
Differential Revision: https://reviews.llvm.org/D125458
Added:
Modified:
mlir/utils/textmate/mlir.json
Removed:
################################################################################
diff --git a/mlir/utils/textmate/mlir.json b/mlir/utils/textmate/mlir.json
index 5b8accac30002..820f8921cf237 100644
--- a/mlir/utils/textmate/mlir.json
+++ b/mlir/utils/textmate/mlir.json
@@ -1,40 +1,49 @@
{
+ "name": "MLIR",
"fileTypes": [
"mlir"
],
- "repository": {
- "attribute": {
- "match": "\\W[\\w_][\\w\\d_.$]*\\s*=",
- "name": "meta.attribute.mlir"
+ "patterns": [
+ {
+ "include": "#comment"
},
- "branch_target": {
- "match": "\\^bb[\\w\\d_$\\.-]+",
- "name": "entity.name.label.mlir"
+ {
+ "include": "#string"
},
+ {
+ "include": "#top_level_entity"
+ }
+ ],
+ "repository": {
"comment": {
"match": "\/\/.*$",
"name": "comment.line.double-slash.mlir"
},
- "identifier": {
- "match": "[\\%#@][\\w_][\\w\\d_.$]*",
- "captures": {
- "0": {
- "name": "variable.mlir"
- }
- },
- "name": "meta.identifier.mlir"
- },
- "integer": {
- "match": "[\\Wx]([0-9]+)",
- "captures": {
- "1": {
+ "number": {
+ "patterns": [
+ {
+ "match": "(\\W)?([0-9]+\\.[0-9]*)([eE][+-]?[0-9]+)?",
"name": "constant.numeric.mlir"
+ },
+ {
+ "match": "([\\W])?(0x[0-9a-zA-Z]+)",
+ "captures": {
+ "2": {
+ "name": "constant.numeric.mlir"
+ }
+ }
+ },
+ {
+ "match": "([\\Wx])?([0-9]+)",
+ "captures": {
+ "2": {
+ "name": "constant.numeric.mlir"
+ }
+ }
}
- },
- "name": "meta.identifier.mlir"
+ ]
},
"string": {
- "end": "\"",
"begin": "\"",
"beginCaptures": {
"0": {
@@ -45,12 +54,9 @@
{
"match": "\\\\[nt\"]",
"name": "constant.character.escape.mlir"
- },
- {
- "match": "\\\\.",
- "name": "invalid.illegal.mlir"
}
],
+ "end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.mlir"
@@ -58,58 +64,335 @@
},
"name": "string.quoted.double.mlir"
},
- "types": {
- "match": "[\\Wx](index|i[1-9][0-9]*|f16|bf16|f32|f64|memref|tensor|vector)\\b",
+ "top_level_entity": {
+ "patterns": [
+ {
+ "include": "#attribute_alias_def"
+ },
+ {
+ "include": "#type_alias_def"
+ },
+ {
+ "include": "#operation_body"
+ }
+ ]
+ },
+ "attribute_alias_def": {
+ "match": "^\\s*(\\#\\w+)\\b\\s+\\=",
"captures": {
"1": {
- "name": "storage.type.mlir"
+ "name": "constant.language.mlir"
}
- },
- "name": "meta.types.simple.mlir"
- }
- },
- "patterns": [
- {
- "include": "#comment"
+ }
},
- {
- "include": "#string"
- },
- {
- "match": "\\b(func)\\b\\s*(|private|public)\\s*(@[\\w_][\\w\\d_.$]*)",
+ "type_alias_def": {
+ "match": "^\\s*(\\!\\w+)\\b\\s+\\=",
"captures": {
"1": {
- "name": "keyword.function.mlir"
+ "name": "entity.name.type.mlir"
+ }
+ }
+ },
+ "operation": {
+ "patterns": [
+ {
+ "match": "^\\s*(\\%[\\%\\w\\:\\,\\s]+)\\s+\\=\\s+([\\w\\.\\$\\-]+)\\b",
+ "captures": {
+ "1": {
+ "patterns": [
+ {
+ "include": "#ssa_value"
+ }
+ ]
+ },
+ "2": {
+ "name": "variable.other.enummember.mlir"
+ }
+ }
},
- "2": {
- "name": "keyword.function.mlir"
+ {
+ "match": "^\\s*([\\w\\.\\$\\-]+)\\b(?=[^\\<\\:])",
+ "name": "variable.other.enummember.mlir"
+ }
+ ]
+ },
+ "operation_body": {
+ "patterns": [
+ {
+ "include": "#operation"
},
- "3": {
- "name": "entity.name.function.mlir"
+ {
+ "include": "#region_body_or_attr_dict"
+ },
+ {
+ "include": "#comment"
+ },
+ {
+ "include": "#ssa_value"
+ },
+ {
+ "include": "#block"
+ },
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "include": "#bare_identifier"
}
- },
- "name": "support.function.mlir"
+ ]
},
- {
- "match": "\\b(attributes|br|call|constant|loc|return)\\b",
- "name": "keyword.module.mlir"
+ "region_body_or_attr_dict": {
+ "patterns": [
+ {
+ "begin": "\\{\\s*(?=\\%|\\/|\\^)",
+ "patterns": [
+ {
+ "include": "#operation_body"
+ }
+ ],
+ "end": "\\}"
+ },
+ {
+ "begin": "\\{\\s*(?=[^\\}]*$)",
+ "patterns": [
+ {
+ "include": "#operation_body"
+ }
+ ],
+ "end": "\\}"
+ },
+ {
+ "begin": "\\{\\s*(?=\\%)",
+ "patterns": [
+ {
+ "include": "#operation_body"
+ }
+ ],
+ "end": "\\}"
+ },
+ {
+ "begin": "\\{\\s*(?=.*$)",
+ "patterns": [
+ {
+ "include": "#attribute_dictionary_body"
+ }
+ ],
+ "end": "\\}"
+ }
+ ]
},
- {
- "include": "#identifier"
+ "attribute_value": {
+ "patterns": [
+ {
+ "include": "#string"
+ },
+ {
+ "include": "#comment"
+ },
+ {
+ "include": "#number"
+ },
+ {
+ "match": "\\b(false|true|unit)\\b",
+ "name": "constant.language.mlir"
+ },
+ {
+ "begin": "\\b(affine_map|affine_set)\\s*\\<",
+ "beginCaptures": {
+ "1": {
+ "name": "constant.language.mlir"
+ }
+ },
+ "patterns": [
+ {
+ "match": "\\b(ceildiv|floordiv|mod|symbol)\\b",
+ "name": "entity.name.function.mlir"
+ },
+ {
+ "match": "\\b([\\w\\.\\$\\-]+)\\b",
+ "name": "variable.mlir"
+ },
+ {
+ "include": "#number"
+ }
+ ],
+ "end": "\\)\\>"
+ },
+ {
+ "begin": "\\b(dense|opaque|sparse)\\s*\\<",
+ "beginCaptures": {
+ "1": {
+ "name": "constant.language.mlir"
+ }
+ },
+ "patterns": [
+ {
+ "include": "#attribute_value"
+ }
+ ],
+ "end": "\\>"
+ },
+ {
+ "begin": "\\[",
+ "patterns": [
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "include": "#operation_body"
+ }
+ ],
+ "end": "\\]"
+ },
+ {
+ "begin": "\\{",
+ "patterns": [
+ {
+ "include": "#attribute_dictionary_body"
+ }
+ ],
+ "end": "\\}"
+ },
+ {
+ "match": "(\\@[\\w+\\$\\-\\.]*)",
+ "name": "entity.name.function.mlir"
+ },
+ {
+ "begin": "(\\#[\\w\\$\\-\\.]+)\\<",
+ "beginCaptures": {
+ "1": {
+ "name": "constant.language.mlir"
+ }
+ },
+ "patterns": [
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "match": "\\-\\>|\\>\\="
+ },
+ {
+ "include": "#bare_identifier"
+ }
+ ],
+ "end": "\\>"
+ },
+ {
+ "match": "\\#[\\w\\$\\-\\.]+\\b",
+ "name": "constant.language.mlir"
+ },
+ {
+ "include": "#type_value"
+ },
+ {
+ "begin": "\\<",
+ "patterns": [
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "include": "#bare_identifier"
+ }
+ ],
+ "end": "\\>"
+ }
+ ]
},
- {
- "include": "#branch_target"
+ "attribute_dictionary_body": {
+ "patterns": [
+ {
+ "include": "#comment"
+ },
+ {
+ "include": "#string"
+ },
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "match": "(\\%)?\\b([\\w\\.\\-\\$\\:0-9]+)\\b\\s*(?=\\=|\\,|\\})",
+ "name": "variable.other.mlir"
+ }
+ ]
},
- {
- "include": "#attribute"
+ "type_value": {
+ "patterns": [
+ {
+ "begin": "(\\![\\w\\$\\-\\.]+)\\<",
+ "beginCaptures": {
+ "1": {
+ "name": "entity.name.type.mlir"
+ }
+ },
+ "patterns": [
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "match": "\\-\\>|\\>\\=",
+ "name": "punctuation.other.mlir"
+ },
+ {
+ "include": "#bare_identifier"
+ }
+ ],
+ "end": "\\>"
+ },
+ {
+ "match": "\\![\\w\\$\\-\\.]+\\b",
+ "name": "entity.name.type.mlir"
+ },
+ {
+ "begin": "(complex|memref|tensor|tuple|vector)\\<",
+ "beginCaptures": {
+ "1": {
+ "name": "entity.name.type.mlir"
+ }
+ },
+ "patterns": [
+ {
+ "match": "[\\?x0-9\\[\\]]+",
+ "captures": {
+ "0": {
+ "patterns": [
+ {
+ "include": "#number"
+ }
+ ]
+ }
+ }
+ },
+ {
+ "include": "#attribute_value"
+ },
+ {
+ "match": "\\-\\>|\\>\\=",
+ "name": "punctuation.other.mlir"
+ },
+ {
+ "include": "#bare_identifier"
+ }
+ ],
+ "end": "\\>"
+ },
+ {
+ "match": "bf16|f16|f32|f64|f80|f128|index|none|(u|s)?i[0-9]+",
+ "name": "entity.name.type.mlir"
+ }
+ ]
},
- {
- "include": "#types"
+ "bare_identifier": {
+ "match": "\\b([\\w\\.\\$\\-]+)\\b",
+ "name": "keyword.other.mlir"
},
- {
- "include": "#integer"
+ "ssa_value": {
+ "match": "\\%[\\w\\.\\$\\:\\#]+",
+ "name": "variable.other.mlir"
+ },
+ "block": {
+ "match": "\\^[\\w\\d_$\\.-]+",
+ "name": "keyword.control.mlir"
}
- ],
- "name": "MLIR",
+ },
"scopeName": "source.mlir"
-}
+}
\ No newline at end of file
More information about the Mlir-commits
mailing list