Skip to content

Commit

Permalink
Add support for properties, __subscript, __init
Browse files Browse the repository at this point in the history
  • Loading branch information
theHamsta committed Nov 18, 2023
1 parent 48ce28b commit f2f8719
Show file tree
Hide file tree
Showing 6 changed files with 465,395 additions and 460,302 deletions.
6 changes: 6 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ module.exports = grammar(HLSL, {
import_statement: $ => seq(optional("__exported"), "import", dotSep1($.identifier), ";"),

// TODO: fix type_hinted_declarator, add __init, add properties, add This
_field_declaration_list_item: ($, original) => choice(original, $.property_declaration, $.subscript_declaraion),
init_declaraion: $ => seq("__init", $.parameter_list, $.compound_statement),
subscript_declaraion: $ => seq("__subscript", $.parameter_list, optional($.trailing_return_type), alias(seq("{", repeat(choice($.property_get, $.property_set)), "}"), $.compound_statement)),
property_declaration: $ => seq("property", $.identifier, ":", $.type_descriptor, alias(seq("{", repeat(choice($.property_get, $.property_set)), "}"), $.compound_statement)),
property_get: $ => seq("get", $.compound_statement),
property_set: $ => seq("set", $.compound_statement)
}
});

Expand Down
336 changes: 253 additions & 83 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4376,122 +4376,135 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "field_declaration"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "field_declaration"
},
{
"type": "SYMBOL",
"name": "preproc_def"
},
{
"type": "SYMBOL",
"name": "preproc_function_def"
},
{
"type": "SYMBOL",
"name": "preproc_call"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "preproc_if_in_field_declaration_list"
},
"named": true,
"value": "preproc_if"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "preproc_ifdef_in_field_declaration_list"
},
"named": true,
"value": "preproc_ifdef"
}
]
},
{
"type": "SYMBOL",
"name": "preproc_def"
"name": "template_declaration"
},
{
"type": "SYMBOL",
"name": "preproc_function_def"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "inline_method_definition"
},
"named": true,
"value": "function_definition"
},
{
"type": "SYMBOL",
"name": "preproc_call"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constructor_or_destructor_definition"
},
"named": true,
"value": "function_definition"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "preproc_if_in_field_declaration_list"
"name": "constructor_or_destructor_declaration"
},
"named": true,
"value": "preproc_if"
"value": "declaration"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "preproc_ifdef_in_field_declaration_list"
"name": "operator_cast_definition"
},
"named": true,
"value": "preproc_ifdef"
}
]
},
{
"type": "SYMBOL",
"name": "template_declaration"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "inline_method_definition"
},
"named": true,
"value": "function_definition"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constructor_or_destructor_definition"
},
"named": true,
"value": "function_definition"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "constructor_or_destructor_declaration"
},
"named": true,
"value": "declaration"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_cast_definition"
},
"named": true,
"value": "function_definition"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_cast_declaration"
},
"named": true,
"value": "declaration"
},
{
"type": "SYMBOL",
"name": "friend_declaration"
},
{
"type": "SEQ",
"members": [
"value": "function_definition"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "operator_cast_declaration"
},
"named": true,
"value": "declaration"
},
{
"type": "SYMBOL",
"name": "access_specifier"
"name": "friend_declaration"
},
{
"type": "STRING",
"value": ":"
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "access_specifier"
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "SYMBOL",
"name": "alias_declaration"
},
{
"type": "SYMBOL",
"name": "using_declaration"
},
{
"type": "SYMBOL",
"name": "type_definition"
},
{
"type": "SYMBOL",
"name": "static_assert_declaration"
}
]
},
{
"type": "SYMBOL",
"name": "alias_declaration"
},
{
"type": "SYMBOL",
"name": "using_declaration"
"name": "property_declaration"
},
{
"type": "SYMBOL",
"name": "type_definition"
},
{
"type": "SYMBOL",
"name": "static_assert_declaration"
"name": "subscript_declaraion"
}
]
},
Expand Down Expand Up @@ -15272,6 +15285,163 @@
"value": ";"
}
]
},
"init_declaraion": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "__init"
},
{
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "SYMBOL",
"name": "compound_statement"
}
]
},
"subscript_declaraion": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "__subscript"
},
{
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "trailing_return_type"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "property_get"
},
{
"type": "SYMBOL",
"name": "property_set"
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"named": true,
"value": "compound_statement"
}
]
},
"property_declaration": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "property"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "type_descriptor"
},
{
"type": "ALIAS",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "property_get"
},
{
"type": "SYMBOL",
"name": "property_set"
}
]
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"named": true,
"value": "compound_statement"
}
]
},
"property_get": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "get"
},
{
"type": "SYMBOL",
"name": "compound_statement"
}
]
},
"property_set": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "set"
},
{
"type": "SYMBOL",
"name": "compound_statement"
}
]
}
},
"extras": [
Expand Down
Loading

0 comments on commit f2f8719

Please sign in to comment.