Skip to content

Commit

Permalink
Add support for attributes (with no parameters) (#15)
Browse files Browse the repository at this point in the history
* Add test for attribute syntax

* Update grammar files

* Add baseline for new test
  • Loading branch information
Dekkonot authored Jun 22, 2024
1 parent d1a7398 commit 5febad5
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Luau.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ patterns:
- include: "#table"
- include: "#type_cast"
- include: "#type_annotation"
- include: "#attribute"

repository:
function-definition:
Expand Down Expand Up @@ -78,6 +79,7 @@ repository:
"1": { name: storage.modifier.local.luau }
patterns:
- include: "#comment"
- include: "#attribute"
- begin: "(:)"
beginCaptures:
"1": { name: keyword.operator.type.luau }
Expand Down Expand Up @@ -398,3 +400,12 @@ repository:
"1": { name: variable.parameter.luau }
"2": { name: keyword.operator.type.luau }
- include: "#type_literal"

attribute:
patterns:
# TODO: support parameters for attributes as defined in the RFC
- name: meta.attribute.luau
match: "(@)({{identifier}})"
captures:
"1": { name: keyword.operator.attribute.luau }
"2": { name: storage.type.attribute.luau}
33 changes: 33 additions & 0 deletions Luau.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
<key>include</key>
<string>#type_annotation</string>
</dict>
<dict>
<key>include</key>
<string>#attribute</string>
</dict>
</array>
<key>repository</key>
<dict>
Expand Down Expand Up @@ -224,6 +228,10 @@
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>include</key>
<string>#attribute</string>
</dict>
<dict>
<key>begin</key>
<string>(:)</string>
Expand Down Expand Up @@ -1138,6 +1146,31 @@
</dict>
</array>
</dict>
<key>attribute</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>meta.attribute.luau</string>
<key>match</key>
<string>(@)([a-zA-Z_][a-zA-Z0-9_]*)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.attribute.luau</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.type.attribute.luau</string>
</dict>
</dict>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
22 changes: 22 additions & 0 deletions Luau.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
},
{
"include": "#type_annotation"
},
{
"include": "#attribute"
}
],
"repository": {
Expand Down Expand Up @@ -150,6 +153,9 @@
{
"include": "#comment"
},
{
"include": "#attribute"
},
{
"begin": "(:)",
"beginCaptures": {
Expand Down Expand Up @@ -749,6 +755,22 @@
]
}
]
},
"attribute": {
"patterns": [
{
"name": "meta.attribute.luau",
"match": "(@)([a-zA-Z_][a-zA-Z0-9_]*)",
"captures": {
"1": {
"name": "keyword.operator.attribute.luau"
},
"2": {
"name": "storage.type.attribute.luau"
}
}
}
]
}
}
}
Loading

0 comments on commit 5febad5

Please sign in to comment.