@felixtensor/tree-sitter-mlir 0.1.1 → 0.1.2

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/grammar.js CHANGED
@@ -50,6 +50,8 @@ export default grammar({
50
50
  _digit: $ => /[0-9]/,
51
51
  integer_literal: $ => choice($._decimal_literal, $._hexadecimal_literal),
52
52
  _decimal_literal: $ => token(seq(optional(/[-+]/), repeat1(/[0-9]/))),
53
+ _unsigned_decimal_literal: $ => token(repeat1(/[0-9]/)),
54
+ _unsigned_integer_literal: $ => choice($._unsigned_decimal_literal, $._hexadecimal_literal),
53
55
  _hexadecimal_literal: $ => token(seq('0x', repeat1(/[0-9a-fA-F]/))),
54
56
  float_literal: $ => token(seq(
55
57
  optional(/[-+]/), repeat1(/[0-9]/), '.', repeat(/[0-9]/),
@@ -182,6 +184,15 @@ export default grammar({
182
184
  func_operation: $ => prec.right(seq(
183
185
  field('name', choice(token(prec(20, 'func.func')), token(prec(20, 'llvm.func')))),
184
186
  field('visibility', optional(choice('private', 'public'))),
187
+ // Optional leading specifier keywords between the function name and its
188
+ // symbol. Covers MLIR symbol visibility (`nested`) and the LLVM dialect's
189
+ // llvm.func linkage / calling-convention / unnamed_addr / visibility
190
+ // keywords (internal, external, linkonce, fastcc, amdgpu_kernelcc,
191
+ // local_unnamed_addr, hidden, ...). MLIR's CConv enum alone has ~50
192
+ // keywords, so rather than enumerate a brittle list we accept bare_id-
193
+ // shaped specifiers here; the trailing `@symbol` (symbol_ref_id) is an
194
+ // unambiguous terminator.
195
+ repeat(field('specifier', alias($.bare_id, $.function_specifier))),
185
196
  field('sym_name', $.symbol_ref_id),
186
197
  field('arguments', $.func_arg_list),
187
198
  field('return', optional($.func_return)),
@@ -340,7 +351,7 @@ export default grammar({
340
351
  $.type,
341
352
  prec(2, $.attribute),
342
353
  $._literal,
343
- 'dense', 'sparse', 'array', 'vector',
354
+ 'dense', 'sparse', 'array', 'vector', 'tensor', 'opaque',
344
355
  $.bare_id,
345
356
  ',', ':', '=', '->', '(', ')', '[', ']', '{', '}', '*', '?',
346
357
  '@', '#',
@@ -361,9 +372,13 @@ export default grammar({
361
372
  repeat1(seq($.dimension_separator, $._dialect_dim_primitive)))),
362
373
  _dialect_dim_primitive: $ => choice(
363
374
  prec(1, $.type),
375
+ prec(1, $._pretty_dialect_body_type),
364
376
  alias($.integer_literal, $.dimension_size),
365
377
  '?',
366
378
  '*'),
379
+ _pretty_dialect_body_type: $ => seq(
380
+ choice($.bare_id, 'array'),
381
+ $.pretty_dialect_item_body),
367
382
 
368
383
  // Builtin types
369
384
  builtin_type: $ => choice(
@@ -424,11 +439,12 @@ export default grammar({
424
439
  attribute_entry: $ => choice(
425
440
  seq(choice($.bare_id, $.string_literal), optional(seq('=', $.attribute_value))),
426
441
  // Array-valued entry (e.g. {["op.name"]} in transform dialect)
427
- seq('[', optional($._attribute_value_nobracket),
428
- repeat(seq(',', $._attribute_value_nobracket)), ']'),
442
+ $._attribute_array,
429
443
  ),
430
- attribute_value: $ => choice(seq('[', optional($._attribute_value_nobracket),
431
- repeat(seq(',', $._attribute_value_nobracket)), ']'), $._attribute_value_nobracket),
444
+ attribute_value: $ => choice($._attribute_array, $._attribute_value_nobracket),
445
+ _attribute_array: $ => seq('[', optional($._attribute_array_element),
446
+ repeat(seq(',', $._attribute_array_element)), ']'),
447
+ _attribute_array_element: $ => choice($._attribute_array, $._attribute_value_nobracket),
432
448
  _attribute_value_nobracket: $ => choice($.attribute_alias, $.dialect_attribute,
433
449
  $.builtin_attribute, $.dictionary_attribute, $._literal_and_type, $.type,
434
450
  $.function_type, $._affine_map_like, $.symbol_ref_id, $.trailing_location,
@@ -449,9 +465,13 @@ export default grammar({
449
465
  prec(1, $.affine_map),
450
466
  prec(1, $.affine_set),
451
467
  $.dense_resource_literal,
468
+ $.distinct_attribute,
452
469
  ),
453
470
  dense_resource_literal: $ => seq(token('dense_resource'), '<',
454
471
  choice($.bare_id, $.string_literal), '>'),
472
+ distinct_attribute: $ => seq(token('distinct'), '[',
473
+ alias($._unsigned_integer_literal, $.integer_literal), ']',
474
+ '<', optional($.attribute_value), '>'),
455
475
  strided_layout: $ => seq(token('strided'), '<', '[', optional($._stride_list_comma), ']',
456
476
  optional(seq(',', token('offset'), ':', $._stride_primitive)), '>'),
457
477
  _stride_list_comma: $ => seq($._stride_primitive, repeat(seq(',', $._stride_primitive))),
@@ -489,7 +509,7 @@ export default grammar({
489
509
  func_arg_list: $ => seq('(', optional(choice($.variadic,
490
510
  $._value_id_and_type_attr_list)), ')'),
491
511
  _value_id_and_type_attr_list: $ => seq($._value_id_and_type_attr,
492
- repeat(seq(',', $._value_id_and_type_attr)), optional(seq(',', $.variadic))),
512
+ repeat(seq(',', choice($._value_id_and_type_attr, $.variadic)))),
493
513
  _value_id_and_type_attr: $ => seq($._function_arg, optional($.attribute),
494
514
  optional($.trailing_location)),
495
515
  _function_arg: $ => choice(seq($.value_use, ':', choice($.type, $.function_type)), $.value_use, $.type, $.function_type),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@felixtensor/tree-sitter-mlir",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "MLIR grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
package/src/grammar.json CHANGED
@@ -103,6 +103,29 @@
103
103
  ]
104
104
  }
105
105
  },
106
+ "_unsigned_decimal_literal": {
107
+ "type": "TOKEN",
108
+ "content": {
109
+ "type": "REPEAT1",
110
+ "content": {
111
+ "type": "PATTERN",
112
+ "value": "[0-9]"
113
+ }
114
+ }
115
+ },
116
+ "_unsigned_integer_literal": {
117
+ "type": "CHOICE",
118
+ "members": [
119
+ {
120
+ "type": "SYMBOL",
121
+ "name": "_unsigned_decimal_literal"
122
+ },
123
+ {
124
+ "type": "SYMBOL",
125
+ "name": "_hexadecimal_literal"
126
+ }
127
+ ]
128
+ },
106
129
  "_hexadecimal_literal": {
107
130
  "type": "TOKEN",
108
131
  "content": {
@@ -1608,6 +1631,22 @@
1608
1631
  ]
1609
1632
  }
1610
1633
  },
1634
+ {
1635
+ "type": "REPEAT",
1636
+ "content": {
1637
+ "type": "FIELD",
1638
+ "name": "specifier",
1639
+ "content": {
1640
+ "type": "ALIAS",
1641
+ "content": {
1642
+ "type": "SYMBOL",
1643
+ "name": "bare_id"
1644
+ },
1645
+ "named": true,
1646
+ "value": "function_specifier"
1647
+ }
1648
+ }
1649
+ },
1611
1650
  {
1612
1651
  "type": "FIELD",
1613
1652
  "name": "sym_name",
@@ -2872,6 +2911,14 @@
2872
2911
  "type": "STRING",
2873
2912
  "value": "vector"
2874
2913
  },
2914
+ {
2915
+ "type": "STRING",
2916
+ "value": "tensor"
2917
+ },
2918
+ {
2919
+ "type": "STRING",
2920
+ "value": "opaque"
2921
+ },
2875
2922
  {
2876
2923
  "type": "SYMBOL",
2877
2924
  "name": "bare_id"
@@ -3109,6 +3156,14 @@
3109
3156
  "name": "type"
3110
3157
  }
3111
3158
  },
3159
+ {
3160
+ "type": "PREC",
3161
+ "value": 1,
3162
+ "content": {
3163
+ "type": "SYMBOL",
3164
+ "name": "_pretty_dialect_body_type"
3165
+ }
3166
+ },
3112
3167
  {
3113
3168
  "type": "ALIAS",
3114
3169
  "content": {
@@ -3128,6 +3183,28 @@
3128
3183
  }
3129
3184
  ]
3130
3185
  },
3186
+ "_pretty_dialect_body_type": {
3187
+ "type": "SEQ",
3188
+ "members": [
3189
+ {
3190
+ "type": "CHOICE",
3191
+ "members": [
3192
+ {
3193
+ "type": "SYMBOL",
3194
+ "name": "bare_id"
3195
+ },
3196
+ {
3197
+ "type": "STRING",
3198
+ "value": "array"
3199
+ }
3200
+ ]
3201
+ },
3202
+ {
3203
+ "type": "SYMBOL",
3204
+ "name": "pretty_dialect_item_body"
3205
+ }
3206
+ ]
3207
+ },
3131
3208
  "builtin_type": {
3132
3209
  "type": "CHOICE",
3133
3210
  "members": [
@@ -3839,45 +3916,8 @@
3839
3916
  ]
3840
3917
  },
3841
3918
  {
3842
- "type": "SEQ",
3843
- "members": [
3844
- {
3845
- "type": "STRING",
3846
- "value": "["
3847
- },
3848
- {
3849
- "type": "CHOICE",
3850
- "members": [
3851
- {
3852
- "type": "SYMBOL",
3853
- "name": "_attribute_value_nobracket"
3854
- },
3855
- {
3856
- "type": "BLANK"
3857
- }
3858
- ]
3859
- },
3860
- {
3861
- "type": "REPEAT",
3862
- "content": {
3863
- "type": "SEQ",
3864
- "members": [
3865
- {
3866
- "type": "STRING",
3867
- "value": ","
3868
- },
3869
- {
3870
- "type": "SYMBOL",
3871
- "name": "_attribute_value_nobracket"
3872
- }
3873
- ]
3874
- }
3875
- },
3876
- {
3877
- "type": "STRING",
3878
- "value": "]"
3879
- }
3880
- ]
3919
+ "type": "SYMBOL",
3920
+ "name": "_attribute_array"
3881
3921
  }
3882
3922
  ]
3883
3923
  },
@@ -3885,46 +3925,63 @@
3885
3925
  "type": "CHOICE",
3886
3926
  "members": [
3887
3927
  {
3888
- "type": "SEQ",
3928
+ "type": "SYMBOL",
3929
+ "name": "_attribute_array"
3930
+ },
3931
+ {
3932
+ "type": "SYMBOL",
3933
+ "name": "_attribute_value_nobracket"
3934
+ }
3935
+ ]
3936
+ },
3937
+ "_attribute_array": {
3938
+ "type": "SEQ",
3939
+ "members": [
3940
+ {
3941
+ "type": "STRING",
3942
+ "value": "["
3943
+ },
3944
+ {
3945
+ "type": "CHOICE",
3889
3946
  "members": [
3890
3947
  {
3891
- "type": "STRING",
3892
- "value": "["
3893
- },
3894
- {
3895
- "type": "CHOICE",
3896
- "members": [
3897
- {
3898
- "type": "SYMBOL",
3899
- "name": "_attribute_value_nobracket"
3900
- },
3901
- {
3902
- "type": "BLANK"
3903
- }
3904
- ]
3905
- },
3906
- {
3907
- "type": "REPEAT",
3908
- "content": {
3909
- "type": "SEQ",
3910
- "members": [
3911
- {
3912
- "type": "STRING",
3913
- "value": ","
3914
- },
3915
- {
3916
- "type": "SYMBOL",
3917
- "name": "_attribute_value_nobracket"
3918
- }
3919
- ]
3920
- }
3948
+ "type": "SYMBOL",
3949
+ "name": "_attribute_array_element"
3921
3950
  },
3922
3951
  {
3923
- "type": "STRING",
3924
- "value": "]"
3952
+ "type": "BLANK"
3925
3953
  }
3926
3954
  ]
3927
3955
  },
3956
+ {
3957
+ "type": "REPEAT",
3958
+ "content": {
3959
+ "type": "SEQ",
3960
+ "members": [
3961
+ {
3962
+ "type": "STRING",
3963
+ "value": ","
3964
+ },
3965
+ {
3966
+ "type": "SYMBOL",
3967
+ "name": "_attribute_array_element"
3968
+ }
3969
+ ]
3970
+ }
3971
+ },
3972
+ {
3973
+ "type": "STRING",
3974
+ "value": "]"
3975
+ }
3976
+ ]
3977
+ },
3978
+ "_attribute_array_element": {
3979
+ "type": "CHOICE",
3980
+ "members": [
3981
+ {
3982
+ "type": "SYMBOL",
3983
+ "name": "_attribute_array"
3984
+ },
3928
3985
  {
3929
3986
  "type": "SYMBOL",
3930
3987
  "name": "_attribute_value_nobracket"
@@ -4109,6 +4166,10 @@
4109
4166
  {
4110
4167
  "type": "SYMBOL",
4111
4168
  "name": "dense_resource_literal"
4169
+ },
4170
+ {
4171
+ "type": "SYMBOL",
4172
+ "name": "distinct_attribute"
4112
4173
  }
4113
4174
  ]
4114
4175
  },
@@ -4145,6 +4206,55 @@
4145
4206
  }
4146
4207
  ]
4147
4208
  },
4209
+ "distinct_attribute": {
4210
+ "type": "SEQ",
4211
+ "members": [
4212
+ {
4213
+ "type": "TOKEN",
4214
+ "content": {
4215
+ "type": "STRING",
4216
+ "value": "distinct"
4217
+ }
4218
+ },
4219
+ {
4220
+ "type": "STRING",
4221
+ "value": "["
4222
+ },
4223
+ {
4224
+ "type": "ALIAS",
4225
+ "content": {
4226
+ "type": "SYMBOL",
4227
+ "name": "_unsigned_integer_literal"
4228
+ },
4229
+ "named": true,
4230
+ "value": "integer_literal"
4231
+ },
4232
+ {
4233
+ "type": "STRING",
4234
+ "value": "]"
4235
+ },
4236
+ {
4237
+ "type": "STRING",
4238
+ "value": "<"
4239
+ },
4240
+ {
4241
+ "type": "CHOICE",
4242
+ "members": [
4243
+ {
4244
+ "type": "SYMBOL",
4245
+ "name": "attribute_value"
4246
+ },
4247
+ {
4248
+ "type": "BLANK"
4249
+ }
4250
+ ]
4251
+ },
4252
+ {
4253
+ "type": "STRING",
4254
+ "value": ">"
4255
+ }
4256
+ ]
4257
+ },
4148
4258
  "strided_layout": {
4149
4259
  "type": "SEQ",
4150
4260
  "members": [
@@ -4805,32 +4915,20 @@
4805
4915
  "value": ","
4806
4916
  },
4807
4917
  {
4808
- "type": "SYMBOL",
4809
- "name": "_value_id_and_type_attr"
4918
+ "type": "CHOICE",
4919
+ "members": [
4920
+ {
4921
+ "type": "SYMBOL",
4922
+ "name": "_value_id_and_type_attr"
4923
+ },
4924
+ {
4925
+ "type": "SYMBOL",
4926
+ "name": "variadic"
4927
+ }
4928
+ ]
4810
4929
  }
4811
4930
  ]
4812
4931
  }
4813
- },
4814
- {
4815
- "type": "CHOICE",
4816
- "members": [
4817
- {
4818
- "type": "SEQ",
4819
- "members": [
4820
- {
4821
- "type": "STRING",
4822
- "value": ","
4823
- },
4824
- {
4825
- "type": "SYMBOL",
4826
- "name": "variadic"
4827
- }
4828
- ]
4829
- },
4830
- {
4831
- "type": "BLANK"
4832
- }
4833
- ]
4834
4932
  }
4835
4933
  ]
4836
4934
  },
@@ -378,6 +378,10 @@
378
378
  "type": "dense_resource_literal",
379
379
  "named": true
380
380
  },
