Add integer select pattern
All checks were successful
ci/woodpecker/push/check Pipeline was successful

This commit is contained in:
Bruno BELANYI 2025-04-02 10:14:21 +00:00
parent 2b7323eaf0
commit e6473f64ae
5 changed files with 466 additions and 373 deletions

View file

@ -163,6 +163,7 @@ module.exports = grammar({
_select_pattern: ($) => choice( _select_pattern: ($) => choice(
$._string_literal, $._string_literal,
$.boolean_literal, $.boolean_literal,
$.integer_literal,
alias("any", $.any), alias("any", $.any),
$.pattern_binding, $.pattern_binding,
alias("default", $.default), alias("default", $.default),

4
src/grammar.json generated
View file

@ -757,6 +757,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "boolean_literal" "name": "boolean_literal"
}, },
{
"type": "SYMBOL",
"name": "integer_literal"
},
{ {
"type": "ALIAS", "type": "ALIAS",
"content": { "content": {

4
src/node-types.json generated
View file

@ -531,6 +531,10 @@
"type": "default", "type": "default",
"named": true "named": true
}, },
{
"type": "integer_literal",
"named": true
},
{ {
"type": "interpreted_string_literal", "type": "interpreted_string_literal",
"named": true "named": true

790
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -409,6 +409,46 @@ foo = select(some_boolean("IS_TRUE"), {
(boolean_literal)) (boolean_literal))
(interpreted_string_literal)))))) (interpreted_string_literal))))))
================================================================================
Select (integer typed)
================================================================================
foo = select(some_integer("VALUE"), {
0: "0",
-1: "-1",
1: "1",
default: "default",
})
--------------------------------------------------------------------------------
(source_file
(assignment
(identifier)
(operator)
(select_expression
(select_value
(condition
(identifier)
(interpreted_string_literal)))
(select_cases
(select_case
(select_pattern
(integer_literal))
(interpreted_string_literal))
(select_case
(select_pattern
(integer_literal))
(interpreted_string_literal))
(select_case
(select_pattern
(integer_literal))
(interpreted_string_literal))
(select_case
(select_pattern
(default))
(interpreted_string_literal))))))
================================================================================ ================================================================================
Select as an identifier Select as an identifier
================================================================================ ================================================================================