mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Experiment with new grammatical parsing rule for expression level (-strict-style) idea
This commit is contained in:
+34
-6
@@ -1231,6 +1231,17 @@ void comsume_comment_groups(AstFile *f, Token prev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ignore_newlines(AstFile *f) {
|
||||||
|
if (build_context.strict_style) {
|
||||||
|
if (f->allow_newline) {
|
||||||
|
return f->expr_level > 0;
|
||||||
|
}
|
||||||
|
return f->expr_level >= 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Token advance_token(AstFile *f) {
|
Token advance_token(AstFile *f) {
|
||||||
f->lead_comment = nullptr;
|
f->lead_comment = nullptr;
|
||||||
@@ -1239,8 +1250,17 @@ Token advance_token(AstFile *f) {
|
|||||||
Token prev = f->prev_token = f->curr_token;
|
Token prev = f->prev_token = f->curr_token;
|
||||||
|
|
||||||
bool ok = next_token0(f);
|
bool ok = next_token0(f);
|
||||||
if (ok && f->curr_token.kind == Token_Comment) {
|
if (ok) {
|
||||||
comsume_comment_groups(f, prev);
|
switch (f->curr_token.kind) {
|
||||||
|
case Token_Comment:
|
||||||
|
comsume_comment_groups(f, prev);
|
||||||
|
break;
|
||||||
|
case Token_Semicolon:
|
||||||
|
if (ignore_newlines(f) && f->curr_token.string == "\n") {
|
||||||
|
advance_token(f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
@@ -2513,7 +2533,11 @@ Ast *parse_call_expr(AstFile *f, Ast *operand) {
|
|||||||
Token open_paren, close_paren;
|
Token open_paren, close_paren;
|
||||||
Token ellipsis = {};
|
Token ellipsis = {};
|
||||||
|
|
||||||
f->expr_level++;
|
isize prev_expr_level = f->expr_level;
|
||||||
|
bool prev_allow_newline = f->allow_newline;
|
||||||
|
f->expr_level = 0;
|
||||||
|
f->allow_newline = true;
|
||||||
|
|
||||||
open_paren = expect_token(f, Token_OpenParen);
|
open_paren = expect_token(f, Token_OpenParen);
|
||||||
|
|
||||||
while (f->curr_token.kind != Token_CloseParen &&
|
while (f->curr_token.kind != Token_CloseParen &&
|
||||||
@@ -2550,8 +2574,8 @@ Ast *parse_call_expr(AstFile *f, Ast *operand) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
f->allow_newline = prev_allow_newline;
|
||||||
f->expr_level--;
|
f->expr_level = prev_expr_level;
|
||||||
close_paren = expect_closing(f, Token_CloseParen, str_lit("argument list"));
|
close_paren = expect_closing(f, Token_CloseParen, str_lit("argument list"));
|
||||||
|
|
||||||
|
|
||||||
@@ -4828,7 +4852,9 @@ gb_global Rune illegal_import_runes[] = {
|
|||||||
'\\', // NOTE(bill): Disallow windows style filepaths
|
'\\', // NOTE(bill): Disallow windows style filepaths
|
||||||
'!', '$', '%', '^', '&', '*', '(', ')', '=', '+',
|
'!', '$', '%', '^', '&', '*', '(', ')', '=', '+',
|
||||||
'[', ']', '{', '}',
|
'[', ']', '{', '}',
|
||||||
';', ':', '#',
|
';',
|
||||||
|
':', // NOTE(bill): Disallow windows style absolute filepaths
|
||||||
|
'#',
|
||||||
'|', ',', '<', '>', '?',
|
'|', ',', '<', '>', '?',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -4887,6 +4913,8 @@ bool is_build_flag_path_valid(String path) {
|
|||||||
#if defined(GB_SYSTEM_WINDOWS)
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
if (r == '\\') {
|
if (r == '\\') {
|
||||||
break;
|
break;
|
||||||
|
} else if (r == ':') {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (r == illegal_import_runes[i]) {
|
if (r == illegal_import_runes[i]) {
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ struct AstFile {
|
|||||||
// < 0: In Control Clause
|
// < 0: In Control Clause
|
||||||
// NOTE(bill): Used to prevent type literals in control clauses
|
// NOTE(bill): Used to prevent type literals in control clauses
|
||||||
isize expr_level;
|
isize expr_level;
|
||||||
|
bool allow_newline; // Only valid for expr_level == 0
|
||||||
bool allow_range; // NOTE(bill): Ranges are only allowed in certain cases
|
bool allow_range; // NOTE(bill): Ranges are only allowed in certain cases
|
||||||
bool allow_in_expr; // NOTE(bill): in expression are only allowed in certain cases
|
bool allow_in_expr; // NOTE(bill): in expression are only allowed in certain cases
|
||||||
bool in_foreign_block;
|
bool in_foreign_block;
|
||||||
|
|||||||
Reference in New Issue
Block a user