xref: /llvm-project/mlir/utils/vscode/pdll-grammar.json (revision 1febbd67aa9cf31119398dde27d2dbf016de351e)
1{
2  "name": "PDLL",
3  "fileTypes": [
4    "pdll"
5  ],
6  "patterns": [
7    {
8      "include": "#comment"
9    },
10    {
11      "include": "#string"
12    },
13    {
14      "include": "#string_block"
15    },
16    {
17      "include": "#integer"
18    },
19    {
20      "include": "#include"
21    },
22    {
23      "include": "#user_constraint"
24    },
25    {
26      "include": "#user_rewrite"
27    },
28    {
29      "include": "#pattern"
30    },
31    {
32      "include": "#inside_pattern"
33    }
34  ],
35  "repository": {
36    "comment": {
37      "match": "\/\/.*$",
38      "name": "comment.line.double-slash.pdll"
39    },
40    "string": {
41      "name": "string.quoted.double.pdll",
42      "begin": "\"",
43      "end": "\"",
44      "beginCaptures": {
45        "0": {
46          "name": "punctuation.definition.string.begin.pdll"
47        }
48      },
49      "patterns": [
50        {
51          "match": "\\\\[nt\"]",
52          "name": "constant.character.escape.pdll"
53        },
54        {
55          "match": "\\\\.",
56          "name": "invalid.illegal.pdll"
57        }
58      ],
59      "endCaptures": {
60        "0": {
61          "name": "punctuation.definition.string.end.pdll"
62        }
63      }
64    },
65    "string_block": {
66      "name": "string.quoted.triple.pdll",
67      "begin": "\\[{",
68      "end": "}]",
69      "beginCaptures": {
70        "0": {
71          "name": "punctuation.definition.string.begin.pdll"
72        }
73      },
74      "patterns": [
75        {
76          "match": "\\\\[nt\"]",
77          "name": "constant.character.escape.pdll"
78        },
79        {
80          "match": "\\\\.",
81          "name": "invalid.illegal.pdll"
82        }
83      ],
84      "endCaptures": {
85        "0": {
86          "name": "punctuation.definition.string.end.pdll"
87        }
88      }
89    },
90    "integer": {
91      "match": "[0-9]+",
92      "name": "constant.numeric.pdll"
93    },
94    "include": {
95      "patterns": [
96        {
97          "match": "(#include)",
98          "name": "keyword.control.pdll"
99        }
100      ]
101    },
102    "argument_or_result_list": {
103      "patterns": [
104        {
105          "match": "\\b([aA-zZ_0-9]*)\\b\\s*:\\s*([aA-zZ_0-9]+)\\b(\\<([^\\>]+)\\>)?",
106          "captures": {
107            "1": {
108              "name": "variable.parameter.pdll"
109            },
110            "2": {
111              "name": "entity.name.type.pdll"
112            },
113            "4": {
114              "name": "variable.other.enummember.pdll"
115            }
116          }
117        },
118        {
119          "match": "(\\(|\\>|,)\\s*([aA-zZ_0-9]+)\\b(\\<([^\\>]+)\\>)?\\s*(?=[^:])",
120          "captures": {
121            "2": {
122              "name": "entity.name.type.pdll"
123            },
124            "4": {
125              "name": "variable.other.enummember.pdll"
126            }
127          }
128        }
129      ]
130    },
131    "user_constraint": {
132      "patterns": [
133        {
134          "begin": "\\b(Constraint)\\b\\s*(\\b[aA-zZ_0-9]*\\b)?",
135          "beginCaptures": {
136            "1": {
137              "name": "keyword.other.pdll"
138            },
139            "2": {
140              "name": "entity.name.type.pdll"
141            }
142          },
143          "patterns": [
144            {
145              "begin": "(\\[{)",
146              "patterns": [
147                {
148                  "include": "source.cpp"
149                }
150              ],
151              "end": "(}])"
152            },
153            {
154              "begin": "(?=\\()",
155              "patterns": [
156                {
157                  "include": "#argument_or_result_list"
158                }
159              ],
160              "end": "\\)"
161            },
162            {
163              "include": "#argument_or_result_list"
164            },
165            {
166              "begin": "{",
167              "patterns": [
168                {
169                  "include": "#inside_pattern"
170                }
171              ],
172              "end": "(?=})"
173            },
174            {
175              "begin": "=>",
176              "patterns": [
177                {
178                  "include": "#inside_pattern"
179                }
180              ],
181              "end": "(?=;|,|\\))"
182            }
183          ],
184          "end": "(}|;|,)|(?=\\))"
185        }
186      ]
187    },
188    "user_rewrite": {
189      "patterns": [
190        {
191          "begin": "\\b(Rewrite)\\b\\s*(\\b[aA-zZ_0-9]*\\b)?",
192          "beginCaptures": {
193            "1": {
194              "name": "keyword.other.pdll"
195            },
196            "2": {
197              "name": "entity.name.function.pdll"
198            }
199          },
200          "patterns": [
201            {
202              "begin": "(\\[{)",
203              "patterns": [
204                {
205                  "include": "source.cpp"
206                }
207              ],
208              "end": "(}])"
209            },
210            {
211              "begin": "(?=\\()",
212              "patterns": [
213                {
214                  "include": "#argument_or_result_list"
215                }
216              ],
217              "end": "\\)"
218            },
219            {
220              "include": "#argument_or_result_list"
221            },
222            {
223              "begin": "{",
224              "patterns": [
225                {
226                  "include": "#inside_pattern"
227                }
228              ],
229              "end": "(?=})"
230            },
231            {
232              "begin": "=>",
233              "patterns": [
234                {
235                  "include": "#inside_pattern"
236                }
237              ],
238              "end": "(?=;|,|\\))"
239            }
240          ],
241          "end": "(}|;|,)|(?=\\))"
242        }
243      ]
244    },
245    "pattern_metadata": {
246      "patterns": [
247        {
248          "match": "\\b(with)\\b",
249          "name": "keyword.other.pdll"
250        },
251        {
252          "match": "\\b(benefit)\\b\\(([0-9]+)\\)",
253          "captures": {
254            "1": {
255              "name": "entity.name.variable.pdll"
256            },
257            "2": {
258              "name": "constant.numeric.pdll"
259            }
260          }
261        },
262        {
263          "match": "\\b(recursion)\\b",
264          "name": "entity.name.variable.pdll"
265        }
266      ]
267    },
268    "pattern": {
269      "patterns": [
270        {
271          "begin": "\\b(Pattern)\\b\\s*(\\b[aA-zZ_0-9]*\\b)?\\s*(\\bwith\\b\\s*[^\\{]*)?\\s*({)",
272          "beginCaptures": {
273            "1": {
274              "name": "keyword.other.pdll"
275            },
276            "2": {
277              "name": "entity.name.function.pdll"
278            },
279            "3": {
280              "patterns": [
281                {
282                  "include": "#pattern_metadata"
283                }
284              ]
285            }
286          },
287          "patterns": [
288            {
289              "include": "#inside_pattern"
290            }
291          ],
292          "end": "(})"
293        },
294        {
295          "begin": "\\b(Pattern)\\b\\s*(\\b[aA-zZ_0-9]*\\b)?\\s*(\\bwith\\b\\s*[^\\=]*)?\\s*(=>)",
296          "beginCaptures": {
297            "1": {
298              "name": "keyword.other.pdll"
299            },
300            "2": {
301              "name": "entity.name.function.pdll"
302            },
303            "3": {
304              "patterns": [
305                {
306                  "include": "#pattern_metadata"
307                }
308              ]
309            }
310          },
311          "patterns": [
312            {
313              "include": "#inside_pattern"
314            }
315          ],
316          "end": ";"
317        }
318      ]
319    },
320    "inside_pattern": {
321      "patterns": [
322        {
323          "match": "\\b(erase|let|replace|return|rewrite|with)\\b",
324          "captures": {
325            "1": {
326              "name": "keyword.control.pdll"
327            }
328          }
329        },
330        {
331          "include": "#expressions"
332        }
333      ]
334    },
335    "variable_constraint": {
336      "patterns": [
337        {
338          "match": "\\b(Op)<([a-zA-Z0-9_\\.$-]*)>",
339          "captures": {
340            "1": {
341              "name": "entity.name.type.pdll"
342            },
343            "2": {
344              "name": "variable.other.enummember.pdll"
345            }
346          }
347        },
348        {
349          "begin": "<",
350          "patterns": [
351            {
352              "include": "#expressions"
353            }
354          ],
355          "end": ">"
356        },
357        {
358          "match": "[a-zA-Z_0-9]+",
359          "name": "entity.name.type.pdll"
360        }
361      ]
362    },
363    "variable_definition": {
364      "patterns": [
365        {
366          "begin": "\\b([aA-zZ_0-9]*)\\b\\s*:\\s*\\[",
367          "beginCaptures": {
368            "1": {
369              "name": "entity.name.variable.pdll"
370            }
371          },
372          "patterns": [
373            {
374              "include": "#variable_constraint"
375            }
376          ],
377          "end": "\\]"
378        },
379        {
380          "match": "\\b([aA-zZ_0-9]*)\\b\\s*:\\s*([aA-zZ_0-9]+(\\<([^\\>]+)\\>)?)",
381          "captures": {
382            "1": {
383              "name": "entity.name.variable.pdll"
384            },
385            "2": {
386              "patterns": [
387                {
388                  "include": "#variable_constraint"
389                }
390              ]
391            }
392          }
393        }
394      ]
395    },
396    "expressions": {
397      "patterns": [
398        {
399          "include": "#user_constraint"
400        },
401        {
402          "include": "#user_rewrite"
403        },
404        {
405          "include": "#attr_expr"
406        },
407        {
408          "include": "#op_expr"
409        },
410        {
411          "include": "#type_expr"
412        },
413        {
414          "include": "#call_expr"
415        },
416        {
417          "include": "#variable_definition"
418        },
419        {
420          "include": "#identifier_expr"
421        },
422        {
423          "include": "#string"
424        },
425        {
426          "include": "#string_block"
427        },
428        {
429          "include": "#comment"
430        },
431        {
432          "begin": "{",
433          "patterns": [
434            {
435              "include": "#inside_pattern"
436            }
437          ],
438          "end": "}"
439        },
440        {
441          "begin": "\\(",
442          "patterns": [
443            {
444              "include": "#expressions"
445            }
446          ],
447          "end": "\\)"
448        }
449      ]
450    },
451    "attr_expr": {
452      "patterns": [
453        {
454          "begin": "(attr)<",
455          "beginCaptures": {
456            "1": {
457              "name": "keyword.other.pdll"
458            }
459          },
460          "patterns": [
461            {
462              "include": "#string"
463            },
464            {
465              "include": "#string_block"
466            }
467          ],
468          "end": ">"
469        }
470      ]
471    },
472    "call_expr": {
473      "begin": "\\b([a-zA-Z0-9_]+)\\(",
474      "beginCaptures": {
475        "1": {
476          "name": "entity.name.variable.pdll"
477        }
478      },
479      "patterns": [
480        {
481          "include": "#expressions"
482        }
483      ],
484      "end": "\\)"
485    },
486    "identifier_expr": {
487      "match": "\\b([a-zA-Z0-9_]+)\\b",
488      "name": "entity.name.variable.pdll"
489    },
490    "op_expr": {
491      "match": "\\b(op)<([0-9a-zA-Z_\\.]*)>",
492      "captures": {
493        "1": {
494          "name": "keyword.other.pdll"
495        },
496        "2": {
497          "name": "variable.other.enummember.pdll"
498        }
499      }
500    },
501    "type_expr": {
502      "patterns": [
503        {
504          "begin": "\\b(type)<",
505          "beginCaptures": {
506            "1": {
507              "name": "keyword.other.pdll"
508            }
509          },
510          "patterns": [
511            {
512              "include": "#string"
513            },
514            {
515              "include": "#string_block"
516            }
517          ],
518          "end": ">"
519        }
520      ]
521    }
522  },
523  "scopeName": "source.pdll"
524}