// File: /workspace/github_cpp_makefile_star2_O3/WayfireWM[P]wf-utils/wayfire/lexer/literal.cpp
// Function: wf::parse_literal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
variant_t parse_literal(const std::string &s)
{
    // Deal with char literal
    if ((s.front() == '\'') && (s.back() == '\''))
    {
        char c = s.at(1);
        if (c == '\\')
        {
            if (s.size() != 4)
            {
                std::string error = "Literal parser error. Text could not be converted to char. text:";
                error.append(s);
                throw std::runtime_error(error);
            }

            switch (s.at(2))
            {
            case 'a': // bell
                c = '\a';
                break;
            case 'b': // backspace
                c = '\b';
                break;
            case 'e': // escape
                c = 0x1b;
                break;
            case 'f': // form feed
                c = '\f';
                break;
            case 'n': // newline
                c = '\n';
                break;
            case 'r': // carriage return
                c = '\r';
                break;
            case 't': // tab
                c = '\t';
                break;
            case 'v': // vertical tab
                c = '\v';
                break;
            case '\\': // backslash
                c = '\\';
                break;
            case '\'': // apostrophe
                c = '\'';
                break;
            case '\"': // quotation mark
                c = '\"';
                break;
            case '\?': // question mark
                c = '\?';
                break;
            }
        }
        else
        {
            if (s.size() != 3)
            {
                std::string error = "Literal parser error. Text could not be converted to char. text:";
                error.append(s);
                throw std::runtime_error(error);
            }
        }

        return variant_t(c);
    }

    // Deal with boolean literal.
    if ((s == "true") || (s == "TRUE") || (s == "True"))
    {
        return variant_t(true);
    }
    if ((s == "false") || (s == "FALSE") || (s == "False"))
    {
        return variant_t(false);
    }

    // Deal with float or double here.
    if (std::count(std::begin(s), std::end(s), '.') == 1)
    {
        // Float or Double.
        if ((s.find('f') != std::string::npos) || (s.find('F') != std::string::npos))
        {
            // Float.
            try
            {
                return variant_t(std::stof(s));
            }
            catch (std::logic_error &)
            {
                std::string error = "Literal parser error. Text could not be converted to float. text:";
                error.append(s);
                throw std::runtime_error(error);
            }
        }
        else
        {
            // Double.
            try
            {
                return variant_t(std::stod(s));
            }
            catch (std::logic_error &)
            {
                std::string error = "Literal parser error. Text could not be converted to double. text:";
                error.append(s);
                throw std::runtime_error(error);
            }
        }
    }

    // Assume literal will be an integer and test the assumption by looking at all characters.
    auto integer = true;
    auto first = true;
    for (const auto &c : s)
    {
        auto digit = std::isdigit(c);
        auto hyphen = (c == '-');

        if (first)
        {
            first = false;
            if (!(digit | hyphen))
            {
                integer = false;
                break;
            }
        }
        else
        {
            if (!(digit))
            {
                integer = false;
                break;
            }
        }
    }
    if (integer)
    {
        try
        {
            return variant_t(std::stoi(s));
        }
        catch (std::logic_error &)
        {
            std::string error = "Literal parser error. Text could not be converted to int. text:";
            error.append(s);
            throw std::runtime_error(error);
        }
    }

    // If we get here, the text is a string.
    return variant_t(s);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq (%rsi), %rcx
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x27, (%rcx)
jne 0x8132
movq 0x8(%r14), %rdx
cmpb $0x27, -0x1(%rcx,%rdx)
jne 0x8132
cmpq $0x1, %rdx
jbe 0x833f
movb 0x1(%rcx), %al
cmpb $0x5c, %al
jne 0x823c
cmpq $0x4, %rdx
jne 0x8352
movb 0x2(%rcx), %dl
movb $0x5c, %al
movzbl %dl, %ecx
cmpl $0x60, %ecx
jg 0x825a
cmpl $0x22, %ecx
je 0x812b
cmpl $0x27, %ecx
je 0x812b
cmpl $0x3f, %ecx
jne 0x8246
movl %edx, %eax
jmp 0x8246
leaq 0x3f7a(%rip), %rsi      # 0xc0b3
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8230
leaq 0x41f5(%rip), %rsi      # 0xc345
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8230
leaq 0x41e3(%rip), %rsi      # 0xc34a
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8230
leaq 0x3f3a(%rip), %rsi      # 0xc0b8
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8237
leaq 0x41ba(%rip), %rsi      # 0xc34f
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8237
leaq 0x41a9(%rip), %rsi      # 0xc355
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8237
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x82d2
movq (%r14), %rsi
xorl %ecx, %ecx
xorl %edi, %edi
leaq (%rsi,%rax), %rdx
xorl %r8d, %r8d
cmpb $0x2e, (%rsi,%rcx)
sete %r8b
incq %rcx
addq %r8, %rdi
cmpq %rcx, %rax
jne 0x81d0
cmpq $0x1, %rdi
jne 0x8292
movl $0x66, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x52b0
cmpq $-0x1, %rax
jne 0x821e
movl $0x46, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x52b0
cmpq $-0x1, %rax
je 0x832a
movq %r14, %rdi
xorl %esi, %esi
callq 0x864e
vmovss %xmm0, (%rbx)
movb $0x3, %al
jmp 0x824a
movb $0x1, (%rbx)
movb $0x2, %al
jmp 0x824a
movb $0x0, (%rbx)
jmp 0x8233
cmpq $0x3, %rdx
jne 0x83b3
movb %al, (%rbx)
movb $0x1, %al
movb %al, 0x20(%rbx)
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
leal -0x61(%rcx), %edx
cmpl $0x5, %edx
jbe 0x827e
addl $-0x6e, %ecx
cmpl $0x8, %ecx
ja 0x8246
leaq 0x406f(%rip), %rdx      # 0xc2e0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movb $0xa, %al
jmp 0x8246
leaq 0x4043(%rip), %rcx      # 0xc2c8
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movb $0x7, %al
jmp 0x8246
testq %rax, %rax
je 0x82d2
movb $0x1, %dil
xorl %ecx, %ecx
movsbl (%rsi,%rcx), %r8d
leal -0x30(%r8), %r9d
testb $0x1, %dil
je 0x82c2
cmpl $0xa, %r9d
setb %dil
cmpb $0x2d, %r8b
sete %r8b
orb %dil, %r8b
jne 0x82c8
jmp 0x8314
cmpl $0x9, %r9d
ja 0x8314
incq %rcx
xorl %edi, %edi
cmpq %rcx, %rax
jne 0x829c
movl $0xa, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8756
movl %eax, (%rbx)
xorl %eax, %eax
jmp 0x824a
movb $0xc, %al
jmp 0x8246
movb $0x8, %al
jmp 0x8246
movb $0x1b, %al
jmp 0x8246
movb $0xb, %al
jmp 0x8246
movb $0xd, %al
jmp 0x8246
movb $0x9, %al
jmp 0x8246
leaq 0x10(%rbx), %rax
movq %rbx, %rdi
movq %rax, (%rbx)
callq 0x6214
movb $0x5, %al
jmp 0x824a
movq %r14, %rdi
xorl %esi, %esi
callq 0x86d2
vmovsd %xmm0, (%rbx)
movb $0x4, %al
jmp 0x824a
leaq 0x3f24(%rip), %rdi      # 0xc26a
movl $0x1, %esi
xorl %eax, %eax
callq 0x5300
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3fa2(%rip), %rsi      # 0xc304
leaq 0x3fdb(%rip), %rdx      # 0xc344
movq %rsp, %rdi
callq 0x6386
movq 0x8(%r14), %rdx
movq (%r14), %rsi
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xac51(%rip), %rsi      # 0x12ff0
movq 0xac12(%rip), %rdx      # 0x12fb8
movq %r14, %rdi
callq 0x5370
jmp 0x85ea
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3f41(%rip), %rsi      # 0xc304
leaq 0x3f7a(%rip), %rdx      # 0xc344
movq %rsp, %rdi
callq 0x6386
movq 0x8(%r14), %rdx
movq (%r14), %rsi
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xabf0(%rip), %rsi      # 0x12ff0
movq 0xabb1(%rip), %rdx      # 0x12fb8
movq %r14, %rdi
callq 0x5370
jmp 0x85ea
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8646
movq %rbx, %rdi
callq 0x50e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3f65(%rip), %rsi      # 0xc39d
leaq 0x3fa0(%rip), %rdx      # 0xc3df
movq %rsp, %rdi
callq 0x6386
movq 0x8(%r14), %rdx
movq (%r14), %rsi
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xab7b(%rip), %rsi      # 0x12ff0
movq 0xab3c(%rip), %rdx      # 0x12fb8
movq %r14, %rdi
callq 0x5370
jmp 0x85ea
movq %r14, %rdi
movq %rax, %rbx
callq 0x51a0
jmp 0x8499
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x84b4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x84b4
movq %rax, %rbx
callq 0x5360
jmp 0x8646
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8646
movq %rbx, %rdi
callq 0x50e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3e79(%rip), %rsi      # 0xc35b
leaq 0x3eb3(%rip), %rdx      # 0xc39c
movq %rsp, %rdi
callq 0x6386
movq 0x8(%r14), %rdx
movq (%r14), %rsi
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xaad1(%rip), %rsi      # 0x12ff0
movq 0xaa92(%rip), %rdx      # 0x12fb8
movq %r14, %rdi
callq 0x5370
jmp 0x85ea
movq %r14, %rdi
movq %rax, %rbx
callq 0x51a0
jmp 0x8543
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x855e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x855e
movq %rax, %rbx
callq 0x5360
jmp 0x8646
jmp 0x856a
movq %r14, %rdi
movq %rax, %rbx
callq 0x51a0
jmp 0x8629
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8646
movq %rbx, %rdi
callq 0x50e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3e42(%rip), %rsi      # 0xc3e0
leaq 0x3e7a(%rip), %rdx      # 0xc41f
movq %rsp, %rdi
callq 0x6386
movq 0x8(%r14), %rdx
movq (%r14), %rsi
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xaa15(%rip), %rsi      # 0x12ff0
movq 0xa9d6(%rip), %rdx      # 0x12fb8
movq %r14, %rdi
callq 0x5370
movq %r14, %rdi
movq %rax, %rbx
callq 0x51a0
jmp 0x85fa
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x8615
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x8615
movq %rax, %rbx
callq 0x5360
jmp 0x8646
movq %rax, %rdi
callq 0x6209
jmp 0x8626
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x8646
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x8646
jmp 0x8643
movq %rax, %rbx
movq %rbx, %rdi
callq 0x5390