// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq 0x18(%rsi), %r15
movq 0x8(%rdi), %rbx
movq %r15, %r12
cmpq %rbx, %r15
jbe 0x91f7
movq %r15, %r12
movzbl (%r12), %eax
cmpl $0xd, %eax
je 0x91f4
cmpl $0xa, %eax
je 0x91f4
decq %r12
cmpq %rbx, %r12
ja 0x91d8
movq %rbx, %r12
jmp 0x91f7
incq %r12
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rdx
shlq $0x5, %rax
leaq (%rdx,%rax), %r13
addq $-0x20, %r13
addq (%rdi), %rbx
cmpq %r14, %r13
je 0x924b
movq 0x10(%r14), %rax
movq 0x18(%r14), %rbp
leaq (%rax,%rbp), %rsi
cmpq %rbx, %rsi
movq %rsi, (%rsp)
jae 0x9254
leaq (%rax,%rbp), %rdx
incq %rdx
movq %rdx, %rax
movzbl -0x1(%rdx), %edx
cmpl $0xa, %edx
je 0x926b
cmpl $0xd, %edx
je 0x9259
leaq 0x1(%rax), %rdx
cmpq %rbx, %rax
jb 0x922f
jmp 0x926b
movq %rbx, %rbp
movq %rbx, (%rsp)
jmp 0x926e
movq %rsi, %rbx
jmp 0x926e
cmpq %rbx, %rax
jae 0x926b
leaq 0x1(%rax), %rbx
cmpb $0xa, (%rax)
cmovneq %rax, %rbx
jmp 0x926e
movq %rax, %rbx
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
leaq 0x7fd5(%rip), %rdi      # 0x11252
xorl %eax, %eax
callq 0x4261
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x76d6
leaq 0x7fd8(%rip), %rdi      # 0x11273
xorl %eax, %eax
callq 0x4261
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x76d6
cmpq %r14, %r13
je 0x92fc
leaq 0x7fd0(%rip), %rdi      # 0x1128b
xorl %eax, %eax
callq 0x4261
movq %rbp, %rdi
movq (%rsp), %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x76d6
leaq 0x899e(%rip), %rdi      # 0x11c78
xorl %eax, %eax
callq 0x4261
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x76d6
leaq 0x7f78(%rip), %rdi      # 0x1127b
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4261