-strict-style enforce 1TBS (mostly)

This commit is contained in:
gingerBill
2024-06-29 19:14:24 +01:00
parent 5413a8b744
commit 2187f3e7ff

View File

@@ -1486,7 +1486,7 @@ gb_internal bool skip_possible_newline(AstFile *f) {
return false;
}
gb_internal bool skip_possible_newline_for_literal(AstFile *f) {
gb_internal bool skip_possible_newline_for_literal(AstFile *f, bool seen_where=false) {
Token curr = f->curr_token;
if (token_is_newline(curr)) {
Token next = peek_token(f);
@@ -1494,6 +1494,10 @@ gb_internal bool skip_possible_newline_for_literal(AstFile *f) {
switch (next.kind) {
case Token_OpenBrace:
case Token_else:
if (build_context.strict_style && !seen_where) {
syntax_error(next, "With '-strict-style' the attached brace style (1TBS) is enforced");
}
/*fallthrough*/
case Token_where:
advance_token(f);
return true;
@@ -2517,7 +2521,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
return type;
}
skip_possible_newline_for_literal(f);
skip_possible_newline_for_literal(f, where_token.kind == Token_where);
if (allow_token(f, Token_Uninit)) {
if (where_token.kind != Token_Invalid) {
@@ -4499,6 +4503,9 @@ gb_internal bool parse_control_statement_semicolon_separator(AstFile *f) {
}
gb_internal Ast *parse_if_stmt(AstFile *f) {
if (f->curr_proc == nullptr) {
syntax_error(f->curr_token, "You cannot use an if statement in the file scope");