Add start of textmate language grammar.
Basic* grammar to start of with, this doesn't handle custom ops and doesn't handle ops with regions. But useful enough to make reading the .mlir files easier. Followed the approach used for emacs & vim and placed in separate directory under utils. * I got a little bit carried away trying to handle attributes and tried to do some custom op printing handling, but finally abandoned it. Also first time writing a textmate grammar so I assume a lot can be improved :) PiperOrigin-RevId: 262985490
This commit is contained in:
parent
89fc1b5b3b
commit
59cfb460cc
387
third_party/mlir/utils/textmate/mlir.json
vendored
Normal file
387
third_party/mlir/utils/textmate/mlir.json
vendored
Normal file
@ -0,0 +1,387 @@
|
||||
{
|
||||
"fileTypes" : [
|
||||
"mlir"
|
||||
],
|
||||
"repository" : {
|
||||
"container" : {
|
||||
"end" : ">",
|
||||
"begin" : "(complex|tuple)<",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.container.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#types"
|
||||
}
|
||||
],
|
||||
"name" : "meta.types.container.mlir"
|
||||
},
|
||||
"loc" : {
|
||||
"end" : "\\)",
|
||||
"begin" : "\\b(loc)\\(",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.loc.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#loc_fusedloc"
|
||||
},
|
||||
{
|
||||
"include" : "#loc_nameloc"
|
||||
},
|
||||
{
|
||||
"include" : "#op_generic"
|
||||
}
|
||||
],
|
||||
"name" : "meta.loc.mlir"
|
||||
},
|
||||
"integer" : {
|
||||
"match" : "[1-9][0-9]*",
|
||||
"name" : "constant.numeric.mlir"
|
||||
},
|
||||
"op" : {
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#terminator"
|
||||
},
|
||||
{
|
||||
"include" : "#op_generic"
|
||||
}
|
||||
]
|
||||
},
|
||||
"loc_nameloc" : {
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#string"
|
||||
}
|
||||
],
|
||||
"name" : "meta.location.mlir"
|
||||
},
|
||||
"bool_constant" : {
|
||||
"match" : "\\b(true|false)\\b",
|
||||
"captures" : {
|
||||
"1" : {
|
||||
"name" : "constant.language.mlir"
|
||||
}
|
||||
},
|
||||
"name" : "constant.language.mlir"
|
||||
},
|
||||
"string" : {
|
||||
"end" : "\"",
|
||||
"begin" : "\"",
|
||||
"beginCaptures" : {
|
||||
"0" : {
|
||||
"name" : "punctuation.definition.string.begin.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"match" : "\\\\[nt\"]",
|
||||
"name" : "constant.character.escape.mlir"
|
||||
},
|
||||
{
|
||||
"match" : "\\\\.",
|
||||
"name" : "invalid.illegal.mlir"
|
||||
}
|
||||
],
|
||||
"endCaptures" : {
|
||||
"0" : {
|
||||
"name" : "punctuation.definition.string.end.mlir"
|
||||
}
|
||||
},
|
||||
"name" : "string.quoted.double.mlir"
|
||||
},
|
||||
"terminator" : {
|
||||
"end" : "\\n",
|
||||
"begin" : "(br|cond_br|return)",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.control.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#branch_target"
|
||||
},
|
||||
{
|
||||
"include" : "#identifier"
|
||||
},
|
||||
{
|
||||
"include" : "#types"
|
||||
},
|
||||
{
|
||||
"include" : "#loc"
|
||||
}
|
||||
]
|
||||
},
|
||||
"region" : {
|
||||
"end" : "(?=})",
|
||||
"begin" : "{",
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#branch_target"
|
||||
},
|
||||
{
|
||||
"include" : "#op"
|
||||
},
|
||||
{
|
||||
"include" : "#attributes"
|
||||
},
|
||||
{
|
||||
"include" : "#comment"
|
||||
},
|
||||
{
|
||||
"include" : "#string"
|
||||
}
|
||||
],
|
||||
"name" : "meta.region.mlir"
|
||||
},
|
||||
"constant" : {
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#bool_constant"
|
||||
},
|
||||
{
|
||||
"include" : "#integer"
|
||||
},
|
||||
{
|
||||
"include" : "#string"
|
||||
}
|
||||
],
|
||||
"name" : "constants.other.mlir"
|
||||
},
|
||||
"loc_fusedloc" : {
|
||||
"end" : "\\]",
|
||||
"begin" : "(fused)(<.*>)?\\[",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.loc.mlir"
|
||||
},
|
||||
"2" : {
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#string"
|
||||
}
|
||||
],
|
||||
"name" : "meta.location.mlir"
|
||||
},
|
||||
"branch_target" : {
|
||||
"end" : "[:,\\n]",
|
||||
"begin" : "(\\^bb[\\w\\d_$\\.-]+)",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "entity.name.label.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#branch_target_region"
|
||||
},
|
||||
{
|
||||
"include" : "#comment"
|
||||
}
|
||||
],
|
||||
"name" : "meta.branch_target.mlir"
|
||||
},
|
||||
"types" : {
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#container"
|
||||
},
|
||||
{
|
||||
"include" : "#shaped_container"
|
||||
},
|
||||
{
|
||||
"include" : "#standard_simple_types"
|
||||
}
|
||||
],
|
||||
"name" : "meta.types.mlir"
|
||||
},
|
||||
"attribute_keywords" : {
|
||||
"match" : "\\b(dense|none|opaque|sparse)\\b",
|
||||
"captures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.attributes.mlir"
|
||||
}
|
||||
}
|
||||
},
|
||||
"identifier" : {
|
||||
"match" : "[\\%#][a-zA-Z0-9][\\w\\d_]*",
|
||||
"captures" : {
|
||||
"0" : {
|
||||
"name" : "variable.mlir"
|
||||
}
|
||||
},
|
||||
"name" : "meta.identifier.mlir"
|
||||
},
|
||||
"shaped_container" : {
|
||||
"end" : ">",
|
||||
"begin" : "(memref|tensor|vector)<",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.shaped_container.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#types"
|
||||
}
|
||||
],
|
||||
"name" : "meta.types.standard.shaped_container.mlir"
|
||||
},
|
||||
"standard_simple_types" : {
|
||||
"match" : "\\b(index|i[1-9]\\d*|f16|bf16|f32|f64)\\b",
|
||||
"captures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.types.standard.simple.mlir"
|
||||
}
|
||||
},
|
||||
"name" : "meta.types.standard.simple.mlir"
|
||||
},
|
||||
"function_attributes" : {
|
||||
"end" : "}",
|
||||
"begin" : "(attributes)\\s*{",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.attributes.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#constant"
|
||||
}
|
||||
],
|
||||
"name" : "meta.attributes.function.mlir"
|
||||
},
|
||||
"op_generic" : {
|
||||
"end" : "\\n",
|
||||
"begin" : "((%[\\w\\d_]*)\\s*)=\\s*(?=\")",
|
||||
"beginCaptures" : {
|
||||
"2" : {
|
||||
"name" : "variable.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#attributes"
|
||||
},
|
||||
{
|
||||
"include" : "#identifier"
|
||||
},
|
||||
{
|
||||
"include" : "#loc"
|
||||
},
|
||||
{
|
||||
"include" : "#string"
|
||||
},
|
||||
{
|
||||
"include" : "#types"
|
||||
}
|
||||
],
|
||||
"name" : "meta.op.generic.mlir"
|
||||
},
|
||||
"function_results" : {
|
||||
"end" : "\\)",
|
||||
"begin" : "->\\s*\\(",
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#types"
|
||||
}
|
||||
],
|
||||
"name" : "meta.function.results.mlir"
|
||||
},
|
||||
"branch_target_region" : {
|
||||
"end" : "\\)",
|
||||
"begin" : "\\(",
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#identifier"
|
||||
},
|
||||
{
|
||||
"include" : "#types"
|
||||
}
|
||||
],
|
||||
"name" : "meta.branch_target.mlir"
|
||||
},
|
||||
"comment" : {
|
||||
"match" : "\/\/.*$",
|
||||
"name" : "comment.line.double-slash.mlir"
|
||||
},
|
||||
"attributes" : {
|
||||
"end" : "}",
|
||||
"begin" : "{",
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#attribute_keywords"
|
||||
},
|
||||
{
|
||||
"include" : "#constant"
|
||||
}
|
||||
],
|
||||
"name" : "meta.attributes.mlir"
|
||||
},
|
||||
"function_params" : {
|
||||
"end" : ")",
|
||||
"begin" : "(",
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#identifier"
|
||||
},
|
||||
{
|
||||
"include" : "#types"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"scope" : "mlir",
|
||||
"patterns" : [
|
||||
{
|
||||
"match" : "\\b(module)\\b",
|
||||
"name" : "keyword.module.mlir"
|
||||
},
|
||||
{
|
||||
"end" : "}",
|
||||
"begin" : "\\b(func)\\b\\s*(@[a-zA-Z_][a-zA-Z_0-9\\.]*)",
|
||||
"beginCaptures" : {
|
||||
"1" : {
|
||||
"name" : "keyword.function.mlir"
|
||||
},
|
||||
"2" : {
|
||||
"name" : "entity.name.function.mlir"
|
||||
}
|
||||
},
|
||||
"patterns" : [
|
||||
{
|
||||
"include" : "#function_params"
|
||||
},
|
||||
{
|
||||
"include" : "#function_attributes"
|
||||
},
|
||||
{
|
||||
"include" : "#function_results"
|
||||
},
|
||||
{
|
||||
"include" : "#region"
|
||||
}
|
||||
],
|
||||
"name" : "support.function.mlir"
|
||||
},
|
||||
{
|
||||
"include" : "#comment",
|
||||
"name" : "comment.line.double-slash.mlir"
|
||||
}
|
||||
],
|
||||
"name" : "MLIR",
|
||||
"scopeName" : "source.mlir"
|
||||
}
|
Loading…
Reference in New Issue
Block a user