hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/sfinae.y
diff options
context:
space:
mode:
Diffstat (limited to 'sfinae.y')
-rw-r--r--sfinae.y35
1 files changed, 34 insertions, 1 deletions
diff --git a/sfinae.y b/sfinae.y
index 0d7f0ee..e142aaa 100644
--- a/sfinae.y
+++ b/sfinae.y
@@ -3,6 +3,7 @@
#include "lexer.h"
#include <stdio.h>
+#include <string.h>
struct Node* program_root = NULL;
@@ -12,6 +13,7 @@ void yyerror(const char* message);
%union
{
char character;
+ struct Name name;
struct Node* node;
}
@@ -19,6 +21,9 @@ void yyerror(const char* message);
%token TOK_EMIT
%token TOK_STATIC_ASSERT
%token TOK_COMMIT
+%token TOK_DECLARE
+%token TOK_NAME
+%token TOK_VALUE_OF
%token TOK_VOID
%token TOK_INT32
%token TOK_BYTE
@@ -43,6 +48,7 @@ void yyerror(const char* message);
%token TOK_LESS
%token <character> TOK_CHAR
+%type <name> name char_list
%type <node> statements statement type value condition
%%
@@ -64,6 +70,30 @@ statement
{ $$ = node_unary(STMT_EMIT, $4); }
| TOK_COLONCOLON TOK_STATIC_ASSERT '<' condition '>' TOK_COLONCOLON TOK_COMMIT
{ $$ = node_unary(STMT_STATIC_ASSERT, $4); }
+ | TOK_COLONCOLON TOK_DECLARE '<' name ',' type '>' TOK_COLONCOLON TOK_COMMIT
+ { $$ = node_named(STMT_DECLARE, &$4, $6); }
+ ;
+
+name
+ : TOK_COLONCOLON TOK_NAME '<' char_list '>'
+ { $$ = $4; }
+ ;
+
+char_list
+ : TOK_CHAR
+ {
+ name_init(&$$);
+ (void)name_push(&$$, $1);
+ }
+ | char_list ',' TOK_CHAR
+ {
+ $$ = $1;
+ if (!name_push(&$$, $3))
+ {
+ yyerror("that name is too long, who are you");
+ YYERROR;
+ }
+ }
;
type
@@ -94,6 +124,8 @@ value
{ $$ = node_binary(VALUE_PRODUCT, $4, $6); }
| TOK_COLONCOLON TOK_QUOTIENT '<' value ',' value '>'
{ $$ = node_binary(VALUE_QUOTIENT, $4, $6); }
+ | TOK_COLONCOLON TOK_VALUE_OF '<' name '>'
+ { $$ = node_named(VALUE_VARIABLE, &$4, NULL); }
| TOK_COLONCOLON TOK_EXTENT '<' type '>' TOK_COLONCOLON TOK_VALUE
{ $$ = node_unary(VALUE_EXTENT, $4); }
| TOK_COLONCOLON TOK_TUPLE_SIZE '<' type '>' TOK_COLONCOLON TOK_VALUE
@@ -124,6 +156,7 @@ void yyerror(const char* message)
{
if (!lexer_failed())
{
- (void)fprintf(stderr, "line %d: %s, did you forget to commit\n", yylineno, message);
+ (void)fprintf(stderr, "line %d: %s%s\n", yylineno, message,
+ strcmp(message, "syntax error") == 0 ? ", did you forget to commit" : "");
}
}