From d0ca03c84bcad3dc42fd173b0baf3a15e9b52f9b Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 13:47:08 +0200 Subject: feat: add conditionals --- sfinae.y | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'sfinae.y') diff --git a/sfinae.y b/sfinae.y index 5b5d1be..ca3121d 100644 --- a/sfinae.y +++ b/sfinae.y @@ -33,9 +33,16 @@ void yyerror(const char* message); %token TOK_TUPLE_SIZE %token TOK_INTEGRAL_CONSTANT %token TOK_VALUE +%token TOK_CONDITIONAL_T +%token TOK_CONDITIONAL +%token TOK_TRUE_TYPE +%token TOK_FALSE_TYPE +%token TOK_IS_SAME +%token TOK_EQUAL +%token TOK_LESS %token TOK_CHAR -%type statements statement type value +%type statements statement type value condition %% @@ -69,6 +76,8 @@ type { $$ = node_unary(TYPE_REMOVE_CV, $4); } | TOK_COLONCOLON TOK_ARRAY '<' type ',' value '>' { $$ = node_binary(TYPE_ARRAY, $4, $6); } + | TOK_COLONCOLON TOK_CONDITIONAL_T '<' condition ',' type ',' type '>' + { $$ = node_ternary(TYPE_CONDITIONAL, $4, $6, $8); } | TOK_COLONCOLON TOK_DECLTYPE '(' value ')' { $$ = node_unary(TYPE_DECLTYPE, $4); } ; @@ -89,6 +98,21 @@ value | TOK_COLONCOLON TOK_INTEGRAL_CONSTANT '<' TOK_COLONCOLON TOK_SIZE_T ',' value '>' TOK_COLONCOLON TOK_VALUE { $$ = node_unary(VALUE_INTEGRAL_CONSTANT, $7); } + | TOK_COLONCOLON TOK_CONDITIONAL '<' condition ',' value ',' value '>' + { $$ = node_ternary(VALUE_CONDITIONAL, $4, $6, $8); } + ; + +condition + : TOK_COLONCOLON TOK_TRUE_TYPE TOK_COLONCOLON TOK_VALUE + { $$ = node_leaf(COND_TRUE); } + | TOK_COLONCOLON TOK_FALSE_TYPE TOK_COLONCOLON TOK_VALUE + { $$ = node_leaf(COND_FALSE); } + | TOK_COLONCOLON TOK_IS_SAME '<' type ',' type '>' TOK_COLONCOLON TOK_VALUE + { $$ = node_binary(COND_IS_SAME, $4, $6); } + | TOK_COLONCOLON TOK_EQUAL '<' value ',' value '>' TOK_COLONCOLON TOK_VALUE + { $$ = node_binary(COND_EQUAL, $4, $6); } + | TOK_COLONCOLON TOK_LESS '<' value ',' value '>' TOK_COLONCOLON TOK_VALUE + { $$ = node_binary(COND_LESS, $4, $6); } ; %% -- cgit v1.3