// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movq (%rsi), %rcx
cmpb $0x27, (%rcx)
jne 0x818d
movq 0x8(%r14), %rdx
cmpb $0x27, -0x1(%rcx,%rdx)
jne 0x818d
cmpq $0x1, %rdx
jbe 0x83c4
movb 0x1(%rcx), %al
cmpb $0x5c, %al
jne 0x8297
cmpq $0x4, %rdx
jne 0x83d7
movb 0x2(%rcx), %cl
movzbl %cl, %edx
cmpl $0x5b, %edx
jg 0x82b5
cmpl $0x22, %edx
je 0x8186
cmpl $0x27, %edx
je 0x8186
cmpl $0x3f, %edx
jne 0x82a1
movl %ecx, %eax
jmp 0x82a1
leaq 0x4f1f(%rip), %rsi      # 0xd0b3
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x828b
leaq 0x51ae(%rip), %rsi      # 0xd359
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x828b
leaq 0x519c(%rip), %rsi      # 0xd35e
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x828b
leaq 0x4edf(%rip), %rsi      # 0xd0b8
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8292
leaq 0x5173(%rip), %rsi      # 0xd363
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8292
leaq 0x5162(%rip), %rsi      # 0xd369
movq %r14, %rdi
callq 0x5080
testl %eax, %eax
je 0x8292
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x8357
movq (%r14), %rsi
leaq (%rsi,%rax), %rdx
xorl %ecx, %ecx
xorl %edi, %edi
xorl %r8d, %r8d
cmpb $0x2e, (%rsi,%rcx)
sete %r8b
addq %r8, %rdi
incq %rcx
cmpq %rcx, %rax
jne 0x822b
cmpq $0x1, %rdi
jne 0x82ed
movq %r14, %rdi
movl $0x66, %esi
xorl %edx, %edx
callq 0x52b0
cmpq $-0x1, %rax
jne 0x8279
movq %r14, %rdi
movl $0x46, %esi
xorl %edx, %edx
callq 0x52b0
cmpq $-0x1, %rax
je 0x83af
movq %r14, %rdi
xorl %esi, %esi
callq 0x86d3
vmovss %xmm0, (%rbx)
movb $0x3, %al
jmp 0x82a5
movb $0x1, (%rbx)
movb $0x2, %al
jmp 0x82a5
movb $0x0, (%rbx)
jmp 0x828e
cmpq $0x3, %rdx
jne 0x8438
movb %al, (%rbx)
movb $0x1, %al
movb %al, 0x20(%rbx)
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
leal -0x5c(%rdx), %esi
cmpl $0xa, %esi
ja 0x82d1
leaq 0x5004(%rip), %rdx      # 0xd2c8
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movb $0x7, %al
jmp 0x82a1
addl $-0x6e, %edx
cmpl $0x8, %edx
ja 0x82a1
leaq 0x5014(%rip), %rcx      # 0xd2f4
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movb $0xa, %al
jmp 0x82a1
decq %rax
movb $0x1, %r8b
xorl %ecx, %ecx
movb $0x1, %dil
movsbl (%rsi,%rcx), %r9d
leal -0x30(%r9), %r10d
testb $0x1, %dil
je 0x8329
cmpl $0xa, %r10d
setb %r10b
cmpb $0x2d, %r9b
sete %r9b
xorl %edi, %edi
orb %r10b, %r9b
movb $0x1, %r10b
movl $0x0, %r9d
jne 0x832f
jmp 0x833d
cmpl $0x9, %r10d
ja 0x8337
xorl %r10d, %r10d
movl %r8d, %r9d
jmp 0x833d
movb $0x1, %r10b
xorl %r9d, %r9d
testb %r10b, %r10b
jne 0x8351
leaq 0x1(%rcx), %r10
movl %r9d, %r8d
cmpq %rcx, %rax
movq %r10, %rcx
jne 0x82f8
testb $0x1, %r9b
je 0x836f
movq %r14, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x87db
movl %eax, (%rbx)
xorl %eax, %eax
jmp 0x82a5
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq %rbx, %rdi
callq 0x6214
movb $0x5, %al
jmp 0x82a5
movb $0xc, %al
jmp 0x82a1
movb $0x1b, %al
jmp 0x82a1
movb $0x8, %al
jmp 0x82a1
movb $0xb, %al
jmp 0x82a1
movb $0xd, %al
jmp 0x82a1
movb $0x9, %al
jmp 0x82a1
movq %r14, %rdi
xorl %esi, %esi
callq 0x8757
vmovsd %xmm0, (%rbx)
movb $0x4, %al
jmp 0x82a5
leaq 0x4e9f(%rip), %rdi      # 0xd26a
movl $0x1, %esi
xorl %eax, %eax
callq 0x5300
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4f31(%rip), %rsi      # 0xd318
leaq 0x4f6a(%rip), %rdx      # 0xd358
movq %rsp, %rdi
callq 0x6382
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xbbcc(%rip), %rsi      # 0x13ff0
movq 0xbb8d(%rip), %rdx      # 0x13fb8
movq %r14, %rdi
callq 0x5370
jmp 0x866f
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4ed0(%rip), %rsi      # 0xd318
leaq 0x4f09(%rip), %rdx      # 0xd358
movq %rsp, %rdi
callq 0x6382
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xbb6b(%rip), %rsi      # 0x13ff0
movq 0xbb2c(%rip), %rdx      # 0x13fb8
movq %r14, %rdi
callq 0x5370
jmp 0x866f
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x86cb
movq %rbx, %rdi
callq 0x50e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4ef4(%rip), %rsi      # 0xd3b1
leaq 0x4f2f(%rip), %rdx      # 0xd3f3
movq %rsp, %rdi
callq 0x6382
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xbaf6(%rip), %rsi      # 0x13ff0
movq 0xbab7(%rip), %rdx      # 0x13fb8
movq %r14, %rdi
callq 0x5370
jmp 0x866f
movq %rax, %rbx
movq %r14, %rdi
callq 0x51a0
jmp 0x851e
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x8539
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x8539
movq %rax, %rbx
callq 0x5360
jmp 0x86cb
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x86cb
movq %rbx, %rdi
callq 0x50e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4e08(%rip), %rsi      # 0xd36f
leaq 0x4e42(%rip), %rdx      # 0xd3b0
movq %rsp, %rdi
callq 0x6382
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xba4c(%rip), %rsi      # 0x13ff0
movq 0xba0d(%rip), %rdx      # 0x13fb8
movq %r14, %rdi
callq 0x5370
jmp 0x866f
movq %rax, %rbx
movq %r14, %rdi
callq 0x51a0
jmp 0x85c8
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x85e3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x85e3
movq %rax, %rbx
callq 0x5360
jmp 0x86cb
jmp 0x85ef
movq %rax, %rbx
movq %r14, %rdi
callq 0x51a0
jmp 0x86ae
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x86cb
movq %rbx, %rdi
callq 0x50e0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4dd1(%rip), %rsi      # 0xd3f4
leaq 0x4e09(%rip), %rdx      # 0xd433
movq %rsp, %rdi
callq 0x6382
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rsp, %rdi
callq 0x5090
movl $0x10, %edi
callq 0x5110
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x5350
movq 0xb990(%rip), %rsi      # 0x13ff0
movq 0xb951(%rip), %rdx      # 0x13fb8
movq %r14, %rdi
callq 0x5370
movq %rax, %rbx
movq %r14, %rdi
callq 0x51a0
jmp 0x867f
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x869a
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x869a
movq %rax, %rbx
callq 0x5360
jmp 0x86cb
movq %rax, %rdi
callq 0x6209
jmp 0x86ab
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x86cb
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x86cb
jmp 0x86c8
movq %rax, %rbx
movq %rbx, %rdi
callq 0x5390