// File: /workspace/github_cpp_makefile_star2_O2/cphinton42[P]hinton-language/src/parse.cpp
// Function: report_error(Parsing_Context*, Token*, Token*, char const*)
void report_error(Parsing_Context *ctx, Token *start_section, Token *current,const byte *error_text)
{
    byte *start_highlight = start_section->contents.data;
    byte *start = start_highlight;
    byte *start_program = ctx->program_text.data;
    while(start > start_program)
    {
        if(*start == '\n' || *start == '\r')
        {
            ++start;
            break;
        }
        else
        {
            --start;
        }
    }
    
    bool error_at_eof = (current == &ctx->tokens[ctx->tokens.count - 1]);
    byte *end_program = ctx->program_text.data + ctx->program_text.count;
    
    byte *start_error;
    byte *end_highlight;
    byte *end;
    
    if(error_at_eof)
    {
        start_error = end_program;
        end_highlight = end_program;
        end = end_program;
    }
    else
    {
        start_error = current->contents.data;
        end_highlight = start_error + current->contents.count;
        end = end_highlight;
        
        while(end < end_program)
        {
            if(*end == '\r')
            {
                ++end;
                if(end < end_program && *end == '\n')
                {
                    ++end;
                }
                break;
            }
            else if(*end == '\n')
            {
                ++end;
                break;
            }
            else
            {
                ++end;
            }
        }
    }
    
    print_err("\x1B[1;31mError\x1B[0m: %d:%d:\n    %s\n", current->line_number, current->line_offset, error_text);
    
    print_err_indented(start, start_highlight);
    
    print_err("\x1B[1;33m");
    print_err_indented(start_highlight, start_error, false);
    
    if(error_at_eof)
    {
        print_err("\x1B[1;31mEOF\x1B[0m\n");
    }
    else
    {
        print_err("\x1B[1;31m");
        print_err_indented(start_error, end_highlight, false);
        
        print_err("\x1B[0m");
        print_err_indented(end_highlight, end, false);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq 0x18(%rsi), %r14
movq 0x8(%rdi), %rax
movq %r14, %r15
cmpq %rax, %r15
jbe 0x7bed
movzbl (%r15), %edx
cmpl $0xd, %edx
je 0x7bea
cmpl $0xa, %edx
je 0x7bea
decq %r15
jmp 0x7bd2
incq %r15
movq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rsi
shlq $0x5, %rdx
addq %rdx, %rsi
addq $-0x20, %rsi
addq (%rdi), %rax
cmpq %rbx, %rsi
movq %rsi, (%rsp)
je 0x7c45
movq 0x18(%rbx), %rbp
movq 0x10(%rbx), %r12
addq %rbp, %r12
movq %r12, %r13
cmpq %rax, %r13
jae 0x7c4e
movzbl (%r13), %edx
incq %r13
cmpl $0xa, %edx
je 0x7c4e
cmpl $0xd, %edx
jne 0x7c1a
cmpq %rax, %r13
jae 0x7c4e
leaq 0x1(%r13), %rax
cmpb $0xa, (%r13)
cmoveq %rax, %r13
jmp 0x7c4e
movq %rax, %rbp
movq %rax, %r12
movq %rax, %r13
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
leaq 0x75c7(%rip), %rdi      # 0xf222
xorl %eax, %eax
callq 0x3ec6
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x6ca3
leaq 0x75cc(%rip), %rdi      # 0xf243
xorl %eax, %eax
callq 0x3ec6
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x6ca3
cmpq %rbx, (%rsp)
je 0x7cd5
leaq 0x75c3(%rip), %rdi      # 0xf25b
xorl %eax, %eax
callq 0x3ec6
movq %rbp, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x6ca3
leaq 0x7f10(%rip), %rdi      # 0xfbc3
xorl %eax, %eax
callq 0x3ec6
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ca3
leaq 0x756f(%rip), %rdi      # 0xf24b
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ec6