1 package m
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Mlir = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "MLIR",
12 Aliases: []string{"mlir"},
13 Filenames: []string{"*.mlir"},
14 MimeTypes: []string{"text/x-mlir"},
15 },
16 mlirRules,
17 ))
18
19 func mlirRules() Rules {
20 return Rules{
21 "root": {
22 Include("whitespace"),
23 {`c?"[^"]*?"`, LiteralString, nil},
24 {`\^([-a-zA-Z$._][\w\-$.0-9]*)\s*`, NameLabel, nil},
25 {`([\w\d_$.]+)\s*=`, NameLabel, nil},
26 Include("keyword"),
27 {`->`, Punctuation, nil},
28 {`@([\w_][\w\d_$.]*)`, NameFunction, nil},
29 {`[%#][\w\d_$.]+`, NameVariable, nil},
30 {`([1-9?][\d?]*\s*x)+`, LiteralNumber, nil},
31 {`0[xX][a-fA-F0-9]+`, LiteralNumber, nil},
32 {`-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?`, LiteralNumber, nil},
33 {`[=<>{}\[\]()*.,!:]|x\b`, Punctuation, nil},
34 {`[\w\d]+`, Text, nil},
35 },
36 "whitespace": {
37 {`(\n|\s)+`, Text, nil},
38 {`//.*?\n`, Comment, nil},
39 },
40 "keyword": {
41 {Words(``, ``, `constant`, `return`), KeywordType, nil},
42 {Words(``, ``, `func`, `loc`, `memref`, `tensor`, `vector`), KeywordType, nil},
43 {`bf16|f16|f32|f64|index`, Keyword, nil},
44 {`i[1-9]\d*`, Keyword, nil},
45 },
46 }
47 }
48
View as plain text