// File: 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:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x70(%rsp)
movq %rdi, %rax
movq %rax, 0x78(%rsp)
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rdi
callq 0x63f0
movsbl (%rax), %eax
cmpl $0x27, %eax
jne 0x104dd
movq 0x1c8(%rsp), %rdi
callq 0x6160
movsbl (%rax), %eax
cmpl $0x27, %eax
jne 0x104dd
movq 0x1c8(%rsp), %rdi
movl $0x1, %esi
callq 0x63c0
movb (%rax), %al
movb %al, 0x1c7(%rsp)
movsbl 0x1c7(%rsp), %eax
cmpl $0x5c, %eax
jne 0x103af
movq 0x1c8(%rsp), %rdi
callq 0x6200
cmpq $0x4, %rax
je 0x102f7
leaq 0x19f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x6500
movq 0x68(%rsp), %rdx
leaq 0xf1e1(%rip), %rsi      # 0x1f3f8
leaq 0x1a0(%rsp), %rdi
callq 0x8280
jmp 0x10226
leaq 0x19f(%rsp), %rdi
callq 0x6360
movq 0x1c8(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x6560
jmp 0x1024a
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x60(%rsp)
leaq 0x1a0(%rsp), %rsi
callq 0x64a0
jmp 0x1026e
movq 0x60(%rsp), %rdi
movq 0x1ed76(%rip), %rsi     # 0x2eff0
movq 0x1ed27(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x10c0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x19f(%rsp), %rdi
callq 0x6360
jmp 0x10bf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x102e5
movq 0x60(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
callq 0x6240
leaq 0x1a0(%rsp), %rdi
callq 0x61d0
jmp 0x10bf5
movq 0x1c8(%rsp), %rdi
movl $0x2, %esi
callq 0x63c0
movsbl (%rax), %eax
addl $-0x22, %eax
movl %eax, %ecx
movq %rcx, 0x58(%rsp)
subl $0x54, %eax
ja 0x103aa
movq 0x58(%rsp), %rax
leaq 0xef79(%rip), %rcx      # 0x1f2a4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x7, 0x1c7(%rsp)
jmp 0x103aa
movb $0x8, 0x1c7(%rsp)
jmp 0x103aa
movb $0x1b, 0x1c7(%rsp)
jmp 0x103aa
movb $0xc, 0x1c7(%rsp)
jmp 0x103aa
movb $0xa, 0x1c7(%rsp)
jmp 0x103aa
movb $0xd, 0x1c7(%rsp)
jmp 0x103aa
movb $0x9, 0x1c7(%rsp)
jmp 0x103aa
movb $0xb, 0x1c7(%rsp)
jmp 0x103aa
movb $0x5c, 0x1c7(%rsp)
jmp 0x103aa
movb $0x27, 0x1c7(%rsp)
jmp 0x103aa
movb $0x22, 0x1c7(%rsp)
jmp 0x103aa
movb $0x3f, 0x1c7(%rsp)
jmp 0x104c6
movq 0x1c8(%rsp), %rdi
callq 0x6200
cmpq $0x3, %rax
je 0x104c4
leaq 0x167(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x6500
movq 0x50(%rsp), %rdx
leaq 0xf014(%rip), %rsi      # 0x1f3f8
leaq 0x168(%rsp), %rdi
callq 0x8280
jmp 0x103f3
leaq 0x167(%rsp), %rdi
callq 0x6360
movq 0x1c8(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0x6560
jmp 0x10417
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x48(%rsp)
leaq 0x168(%rsp), %rsi
callq 0x64a0
jmp 0x1043b
movq 0x48(%rsp), %rdi
movq 0x1eba9(%rip), %rsi     # 0x2eff0
movq 0x1eb5a(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x10c0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x167(%rsp), %rdi
callq 0x6360
jmp 0x10bf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x104b2
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
callq 0x6240
leaq 0x168(%rsp), %rdi
callq 0x61d0
jmp 0x10bf5
jmp 0x104c6
movq 0x70(%rsp), %rdi
leaq 0x1c7(%rsp), %rsi
callq 0x10c10
jmp 0x10be8
movq 0x1c8(%rsp), %rdi
leaq 0xebc7(%rip), %rsi      # 0x1f0b3
callq 0xcc20
testb $0x1, %al
jne 0x10527
movq 0x1c8(%rsp), %rdi
leaq 0xef35(%rip), %rsi      # 0x1f439
callq 0xcc20
testb $0x1, %al
jne 0x10527
movq 0x1c8(%rsp), %rdi
leaq 0xef22(%rip), %rsi      # 0x1f43e
callq 0xcc20
testb $0x1, %al
jne 0x10527
jmp 0x10546
movq 0x70(%rsp), %rdi
movb $0x1, 0x166(%rsp)
leaq 0x166(%rsp), %rsi
callq 0x10c40
jmp 0x10be8
movq 0x1c8(%rsp), %rdi
leaq 0xeb63(%rip), %rsi      # 0x1f0b8
callq 0xcc20
testb $0x1, %al
jne 0x10590
movq 0x1c8(%rsp), %rdi
leaq 0xeed6(%rip), %rsi      # 0x1f443
callq 0xcc20
testb $0x1, %al
jne 0x10590
movq 0x1c8(%rsp), %rdi
leaq 0xeec4(%rip), %rsi      # 0x1f449
callq 0xcc20
testb $0x1, %al
jne 0x10590
jmp 0x105af
movq 0x70(%rsp), %rdi
movb $0x0, 0x165(%rsp)
leaq 0x165(%rsp), %rsi
callq 0x10c40
jmp 0x10be8
movq 0x1c8(%rsp), %rdi
callq 0x10cc0
movq %rax, 0x158(%rsp)
movq 0x1c8(%rsp), %rdi
callq 0x10cf0
movq %rax, 0x150(%rsp)
movb $0x2e, 0x14f(%rsp)
movq 0x158(%rsp), %rdi
movq 0x150(%rsp), %rsi
leaq 0x14f(%rsp), %rdx
callq 0x10c70
cmpq $0x1, %rax
jne 0x10940
movq 0x1c8(%rsp), %rdi
movl $0x66, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x6410
cmpq $-0x1, %rax
jne 0x10644
movq 0x1c8(%rsp), %rdi
movl $0x46, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x6410
cmpq $-0x1, %rax
je 0x107c2
movq 0x1c8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d20
vmovss %xmm0, 0x44(%rsp)
jmp 0x1065d
movq 0x70(%rsp), %rdi
vmovss 0x44(%rsp), %xmm0
vmovss %xmm0, 0x148(%rsp)
leaq 0x148(%rsp), %rsi
callq 0x10d60
jmp 0x10be8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
movl 0x18c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x10bf5
movq 0x190(%rsp), %rdi
callq 0x6110
movq %rax, 0x140(%rsp)
leaq 0x11f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x6500
movq 0x38(%rsp), %rdx
leaq 0xed71(%rip), %rsi      # 0x1f44f
leaq 0x120(%rsp), %rdi
callq 0x8280
jmp 0x106ed
leaq 0x11f(%rsp), %rdi
callq 0x6360
movq 0x1c8(%rsp), %rsi
leaq 0x120(%rsp), %rdi
callq 0x6560
jmp 0x10711
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
leaq 0x120(%rsp), %rsi
callq 0x64a0
jmp 0x10735
movq 0x30(%rsp), %rdi
movq 0x1e8af(%rip), %rsi     # 0x2eff0
movq 0x1e860(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x10c0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x11f(%rsp), %rdi
callq 0x6360
jmp 0x107b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x107a9
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
callq 0x6240
leaq 0x120(%rsp), %rdi
callq 0x61d0
callq 0x64b0
jmp 0x107bd
jmp 0x10bf5
movq 0x1c8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d90
vmovsd %xmm0, 0x28(%rsp)
jmp 0x107db
movq 0x70(%rsp), %rdi
vmovsd 0x28(%rsp), %xmm0
vmovsd %xmm0, 0x110(%rsp)
leaq 0x110(%rsp), %rsi
callq 0x10dd0
jmp 0x10be8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
movl 0x18c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x10bf5
movq 0x190(%rsp), %rdi
callq 0x6110
movq %rax, 0x108(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x6500
movq 0x20(%rsp), %rdx
leaq 0xec35(%rip), %rsi      # 0x1f491
leaq 0xe8(%rsp), %rdi
callq 0x8280
jmp 0x1086b
leaq 0xe7(%rsp), %rdi
callq 0x6360
movq 0x1c8(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x6560
jmp 0x1088f
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
leaq 0xe8(%rsp), %rsi
callq 0x64a0
jmp 0x108b3
movq 0x18(%rsp), %rdi
movq 0x1e731(%rip), %rsi     # 0x2eff0
movq 0x1e6e2(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x10c0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0xe7(%rsp), %rdi
callq 0x6360
jmp 0x10934
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x10927
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
callq 0x6240
leaq 0xe8(%rsp), %rdi
callq 0x61d0
callq 0x64b0
jmp 0x1093b
jmp 0x10bf5
movb $0x1, 0xe6(%rsp)
movb $0x1, 0xe5(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x62d0
movq %rax, 0xd0(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x6530
movq %rax, 0xc8(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x10e00
testb $0x1, %al
jne 0x109a8
jmp 0x10a51
leaq 0xd0(%rsp), %rdi
callq 0x10e40
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movsbl (%rax), %edi
callq 0x62c0
movl %eax, 0xbc(%rsp)
movq 0xc0(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
sete %al
andb $0x1, %al
movb %al, 0xbb(%rsp)
testb $0x1, 0xe5(%rsp)
je 0x10a27
movb $0x0, 0xe5(%rsp)
movl 0xbc(%rsp), %eax
movb 0xbb(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
jne 0x10a25
movb $0x0, 0xe6(%rsp)
jmp 0x10a51
jmp 0x10a3d
cmpl $0x0, 0xbc(%rsp)
jne 0x10a3b
movb $0x0, 0xe6(%rsp)
jmp 0x10a51
jmp 0x10a3d
jmp 0x10a3f
leaq 0xd0(%rsp), %rdi
callq 0x10e50
jmp 0x1098a
testb $0x1, 0xe6(%rsp)
je 0x10bd6
movq 0x1c8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x10e70
movl %eax, 0x14(%rsp)
jmp 0x10a7b
movq 0x70(%rsp), %rdi
movl 0x14(%rsp), %eax
movl %eax, 0xb4(%rsp)
leaq 0xb4(%rsp), %rsi
callq 0x10ec0
jmp 0x10be8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
movl 0x18c(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x10bf5
movq 0x190(%rsp), %rdi
callq 0x6110
movq %rax, 0xa8(%rsp)
leaq 0x87(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x6500
movq 0x8(%rsp), %rdx
leaq 0xe9dc(%rip), %rsi      # 0x1f4d4
leaq 0x88(%rsp), %rdi
callq 0x8280
jmp 0x10b07
leaq 0x87(%rsp), %rdi
callq 0x6360
movq 0x1c8(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x6560
jmp 0x10b2b
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, (%rsp)
leaq 0x88(%rsp), %rsi
callq 0x64a0
jmp 0x10b4e
movq (%rsp), %rdi
movq 0x1e497(%rip), %rsi     # 0x2eff0
movq 0x1e448(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x10c0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x87(%rsp), %rdi
callq 0x6360
jmp 0x10bcd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x10bc0
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
callq 0x6240
leaq 0x88(%rsp), %rdi
callq 0x61d0
callq 0x64b0
jmp 0x10bd4
jmp 0x10bf5
movq 0x70(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0x10ef0
movq 0x78(%rsp), %rax
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0x190(%rsp), %rdi
callq 0x64f0
movq %rax, %rdi
callq 0x8340
nopw (%rax,%rax)