// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x28, %rsp
movq (%rsi), %rax
movq %rsi, %rbx
movq %rdi, %r14
cmpb $0x27, (%rax)
jne 0x7d29
movq 0x8(%rbx), %rcx
cmpb $0x27, -0x1(%rax,%rcx)
jne 0x7d29
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5250
movb (%rax), %al
movq 0x8(%rbx), %rcx
cmpb $0x5c, %al
jne 0x7d6d
cmpq $0x4, %rcx
jne 0x7f00
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x5250
movb (%rax), %cl
movb $0x5c, %al
movzbl %cl, %edx
leal -0x61(%rdx), %esi
cmpl $0x5, %esi
jbe 0x7dc9
leal -0x6e(%rdx), %esi
cmpl $0x8, %esi
ja 0x7ddd
leaq 0x4580(%rip), %rcx      # 0xc29c
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movb $0xa, %al
jmp 0x7d77
leaq 0x4383(%rip), %rsi      # 0xc0b3
movq %rbx, %rdi
callq 0x73a5
testb %al, %al
jne 0x7d62
leaq 0x45be(%rip), %rsi      # 0xc301
movq %rbx, %rdi
callq 0x73a5
testb %al, %al
jne 0x7d62
leaq 0x45b0(%rip), %rsi      # 0xc306
movq %rbx, %rdi
callq 0x73a5
testb %al, %al
je 0x7d8a
movb $0x1, (%r14)
movb $0x2, 0x20(%r14)
jmp 0x7d7f
cmpq $0x3, %rcx
jne 0x7f56
movb %al, (%r14)
movb $0x1, 0x20(%r14)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
leaq 0x4327(%rip), %rsi      # 0xc0b8
movq %rbx, %rdi
callq 0x73a5
testb %al, %al
jne 0x7dc3
leaq 0x4567(%rip), %rsi      # 0xc30b
movq %rbx, %rdi
callq 0x73a5
testb %al, %al
jne 0x7dc3
leaq 0x455a(%rip), %rsi      # 0xc311
movq %rbx, %rdi
callq 0x73a5
testb %al, %al
je 0x7df0
movb $0x0, (%r14)
jmp 0x7d66
leaq 0x44b4(%rip), %rcx      # 0xc284
movslq (%rcx,%rsi,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movb $0x7, %al
jmp 0x7d77
cmpl $0x22, %edx
je 0x7dec
cmpl $0x27, %edx
je 0x7dec
cmpl $0x3f, %edx
jne 0x7d77
movl %ecx, %eax
jmp 0x7d77
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movb $0x2e, (%rdx)
addq %rdi, %rsi
callq 0x841d
cmpq $0x1, %rax
jne 0x7e7a
pushq $0x66
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x5280
cmpq $-0x1, %rax
jne 0x7e37
pushq $0x46
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x5280
cmpq $-0x1, %rax
je 0x7ee7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8192
vmovss %xmm0, (%r14)
movb $0x3, 0x20(%r14)
jmp 0x7d7f
movb $0x1b, %al
jmp 0x7d77
movb $0x8, %al
jmp 0x7d77
movb $0xc, %al
jmp 0x7d77
movb $0x9, %al
jmp 0x7d77
movb $0xd, %al
jmp 0x7d77
movb $0xb, %al
jmp 0x7d77
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movb $0x1, %sil
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x7ebd
movsbl (%rax,%rdx), %edi
leal -0x30(%rdi), %r8d
testb $0x1, %sil
je 0x7eb0
cmpl $0xa, %r8d
setb %sil
cmpb $0x2d, %dil
sete %dil
orb %sil, %dil
jne 0x7eb6
jmp 0x7ed7
cmpl $0x9, %r8d
ja 0x7ed7
incq %rdx
xorl %esi, %esi
jmp 0x7e86
pushq $0xa
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x81c4
movl %eax, (%r14)
movb $0x0, 0x20(%r14)
jmp 0x7d7f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x840e
jmp 0x7d7f
movq %rbx, %rdi
xorl %esi, %esi
callq 0x81ab
vmovsd %xmm0, (%r14)
movb $0x4, 0x20(%r14)
jmp 0x7d7f
leaq 0x43b9(%rip), %rsi      # 0xc2c0
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x61ca
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %rbx
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xc0ae(%rip), %rsi      # 0x13ff0
movq 0xc05f(%rip), %rdx      # 0x13fa8
movq %rbx, %rdi
callq 0x5320
jmp 0x8137
leaq 0x4363(%rip), %rsi      # 0xc2c0
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x61ca
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %rbx
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xc058(%rip), %rsi      # 0x13ff0
movq 0xc009(%rip), %rdx      # 0x13fa8
movq %rbx, %rdi
callq 0x5320
jmp 0x8137
movq %rax, %r14
cmpl $0x1, %edx
jne 0x818a
movq %r14, %rdi
callq 0x50b0
leaq 0x4392(%rip), %rsi      # 0xc359
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x61ca
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %rbx
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xbfee(%rip), %rsi      # 0x13ff0
movq 0xbf9f(%rip), %rdx      # 0x13fa8
movq %rbx, %rdi
callq 0x5320
jmp 0x8137
movq %rbx, %rdi
movq %rax, %r14
callq 0x5180
jmp 0x8026
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x50e0
jmp 0x8035
movq %rax, %r14
callq 0x5310
jmp 0x818a
movq %rax, %r14
cmpl $0x1, %edx
jne 0x818a
movq %r14, %rdi
callq 0x50b0
leaq 0x4342(%rip), %rsi      # 0xc39c
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x61ca
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %rbx
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xbf5b(%rip), %rsi      # 0x13ff0
movq 0xbf0c(%rip), %rdx      # 0x13fa8
movq %rbx, %rdi
callq 0x5320
jmp 0x8137
movq %rbx, %rdi
movq %rax, %r14
callq 0x5180
jmp 0x80b9
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x50e0
jmp 0x80c8
movq %rax, %r14
callq 0x5310
jmp 0x818a
movq %rax, %r14
cmpl $0x1, %edx
jne 0x818a
movq %r14, %rdi
callq 0x50b0
leaq 0x422a(%rip), %rsi      # 0xc317
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x61ca
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x5390
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %rbx
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0xbec8(%rip), %rsi      # 0x13ff0
movq 0xbe79(%rip), %rdx      # 0x13fa8
movq %rbx, %rdi
callq 0x5320
movq %rbx, %rdi
movq %rax, %r14
callq 0x5180
jmp 0x8147
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x50e0
jmp 0x8156
movq %rax, %r14
callq 0x5310
jmp 0x818a
movq %rax, %rdi
callq 0x6205
jmp 0x8167
movq %rbx, %rdi
movq %rax, %r14
callq 0x5180
jmp 0x8179
jmp 0x8176
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x50e0
jmp 0x818a
jmp 0x8187
movq %rax, %r14
movq %r14, %rdi
callq 0x5340