aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-31 22:45:08 +0100
committergingerBill <bill@gingerbill.org>2021-08-31 22:45:08 +0100
commitcd09068e335c8446a9d48dd1bd9868989e531c5e (patch)
tree86376dcc8d0c7e6a5cb0be69d39b0d6a9d926223 /src
parentcd4687cb13d57c3de1231fdf34f834192f8d8a2f (diff)
Correct parsing rules for `#assert` directives for semicolons
Diffstat (limited to 'src')
-rw-r--r--src/build_settings.cpp2
-rw-r--r--src/main.cpp8
-rw-r--r--src/parser.cpp44
3 files changed, 18 insertions, 36 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index c614a6dc8..728cf5077 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -205,6 +205,8 @@ struct BuildContext {
bool keep_object_files;
bool disallow_do;
+ bool strict_style;
+
bool ignore_warnings;
bool warnings_as_errors;
diff --git a/src/main.cpp b/src/main.cpp
index b4e6c08af..6a0bf381c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1308,11 +1308,11 @@ bool parse_build_flags(Array<String> args) {
case BuildFlag_InsertSemicolon:
gb_printf_err("-insert-semicolon flag is not required any more\n");
+ bad_flags = true;
break;
case BuildFlag_StrictStyle:
- gb_printf_err("-strict-style flag is not required any more\n");
- bad_flags = true;
+ build_context.strict_style = true;
break;
@@ -1870,8 +1870,8 @@ void print_show_help(String const arg0, String const &command) {
print_usage_line(2, "Sets the default allocator to be the nil_allocator, an allocator which does nothing");
print_usage_line(0, "");
- print_usage_line(1, "-insert-semicolon");
- print_usage_line(2, "Inserts semicolons on newlines during tokenization using a basic rule");
+ print_usage_line(1, "-strict-style");
+ print_usage_line(2, "Errs on unneeded tokens, such as unneeded semicolons");
print_usage_line(0, "");
print_usage_line(1, "-ignore-warnings");
diff --git a/src/parser.cpp b/src/parser.cpp
index fe334e4c7..fe421f7db 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1491,33 +1491,6 @@ Token expect_closing(AstFile *f, TokenKind kind, String context) {
return expect_token(f, kind);
}
-bool is_semicolon_optional_for_node(AstFile *f, Ast *s) {
- if (s == nullptr) {
- return false;
- }
- return true;
-}
-
-void expect_semicolon_newline_error(AstFile *f, Token const &token, Ast *s) {
- #if 0
- if (!build_context.insert_semicolon && token.string == "\n") {
- switch (token.kind) {
- case Token_CloseBrace:
- case Token_CloseParen:
- case Token_else:
- return;
- }
- if (is_semicolon_optional_for_node(f, s)) {
- return;
- }
-
- Token tok = token;
- tok.pos.column -= 1;
- syntax_error(tok, "Expected ';', got newline");
- }
- #endif
-}
-
void assign_removal_flag_to_semicolon(AstFile *f) {
// NOTE(bill): this is used for rewriting files to strip unneeded semicolons
Token *prev_token = &f->tokens[f->prev_token_index];
@@ -1525,6 +1498,9 @@ void assign_removal_flag_to_semicolon(AstFile *f) {
GB_ASSERT(prev_token->kind == Token_Semicolon);
if (prev_token->string == ";") {
if (curr_token->pos.line > prev_token->pos.line) {
+ if (build_context.strict_style) {
+ syntax_error(*prev_token, "Found unneeded semicolon");
+ }
prev_token->flags |= TokenFlag_Remove;
}
}
@@ -1535,7 +1511,6 @@ void expect_semicolon(AstFile *f, Ast *s) {
if (allow_token(f, Token_Semicolon)) {
assign_removal_flag_to_semicolon(f);
- expect_semicolon_newline_error(f, f->prev_token, s);
return;
}
switch (f->curr_token.kind) {
@@ -1550,7 +1525,6 @@ void expect_semicolon(AstFile *f, Ast *s) {
prev_token = f->prev_token;
if (prev_token.kind == Token_Semicolon) {
assign_removal_flag_to_semicolon(f);
- expect_semicolon_newline_error(f, f->prev_token, s);
return;
}
@@ -4545,14 +4519,20 @@ Ast *parse_stmt(AstFile *f) {
return s;
} else if (tag == "assert") {
Ast *t = ast_basic_directive(f, hash_token, name);
- return ast_expr_stmt(f, parse_call_expr(f, t));
+ Ast *stmt = ast_expr_stmt(f, parse_call_expr(f, t));
+ expect_semicolon(f, stmt);
+ return stmt;
} else if (tag == "panic") {
Ast *t = ast_basic_directive(f, hash_token, name);
- return ast_expr_stmt(f, parse_call_expr(f, t));
+ Ast *stmt = ast_expr_stmt(f, parse_call_expr(f, t));
+ expect_semicolon(f, stmt);
+ return stmt;
} else if (name.string == "force_inline" ||
name.string == "force_no_inline") {
Ast *expr = parse_force_inlining_operand(f, name);
- return ast_expr_stmt(f, expr);
+ Ast *stmt = ast_expr_stmt(f, expr);
+ expect_semicolon(f, stmt);
+ return stmt;
} else if (tag == "unroll") {
return parse_unrolled_for_loop(f, name);
} else if (tag == "include") {