mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-23 06:45:19 +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_token: Format_Token;
|
||||
keyword_line: int;
|
||||
largest := 0;
|
||||
|
||||
largest := 0;
|
||||
brace_count := 0;
|
||||
done := false;
|
||||
|
||||
@@ -385,6 +385,10 @@ format_keyword_to_brace :: proc(p: ^Printer, line_index: int, format_index: int,
|
||||
break;
|
||||
}
|
||||
|
||||
if format_token.kind == .Undef || format_token.kind == .Comma {
|
||||
return;
|
||||
}
|
||||
|
||||
if line_index == 0 && i <= format_index {
|
||||
continue;
|
||||
}
|
||||
@@ -489,18 +493,20 @@ align_var_decls :: proc(p: ^Printer) {
|
||||
not_mutable = true;
|
||||
}
|
||||
|
||||
if line.format_tokens[i].kind == .Proc ||
|
||||
line.format_tokens[i].kind == .Union ||
|
||||
if line.format_tokens[i].kind == .Union ||
|
||||
line.format_tokens[i].kind == .Enum ||
|
||||
line.format_tokens[i].kind == .Struct ||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if continue_flag {
|
||||
@@ -601,7 +607,6 @@ align_var_decls :: proc(p: ^Printer) {
|
||||
}
|
||||
|
||||
align_switch_stmt :: proc(p: ^Printer, index: int) {
|
||||
|
||||
switch_found := false;
|
||||
brace_token: Format_Token;
|
||||
brace_line: int;
|
||||
@@ -739,7 +744,6 @@ align_enum :: proc(p: ^Printer, index: int) {
|
||||
}
|
||||
|
||||
align_struct :: proc(p: ^Printer, index: int) {
|
||||
|
||||
struct_found := false;
|
||||
brace_token: Format_Token;
|
||||
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};
|
||||
colon_count += 1;
|
||||
largest = max(length, largest);
|
||||
break;
|
||||
}
|
||||
|
||||
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 {
|
||||
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;
|
||||
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 {
|
||||
case Import_Decl:
|
||||
visit_decl(p, cast(^Decl)stmt, true);
|
||||
return;
|
||||
case Value_Decl:
|
||||
visit_decl(p, cast(^Decl)stmt, true);
|
||||
return;
|
||||
@@ -693,6 +698,8 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
|
||||
case Type_Switch_Stmt:
|
||||
move_line(p, v.pos);
|
||||
|
||||
hint_current_line(p, {.Switch_Stmt});
|
||||
|
||||
if v.label != nil {
|
||||
visit_expr(p, v.label);
|
||||
push_generic_token(p, .Colon, 0);
|
||||
|
||||
@@ -608,7 +608,7 @@ scan :: proc(t: ^Tokenizer) -> Token {
|
||||
kind = switch3(t, .And, .And_Eq, '&', .Cmp_And);
|
||||
}
|
||||
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, .Gt, .Gt_Eq, '>', .Shr,.Shr_Eq);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user