381
+ {
382
+ "type": "distinct_attribute",
383
+ "named": true
384
+ },
381
385
  {
382
386
  "type": "strided_layout",
383
387
  "named": true
@@ -711,6 +715,10 @@
711
715
  "multiple": true,
712
716
  "required": true,
713
717
  "types": [
718
+ {
719
+ "type": "bare_id",
720
+ "named": true
721
+ },
714
722
  {
715
723
  "type": "dimension_separator",
716
724
  "named": true
@@ -719,6 +727,10 @@
719
727
  "type": "dimension_size",
720
728
  "named": true
721
729
  },
730
+ {
731
+ "type": "pretty_dialect_item_body",
732
+ "named": true
733
+ },
722
734
  {
723
735
  "type": "type",
724
736
  "named": true
@@ -793,6 +805,25 @@
793
805
  "named": true,
794
806
  "fields": {}
795
807
  },
808
+ {
809
+ "type": "distinct_attribute",
810
+ "named": true,
811
+ "fields": {},
812
+ "children": {
813
+ "multiple": true,
814
+ "required": true,
815
+ "types": [
816
+ {
817
+ "type": "attribute_value",
818
+ "named": true
819
+ },
820
+ {
821
+ "type": "integer_literal",
822
+ "named": true
823
+ }
824
+ ]
825
+ }
826
+ },
796
827
  {
797
828
  "type": "entry_block",
798
829
  "named": true,
@@ -976,6 +1007,16 @@
976
1007
  }
977
1008
  ]
978
1009
  },
1010
+ "specifier": {
1011
+ "multiple": true,
1012
+ "required": false,
1013
+ "types": [
1014
+ {
1015
+ "type": "function_specifier",
1016
+ "named": true
1017
+ }
1018
+ ]
1019
+ },
979
1020
  "sym_name": {
980
1021
  "multiple": false,
981
1022
  "required": true,
@@ -2117,6 +2158,10 @@
2117
2158
  "type": "dimension_separator",
2118
2159
  "named": true
2119
2160
  },
2161
+ {
2162
+ "type": "distinct",
2163
+ "named": false
2164
+ },
2120
2165
  {
2121
2166
  "type": "escape_sequence",
2122
2167
  "named": true
@@ -2137,6 +2182,10 @@
2137
2182
  "type": "func.func",
2138
2183
  "named": false
2139
2184
  },
2185
+ {
2186
+ "type": "function_specifier",
2187
+ "named": true
2188
+ },
2140
2189
  {
2141
2190
  "type": "fused",
2142
2191
  "named": false