Change syntax of $if, $assert, $include, $echo. Introduces $error

This commit is contained in:
Christoffer Lerno
2023-05-06 12:18:00 +02:00
parent 3dd6675e1b
commit 172d561f07
104 changed files with 338 additions and 336 deletions

View File

@@ -1,6 +1,6 @@
macro int factorial($n)
{
$if ($n == 0)
$if $n == 0:
return 1;
$else
return $n * factorial($n - 1);

View File

@@ -16,7 +16,7 @@ const uint MaxDepth = 8;
//#define DEBUG_NODES
$if (DEBUG_NODES)
$if DEBUG_NODES:
fn void Blocks.dump(Blocks* b)
{
@@ -418,7 +418,7 @@ public fn void! TomlReader.parse(TomlReader* r, string filename)
Parser parser;
parser.parse(file.data(), r.message, r.blocks);
$if (DEBUG_NODES)
$if DEBUG_NODES:
r.blocks.dump();
$endif
return status;

View File

@@ -50,6 +50,7 @@ int comment_level = 0;
"$endforeach" { count(); return(CT_ENDFOREACH); }
"$endif" { count(); return(CT_ENDIF); }
"$endswitch" { count(); return(CT_ENDSWITCH); }
"$error" { count(); return(CT_ERROR); }
"$eval" { count(); return(CT_EVAL); }
"$evaltype" { count(); return(CT_EVALTYPE); }
"$extnameof" { count(); return(CT_EXTNAMEOF); }

View File

@@ -23,6 +23,7 @@ void yyerror(char *s);
%token TYPEID BITSTRUCT STATIC BANGBANG AT_CONST_IDENT HASH_TYPE_IDENT
%token STRUCT UNION ENUM ELLIPSIS DOTDOT BYTES
%token CT_ERROR
%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR CONTINUE BREAK RETURN FOREACH_R FOREACH
%token FN FAULT MACRO CT_IF CT_ENDIF CT_ELSE CT_SWITCH CT_CASE CT_DEFAULT CT_FOR CT_FOREACH CT_ENDFOREACH
%token CT_ENDFOR CT_ENDSWITCH BUILTIN IMPLIES INITIALIZE FINALIZE CT_ECHO CT_ASSERT CT_EVALTYPE CT_VATYPE
@@ -410,10 +411,6 @@ constant_expr
: ternary_expr
;
const_paren_expr
: '(' constant_expr ')'
;
param_path_element
: '[' expr ']'
| '[' expr DOTDOT expr ']'
@@ -750,8 +747,8 @@ defer_stmt
;
ct_if_stmt
: CT_IF const_paren_expr opt_stmt_list CT_ENDIF
| CT_IF const_paren_expr opt_stmt_list CT_ELSE opt_stmt_list CT_ENDIF
: CT_IF constant_expr ':' opt_stmt_list CT_ENDIF
| CT_IF constant_expr ':' opt_stmt_list CT_ELSE opt_stmt_list CT_ENDIF
;
assert_expr
@@ -873,16 +870,17 @@ optional_label
;
ct_assert_stmt
: CT_ASSERT '(' constant_expr ',' constant_expr ')' ';'
| CT_ASSERT '(' constant_expr ')' ';'
: CT_ASSERT constant_expr ':' constant_expr ';'
| CT_ASSERT constant_expr ';'
| CT_ERROR constant_expr ';'
;
ct_include_stmt
: CT_INCLUDE '(' string_expr ')' ';'
: CT_INCLUDE string_expr ';'
;
ct_echo_stmt
: CT_ECHO '(' constant_expr ')' ';'
: CT_ECHO constant_expr ';'
bitstruct_declaration
: BITSTRUCT TYPE_IDENT ':' type opt_attributes bitstruct_body
@@ -1173,8 +1171,8 @@ define_declaration
;
tl_ct_if
: CT_IF const_paren_expr opt_tl_stmts CT_ENDIF
| CT_IF const_paren_expr opt_tl_stmts CT_ELSE opt_tl_stmts CT_ENDIF
: CT_IF constant_expr ':' opt_tl_stmts CT_ENDIF
| CT_IF constant_expr ':' opt_tl_stmts CT_ELSE opt_tl_stmts CT_ENDIF
;
tl_ct_switch

View File

@@ -15,7 +15,7 @@ macro @goo(i, $e)
struct Foo
{
$if ($use_bar > 0)
$if $use_bar > 0:
{
int bar;
}
@@ -125,12 +125,12 @@ $default:
}
$endswitch
$if ($e > 0)
$if $e > 0:
{
fn void foo() {}
}
$if ($b > 0)
$if $b > 0:
{
}
$else

View File

@@ -1,7 +1,7 @@
module hello_world;
import std;
import bar;
$if (env::os_is_win32())
$if env::os_is_win32():
fn int test_doubler(int x)
{
return x * x;