// File: /workspace/github_cpp_makefile_star2_O1/AgathokakologicalBit[P]wit/src/parsing/lexing.cpp
// Function: akbit::system::parsing::get_next_token(akbit::system::parsing::LexerState&)
parsing::Token get_next_token(parsing::LexerState &state)
  {
    while (std::isspace(state.peek()))
      state.move();

    if (state.is_eof())
    {
      return parsing::Token{
        state.index, state.line, state.column,
        "##EOF##",
        TokenType::t_eof, TokenSubType::t_eof
      };
    }

    auto sub_type = get_character_type(state.peek());
    if (sub_type != TokenSubType::t_unknown)
    {
      state.move();

      // skipping comments
      if (sub_type == TokenSubType::t_slash && state.peek() == '/')
      {
        do state.move();
        while (state.peek() != '\n');

        // TODO: remove the recursion
        return get_next_token(state);
      }

      return parsing::Token{
        state.index - 1, state.line, state.column - 1,
        state.source.substr(state.index - 1, 1),
        TokenType::t_operator,
        sub_type
      };
    }

    if (state.peek() == '"')
    {
      std::uint32_t length = 1;
      do
      {
        state.move(), ++length;

        if (state.peek() == '\\')
          state.move(), ++length;
        
        if (state.peek() == '\0')
        {
          state.error.code = error_t::t_unexpected_eof;
          state.error.message = "String was not closed";
          break;
        }
      } while (state.peek() != '"');
      state.move();

      return parsing::Token{
        state.index - length, state.line, state.column - length,

        state.source.substr(state.index - length, length),

        TokenType::t_string,
        TokenSubType::t_string
      };
    }

    if (state.peek() == '\'')
    {
      state.move();
      std::uint32_t length = 1;

      if (std::isspace(state.peek()) || std::iscntrl(state.peek()))
      {
        state.error.code = error_t::t_misleading_character;
        state.error.message =
          "Character definition is misleading\n"
          "Whitespace symbols should be written using escape sequences:\n"
          "  \\s - space\n"
          "  \\t - tabulation\n"
          "  \\n - new line\n"
          "  \\r - carriage return";
      }

      if (state.peek() == '\\')
      {
        state.move(), ++length;
        switch(state.peek())
        {
          case 'r': case 'n': case 't': case 's': break;
          default:
          state.error.code = error_t::t_special_character_does_not_exist;
          state.error.message = std::string("Special character identifier '")
            + state.peek() + "' does not exists";
        }
      }

      state.move();

      return parsing::Token{
        state.index - length, state.line, state.column - length,

        state.source.substr(state.index - length, length),

        TokenType::t_character, TokenSubType::t_character,
      };
    }

    if ('0' <= state.peek() && state.peek() <= '9')
    {
      std::uint32_t length = 0;
      bool is_decimal = false;
      do state.move(), ++length;
      while (false
             || std::isdigit(state.peek())
             || (state.peek() == '.' && !is_decimal && (is_decimal = true)));

      return parsing::Token{
        state.index - length, state.line, state.column - length,

        state.source.substr(state.index - length, length),

        TokenType::t_number,
        (is_decimal
         ? TokenSubType::t_decimal
         : TokenSubType::t_integer)
      };
    }

    if (false
        || std::isalpha(state.peek())
        || state.peek() == '_' || state.peek() == '$')
    {
      std::uint32_t length = 0;
      do state.move(), ++length;
      while (false
             || std::isalnum(state.peek())
             || state.peek() == '_' || state.peek() == '$');

      return parsing::Token{
        state.index - length, state.line, state.column - length,
        state.source.substr(state.index - length, length),

        TokenType::t_identifier, TokenSubType::t_identifier
      };
    }

    auto ret = parsing::Token{
      state.index, state.line, state.column,
      state.source.substr(state.index, 1),

      TokenType::t_unknown, TokenSubType::t_unknown
    };

    state.move();
    return ret;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, (%rsp)
movq 0x10(%r14), %r12
movl (%r14), %r15d
movq (%r12), %rax
movb (%rax,%r15), %bl
movsbl %bl, %ebp
movl %ebp, %edi
callq 0x3060
testl %eax, %eax
je 0x7d6f
movq %r14, %rdi
callq 0x7c24
jmp 0x7d48
cmpq %r15, 0x8(%r12)
jbe 0x7e06
movsbl %bl, %edi
callq 0x7c4c
testl %eax, %eax
je 0x7e4e
movl %eax, %r13d
movq %r14, %rdi
callq 0x7c24
cmpl $0x15, %r13d
jne 0x7dc5
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
cmpb $0x2f, (%rax,%rcx)
jne 0x7dc5
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
cmpb $0xa, (%rax,%rcx)
jne 0x7dab
jmp 0x7d48
movl (%r14), %edx
decl %edx
movq (%rsp), %r15
movl %edx, (%r15)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r15)
movl 0x8(%r14), %eax
decl %eax
movl %eax, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq 0x10(%r14), %rsi
movl $0x1, %ecx
callq 0x3220
movl $0x6, 0x30(%r15)
movl %r13d, 0x34(%r15)
jmp 0x8244
movq (%rsp), %rax
movl %r15d, (%rax)
movq %rax, %r15
movl 0x4(%r14), %eax
movl %eax, 0x4(%r15)
movl 0x8(%r14), %eax
movl %eax, 0x8(%r15)
leaq 0x10(%r15), %rdi
leaq 0x20(%r15), %rax
movq %rax, 0x10(%r15)
leaq 0xd5cb(%rip), %rsi      # 0x153fe
leaq 0xd5cb(%rip), %rdx      # 0x15405
callq 0x6c06
movabsq $0x2200000007, %rax     # imm = 0x2200000007
jmp 0x8240
cmpb $0x27, %bl
je 0x7f10
movzbl %bl, %r13d
cmpl $0x22, %r13d
jne 0x8035
movl $0x1, %ebp
movq (%rsp), %r15
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
cmpb $0x5c, (%rax,%rcx)
jne 0x7e93
movq %r14, %rdi
callq 0x7c24
addl $0x2, %ebp
jmp 0x7e95
incl %ebp
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movzbl (%rax,%rcx), %eax
cmpl $0x22, %eax
je 0x7ed0
testl %eax, %eax
jne 0x7e6e
movl $0x3f2, 0x18(%r14)      # imm = 0x3F2
leaq 0x20(%r14), %rdi
movq 0x28(%r14), %rdx
leaq 0xd7b5(%rip), %rcx      # 0x15678
movl $0x15, %r8d
xorl %esi, %esi
callq 0x32d0
movq %r14, %rdi
callq 0x7c24
movl (%r14), %edx
subl %ebp, %edx
movl %edx, (%r15)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r15)
movl 0x8(%r14), %eax
subl %ebp, %eax
movl %eax, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq 0x10(%r14), %rsi
movl %ebp, %ecx
callq 0x3220
movabsq $0x600000004, %rax      # imm = 0x600000004
jmp 0x8240
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movsbl (%rax,%rcx), %ebp
movl %ebp, %edi
callq 0x3060
testl %eax, %eax
movq (%rsp), %r15
jne 0x7f40
movl %ebp, %edi
callq 0x32a0
testl %eax, %eax
je 0x7f64
movl $0x407, 0x18(%r14)      # imm = 0x407
leaq 0x20(%r14), %rdi
movq 0x28(%r14), %rdx
leaq 0xd737(%rip), %rcx      # 0x1568e
movl $0xa5, %r8d
xorl %esi, %esi
callq 0x32d0
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movl $0x1, %ebx
cmpb $0x5c, (%rax,%rcx)
jne 0x8205
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movb (%rax,%rcx), %al
addb $-0x6e, %al
cmpb $0x7, %al
jae 0x7fae
movl $0x2, %ebx
movzbl %al, %eax
movl $0x71, %ecx
btl %eax, %ecx
jb 0x8205
movl $0x406, 0x18(%r14)      # imm = 0x406
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xd76d(%rip), %rsi      # 0x15734
leaq 0xd784(%rip), %rdx      # 0x15752
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x6c06
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movsbl (%rax,%rcx), %edx
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x83c2
leaq 0xd756(%rip), %rsi      # 0x15753
leaq 0x28(%rsp), %rdi
callq 0x33a0
leaq 0x58(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8187
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x818d
leal -0x30(%rbx), %eax
cmpb $0x9, %al
ja 0x80b6
xorl %ebp, %ebp
movl $0x1, %r15d
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x7c24
incl %ebp
movq 0x10(%r14), %rsi
movl (%r14), %edx
movq (%rsi), %rax
movsbl (%rax,%rdx), %eax
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
jb 0x8046
cmpb $0x2e, %al
jne 0x8076
movzbl %bl, %ebx
testb $0x1, %bl
cmovel %r15d, %ebx
je 0x8046
subl %ebp, %edx
movq (%rsp), %r15
movl %edx, (%r15)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r15)
movl 0x8(%r14), %eax
subl %ebp, %eax
movl %eax, 0x8(%r15)
leaq 0x10(%r15), %rdi
movl %ebp, %ecx
callq 0x3220
movl $0x3, 0x30(%r15)
movzbl %bl, %eax
andl $0x1, %eax
orl $0x4, %eax
movl %eax, 0x34(%r15)
jmp 0x8244
movl %ebp, %edi
callq 0x32f0
testl %eax, %eax
je 0x8137
movl $0x1, %ebx
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %r15
movl (%r14), %r12d
movq (%r15), %rax
movsbl (%rax,%r12), %ebp
movl %ebp, %edi
callq 0x3200
testl %eax, %eax
jne 0x80f6
movzbl %bpl, %eax
cmpl $0x24, %eax
je 0x80f6
cmpl $0x5f, %eax
jne 0x80fa
incl %ebx
jmp 0x80c6
subl %ebx, %r12d
movq (%rsp), %rdx
movl %r12d, (%rdx)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rdx)
movl 0x8(%r14), %eax
subl %ebx, %eax
movl %eax, 0x8(%rdx)
leaq 0x10(%rdx), %rdi
movl %ebx, %ecx
movq %r15, %rsi
movq %rdx, %r15
movq %r12, %rdx
callq 0x3220
movabsq $0x300000002, %rax      # imm = 0x300000002
jmp 0x8240
cmpb $0x5f, %bl
je 0x80c1
cmpl $0x24, %r13d
je 0x80c1
movq (%rsp), %rbx
movl %r15d, (%rbx)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x8(%rbx)
leaq 0x10(%rbx), %rdi
movl $0x1, %ecx
movq %r12, %rsi
movq %r15, %rdx
callq 0x3220
movq $0x0, 0x30(%rbx)
movq %r14, %rdi
callq 0x7c24
movq %rbx, %rax
jmp 0x8247
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x48(%rsp), %r15
movq %rdx, 0x8(%r15)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x3270
movq (%r15), %rdi
cmpq %rbx, %rdi
je 0x81ca
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31f0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq (%rsp), %r15
je 0x81e9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x31f0
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x8200
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x31f0
movl $0x2, %ebx
movq %r14, %rdi
callq 0x7c24
movl (%r14), %edx
subl %ebx, %edx
movl %edx, (%r15)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r15)
movl 0x8(%r14), %eax
subl %ebx, %eax
movl %eax, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq 0x10(%r14), %rsi
movl %ebx, %ecx
callq 0x3220
movabsq $0x700000005, %rax      # imm = 0x700000005
movq %rax, 0x30(%r15)
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8279
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0x8279
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x8290
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x31f0
movq %rbx, %rdi
callq 0x3350