mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
fix tokenizer for ~= and better struct aligning
This commit is contained in:
@@ -350,8 +350,8 @@ format_keyword_to_brace :: proc(p: ^Printer, line_index: int, format_index: int,
|
|||||||
keyword_found := false;
|
keyword_found := false;
|
||||||
keyword_token: Format_Token;
|
keyword_token: Format_Token;
|
||||||
keyword_line: int;
|
keyword_line: int;
|
||||||
largest := 0;
|
|
||||||
|
|
||||||
|
largest := 0;
|
||||||
brace_count := 0;
|
brace_count := 0;
|
||||||
done := false;
|
done := false;
|
||||||
|
|
||||||
@@ -385,6 +385,10 @@ format_keyword_to_brace :: proc(p: ^Printer, line_index: int, format_index: int,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if format_token.kind == .Undef || format_token.kind == .Comma {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if line_index == 0 && i <= format_index {
|
if line_index == 0 && i <= format_index {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -489,18 +493,20 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
not_mutable = true;
|
not_mutable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if line.format_tokens[i].kind == .Proc ||
|
if line.format_tokens[i].kind == .Union ||
|
||||||
line.format_tokens[i].kind == .Union ||
|
|
||||||
line.format_tokens[i].kind == .Enum ||
|
line.format_tokens[i].kind == .Enum ||
|
||||||
line.format_tokens[i].kind == .Struct ||
|
line.format_tokens[i].kind == .Struct ||
|
||||||
line.format_tokens[i].kind == .For ||
|
line.format_tokens[i].kind == .For ||
|
||||||
line.format_tokens[i].kind == .If {
|
line.format_tokens[i].kind == .If ||
|
||||||
|
line.format_tokens[i].kind == .Comment {
|
||||||
continue_flag = true;
|
continue_flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if line.format_tokens[i].kind == .Comment {
|
//enforced undef is always on the last line, if it exists
|
||||||
|
if line.format_tokens[i].kind == .Proc && line.format_tokens[len(line.format_tokens)-1].kind != .Undef {
|
||||||
continue_flag = true;
|
continue_flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if continue_flag {
|
if continue_flag {
|
||||||
@@ -601,7 +607,6 @@ align_var_decls :: proc(p: ^Printer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
align_switch_stmt :: proc(p: ^Printer, index: int) {
|
align_switch_stmt :: proc(p: ^Printer, index: int) {
|
||||||
|
|
||||||
switch_found := false;
|
switch_found := false;
|
||||||
brace_token: Format_Token;
|
brace_token: Format_Token;
|
||||||
brace_line: int;
|
brace_line: int;
|
||||||
@@ -739,7 +744,6 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
align_struct :: proc(p: ^Printer, index: int) {
|
align_struct :: proc(p: ^Printer, index: int) {
|
||||||
|
|
||||||
struct_found := false;
|
struct_found := false;
|
||||||
brace_token: Format_Token;
|
brace_token: Format_Token;
|
||||||
brace_line: int;
|
brace_line: int;
|
||||||
@@ -795,6 +799,7 @@ align_struct :: proc(p: ^Printer, index: int) {
|
|||||||
format_tokens[colon_count] = {format_token = &line.format_tokens[i + 1], length = length};
|
format_tokens[colon_count] = {format_token = &line.format_tokens[i + 1], length = length};
|
||||||
colon_count += 1;
|
colon_count += 1;
|
||||||
largest = max(length, largest);
|
largest = max(length, largest);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
length += len(format_token.text) + format_token.spaces_before;
|
length += len(format_token.text) + format_token.spaces_before;
|
||||||
|
|||||||
@@ -461,8 +461,10 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) {
|
|||||||
|
|
||||||
for value in v.values {
|
for value in v.values {
|
||||||
switch a in value.derived {
|
switch a in value.derived {
|
||||||
case Proc_Lit, Union_Type, Enum_Type, Struct_Type:
|
case Union_Type, Enum_Type, Struct_Type:
|
||||||
add_semicolon = false || called_in_stmt;
|
add_semicolon = false || called_in_stmt;
|
||||||
|
case Proc_Lit:
|
||||||
|
add_semicolon = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,6 +534,9 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch v in stmt.derived {
|
switch v in stmt.derived {
|
||||||
|
case Import_Decl:
|
||||||
|
visit_decl(p, cast(^Decl)stmt, true);
|
||||||
|
return;
|
||||||
case Value_Decl:
|
case Value_Decl:
|
||||||
visit_decl(p, cast(^Decl)stmt, true);
|
visit_decl(p, cast(^Decl)stmt, true);
|
||||||
return;
|
return;
|
||||||
@@ -693,6 +698,8 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
|||||||
case Type_Switch_Stmt:
|
case Type_Switch_Stmt:
|
||||||
move_line(p, v.pos);
|
move_line(p, v.pos);
|
||||||
|
|
||||||
|
hint_current_line(p, {.Switch_Stmt});
|
||||||
|
|
||||||
if v.label != nil {
|
if v.label != nil {
|
||||||
visit_expr(p, v.label);
|
visit_expr(p, v.label);
|
||||||
push_generic_token(p, .Colon, 0);
|
push_generic_token(p, .Colon, 0);
|
||||||
|
|||||||
@@ -608,7 +608,7 @@ scan :: proc(t: ^Tokenizer) -> Token {
|
|||||||
kind = switch3(t, .And, .And_Eq, '&', .Cmp_And);
|
kind = switch3(t, .And, .And_Eq, '&', .Cmp_And);
|
||||||
}
|
}
|
||||||
case '|': kind = switch3(t, .Or, .Or_Eq, '|', .Cmp_Or);
|
case '|': kind = switch3(t, .Or, .Or_Eq, '|', .Cmp_Or);
|
||||||
case '~': kind = .Xor;
|
case '~': kind = switch2(t, .Xor, .Xor_Eq);
|
||||||
case '<': kind = switch4(t, .Lt, .Lt_Eq, '<', .Shl, .Shl_Eq);
|
case '<': kind = switch4(t, .Lt, .Lt_Eq, '<', .Shl, .Shl_Eq);
|
||||||
case '>': kind = switch4(t, .Gt, .Gt_Eq, '>', .Shr,.Shr_Eq);
|
case '>': kind = switch4(t, .Gt, .Gt_Eq, '>', .Shr,.Shr_Eq);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user