mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Improve parse_enforce_tabs usage
This commit is contained in:
+17
-5
@@ -1921,6 +1921,9 @@ gb_internal Array<Ast *> parse_enum_field_list(AstFile *f) {
|
|||||||
f->curr_token.kind != Token_EOF) {
|
f->curr_token.kind != Token_EOF) {
|
||||||
CommentGroup *docs = f->lead_comment;
|
CommentGroup *docs = f->lead_comment;
|
||||||
CommentGroup *comment = nullptr;
|
CommentGroup *comment = nullptr;
|
||||||
|
|
||||||
|
parse_enforce_tabs(f);
|
||||||
|
|
||||||
Ast *name = parse_value(f);
|
Ast *name = parse_value(f);
|
||||||
Ast *value = nullptr;
|
Ast *value = nullptr;
|
||||||
if (f->curr_token.kind == Token_Eq) {
|
if (f->curr_token.kind == Token_Eq) {
|
||||||
@@ -2259,6 +2262,7 @@ gb_internal Array<Ast *> parse_union_variant_list(AstFile *f) {
|
|||||||
auto variants = array_make<Ast *>(ast_allocator(f));
|
auto variants = array_make<Ast *>(ast_allocator(f));
|
||||||
while (f->curr_token.kind != Token_CloseBrace &&
|
while (f->curr_token.kind != Token_CloseBrace &&
|
||||||
f->curr_token.kind != Token_EOF) {
|
f->curr_token.kind != Token_EOF) {
|
||||||
|
parse_enforce_tabs(f);
|
||||||
Ast *type = parse_type(f);
|
Ast *type = parse_type(f);
|
||||||
if (type->kind != Ast_BadExpr) {
|
if (type->kind != Ast_BadExpr) {
|
||||||
array_add(&variants, type);
|
array_add(&variants, type);
|
||||||
@@ -4274,6 +4278,7 @@ gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_fl
|
|||||||
while (f->curr_token.kind != follow &&
|
while (f->curr_token.kind != follow &&
|
||||||
f->curr_token.kind != Token_Colon &&
|
f->curr_token.kind != Token_Colon &&
|
||||||
f->curr_token.kind != Token_EOF) {
|
f->curr_token.kind != Token_EOF) {
|
||||||
|
if (!is_signature) parse_enforce_tabs(f);
|
||||||
u32 flags = parse_field_prefixes(f);
|
u32 flags = parse_field_prefixes(f);
|
||||||
Ast *param = parse_var_type(f, allow_ellipsis, allow_typeid_token);
|
Ast *param = parse_var_type(f, allow_ellipsis, allow_typeid_token);
|
||||||
if (param->kind == Ast_Ellipsis) {
|
if (param->kind == Ast_Ellipsis) {
|
||||||
@@ -4363,6 +4368,8 @@ gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_fl
|
|||||||
f->curr_token.kind != Token_EOF &&
|
f->curr_token.kind != Token_EOF &&
|
||||||
f->curr_token.kind != Token_Semicolon) {
|
f->curr_token.kind != Token_Semicolon) {
|
||||||
CommentGroup *docs = f->lead_comment;
|
CommentGroup *docs = f->lead_comment;
|
||||||
|
|
||||||
|
if (!is_signature) parse_enforce_tabs(f);
|
||||||
u32 set_flags = parse_field_prefixes(f);
|
u32 set_flags = parse_field_prefixes(f);
|
||||||
Token tag = {};
|
Token tag = {};
|
||||||
Array<Ast *> names = parse_ident_list(f, allow_poly_names);
|
Array<Ast *> names = parse_ident_list(f, allow_poly_names);
|
||||||
@@ -5375,6 +5382,11 @@ gb_internal u64 check_vet_flags(AstFile *file) {
|
|||||||
|
|
||||||
|
|
||||||
gb_internal void parse_enforce_tabs(AstFile *f) {
|
gb_internal void parse_enforce_tabs(AstFile *f) {
|
||||||
|
// Checks to see if tabs have been used for indentation
|
||||||
|
if ((check_vet_flags(f) & VetFlag_Tabs) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Token prev = f->prev_token;
|
Token prev = f->prev_token;
|
||||||
Token curr = f->curr_token;
|
Token curr = f->curr_token;
|
||||||
if (prev.pos.line < curr.pos.line) {
|
if (prev.pos.line < curr.pos.line) {
|
||||||
@@ -5391,6 +5403,10 @@ gb_internal void parse_enforce_tabs(AstFile *f) {
|
|||||||
|
|
||||||
isize len = end-it;
|
isize len = end-it;
|
||||||
for (isize i = 0; i < len; i++) {
|
for (isize i = 0; i < len; i++) {
|
||||||
|
if (it[i] == '/') {
|
||||||
|
// ignore comments
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (it[i] == ' ') {
|
if (it[i] == ' ') {
|
||||||
syntax_error(curr, "With '-vet-tabs', tabs must be used for indentation");
|
syntax_error(curr, "With '-vet-tabs', tabs must be used for indentation");
|
||||||
break;
|
break;
|
||||||
@@ -5405,11 +5421,7 @@ gb_internal Array<Ast *> parse_stmt_list(AstFile *f) {
|
|||||||
while (f->curr_token.kind != Token_case &&
|
while (f->curr_token.kind != Token_case &&
|
||||||
f->curr_token.kind != Token_CloseBrace &&
|
f->curr_token.kind != Token_CloseBrace &&
|
||||||
f->curr_token.kind != Token_EOF) {
|
f->curr_token.kind != Token_EOF) {
|
||||||
|
parse_enforce_tabs(f);
|
||||||
// Checks to see if tabs have been used for indentation
|
|
||||||
if (check_vet_flags(f) & VetFlag_Tabs) {
|
|
||||||
parse_enforce_tabs(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ast *stmt = parse_stmt(f);
|
Ast *stmt = parse_stmt(f);
|
||||||
if (stmt && stmt->kind != Ast_EmptyStmt) {
|
if (stmt && stmt->kind != Ast_EmptyStmt) {
|
||||||
|
|||||||
+4
-1
@@ -885,4 +885,7 @@ gb_internal gb_inline gbAllocator ast_allocator(AstFile *f) {
|
|||||||
gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind);
|
gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind);
|
||||||
|
|
||||||
gb_internal gbString expr_to_string(Ast *expression);
|
gb_internal gbString expr_to_string(Ast *expression);
|
||||||
gb_internal bool allow_field_separator(AstFile *f);
|
gb_internal bool allow_field_separator(AstFile *f);
|
||||||
|
|
||||||
|
|
||||||
|
gb_internal void parse_enforce_tabs(AstFile *f);
|
||||||
Reference in New Issue
Block a user