Skip to content

Commit

Permalink
Add support for "discard" keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
greenerfield committed Sep 20, 2023
1 parent bc5d822 commit ec9df89
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
19 changes: 19 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ module.exports = grammar(C, {
...original.members.filter((member) => member.content?.name != '_old_style_function_definition'),
),

_top_level_statement: (_, original) => choice(
...original.members.concat({
type: "SYMBOL",
name: "discard_statement",
})
),

_non_case_statement: (_, original) => choice(
...original.members.concat({
type: "SYMBOL",
name: "discard_statement",
})
),

function_definition: ($, original) => seq(
optional(
seq(
Expand All @@ -29,6 +43,11 @@ module.exports = grammar(C, {
, original
),

discard_statement: () => seq(
"discard",
";"
),

declaration: ($, original) =>
choice(seq(choice("invariant", "precise"), $.identifier, ";"), seq(
repeat(
Expand Down
21 changes: 21 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4984,6 +4984,10 @@
{
"type": "SYMBOL",
"name": "goto_statement"
},
{
"type": "SYMBOL",
"name": "discard_statement"
}
]
},
Expand Down Expand Up @@ -5050,6 +5054,10 @@
{
"type": "SYMBOL",
"name": "goto_statement"
},
{
"type": "SYMBOL",
"name": "discard_statement"
}
]
},
Expand Down Expand Up @@ -8497,6 +8505,19 @@
]
}
},
"discard_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "discard"
},
{
"type": "STRING",
"value": ";"
}
]
},
"extension_storage_class": {
"type": "CHOICE",
"members": [
Expand Down
21 changes: 21 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@
"type": "continue_statement",
"named": true
},
{
"type": "discard_statement",
"named": true
},
{
"type": "do_statement",
"named": true
Expand Down Expand Up @@ -916,6 +920,10 @@
"type": "declaration",
"named": true
},
{
"type": "discard_statement",
"named": true
},
{
"type": "do_statement",
"named": true
Expand Down Expand Up @@ -1314,6 +1322,11 @@
]
}
},
{
"type": "discard_statement",
"named": true,
"fields": {}
},
{
"type": "do_statement",
"named": true,
Expand Down Expand Up @@ -3448,6 +3461,10 @@
"type": "declaration",
"named": true
},
{
"type": "discard_statement",
"named": true
},
{
"type": "do_statement",
"named": true
Expand Down Expand Up @@ -4171,6 +4188,10 @@
"type": "defined",
"named": false
},
{
"type": "discard",
"named": false
},
{
"type": "do",
"named": false
Expand Down
24 changes: 24 additions & 0 deletions test/corpus/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,27 @@ layout (input_attachment_index = 1, set = 1, binding = 1) uniform subpassInput i
(number_literal))))
(type_identifier)
(identifier)))

================================================================================
Discard
================================================================================
void main() {
if (true) return;
if (true) discard;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(if_statement
(parenthesized_expression
(true))
(return_statement))
(if_statement
(parenthesized_expression
(true))
(discard_statement)))))

0 comments on commit ec9df89

Please sign in to comment.