Skip to content

Commit

Permalink
feat: allow empty object types and add intersection type to types
Browse files Browse the repository at this point in the history
  • Loading branch information
4teapo authored and amaanq committed Jun 23, 2024
1 parent 5aa9b88 commit fbadc96
Show file tree
Hide file tree
Showing 4 changed files with 10,195 additions and 9,620 deletions.
5 changes: 3 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ module.exports = grammar(lua, {
$.object_type,
$.empty_type,
$.field_type,
$.intersection_type,
$.union_type,
$.optional_type,
$.literal_type,
Expand Down Expand Up @@ -194,12 +195,12 @@ module.exports = grammar(lua, {

object_type: $ => seq(
'{',
choice(
optional(choice(
commaSep1(
seq(choice($.identifier, $.object_field_type), ':', $.type),
),
commaSep1($.type),
),
)),
optional(','),
'}',
),
Expand Down
126 changes: 68 additions & 58 deletions src/grammar.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"0": "l",
"1": "u",
"2": "a",
"name": "luau",
"inherits": "lua",
"word": "identifier",
"rules": {
"chunk": {
Expand Down Expand Up @@ -3225,6 +3223,10 @@
"type": "SYMBOL",
"name": "field_type"
},
{
"type": "SYMBOL",
"name": "intersection_type"
},
{
"type": "SYMBOL",
"name": "union_type"
Expand Down Expand Up @@ -3569,98 +3571,106 @@
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "object_field_type"
}
]
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "object_field_type"
"name": "type"
}
]
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "type"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"type": "STRING",
"value": ","
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "object_field_type"
}
]
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "object_field_type"
"name": "type"
}
]
},
}
]
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
"value": ","
},
{
"type": "SYMBOL",
"name": "type"
}
]
}
]
}
}
]
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "type"
}
]
}
}
]
"type": "BLANK"
}
]
},
Expand Down
25 changes: 22 additions & 3 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
"type": "identifier",
"named": true
},
{
"type": "intersection_type",
"named": true
},
{
"type": "literal_type",
"named": true
Expand Down Expand Up @@ -1014,6 +1018,21 @@
]
}
},
{
"type": "intersection_type",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "type",
"named": true
}
]
}
},
{
"type": "literal_type",
"named": true,
Expand Down Expand Up @@ -1097,7 +1116,7 @@
"fields": {},
"children": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "object_field_type",
Expand Down Expand Up @@ -1781,11 +1800,11 @@
},
{
"type": "number",
"named": false
"named": true
},
{
"type": "number",
"named": true
"named": false
},
{
"type": "or",
Expand Down
Loading

0 comments on commit fbadc96

Please sign in to comment.