Skip to content

Commit

Permalink
feat: add support for function overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
theHamsta committed Jul 25, 2023
1 parent ba65111 commit f494ca5
Show file tree
Hide file tree
Showing 6 changed files with 8,147 additions and 7,506 deletions.
15 changes: 15 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ module.exports = grammar(WGSL, {
original,
),

function_declaration: ($, original) => choice(seq(
optional("virtual"),
original
), seq(
"override",
repeat($.attribute),
"fn",
field("name", $.import_path),
"(",
field("parameters", optional($.parameter_list)),
")",
field("type", optional($.function_return_type_declaration)),
field("body", $.compound_statement)
)),

struct_declaration: $ => seq(
"struct",
field("name", $.identifier),
Expand Down
218 changes: 158 additions & 60 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,74 +400,172 @@
}
},
"function_declaration": {
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "attribute"
}
},
{
"type": "STRING",
"value": "fn"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "("
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "virtual"
},
{
"type": "BLANK"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "attribute"
}
},
{
"type": "STRING",
"value": "fn"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "parameters",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": ")"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "function_return_type_declaration"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "compound_statement"
}
}
]
}
]
},
{
"type": "FIELD",
"name": "parameters",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "override"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "BLANK"
"name": "attribute"
}
]
}
},
{
"type": "STRING",
"value": ")"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "CHOICE",
"members": [
{
},
{
"type": "STRING",
"value": "fn"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "function_return_type_declaration"
},
{
"type": "BLANK"
"name": "import_path"
}
]
}
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "compound_statement"
}
},
{
"type": "STRING",
"value": "("
},
{
"type": "FIELD",
"name": "parameters",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": ")"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "function_return_type_declaration"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "compound_statement"
}
}
]
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,10 @@
{
"type": "identifier",
"named": true
},
{
"type": "import_path",
"named": true
}
]
},
Expand Down Expand Up @@ -2769,6 +2773,10 @@
"type": "vec4",
"named": false
},
{
"type": "virtual",
"named": false
},
{
"type": "while",
"named": false
Expand Down
Loading

0 comments on commit f494ca5

Please # to comment.