// File: WayfireWM[P]wf-utils/wayfire/parser/condition_parser.cpp
// Function: wf::condition_parser_t::parse(wf::lexer_t&)
std::shared_ptr<condition_t> condition_parser_t::parse(lexer_t &lexer)
{
    // Peek at the first symbol to see if we consider a catch-all or catch-none condition.
    auto symbol = lexer.parse_symbol();
    lexer.reverse();

    if (symbol.type == symbol_t::type_t::KEYWORD)
    {
        auto keyword = get_string(symbol.value);
        if (keyword == "all")
        {
            _root = std::make_shared<true_condition_t>();
        }
        else if (keyword == "none")
        {
            _root = std::make_shared<false_condition_t>();
        }
        else
        {
            throw std::runtime_error("Condition parser error. Single keyword rules must be 'all' or 'none'.");
        }
    }
    else
    {
        _expression(lexer);
        lexer.reverse();
    }

    std::cout << _root->to_string() << std::endl;

    return _root;
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xd0(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0xc270
movq 0xd0(%rsp), %rdi
callq 0xcb50
jmp 0x13eed
cmpl $0x4, 0xa0(%rsp)
jne 0x14051
leaq 0xa8(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x1bea0
jmp 0x13f0f
leaq 0xb2e1(%rip), %rsi      # 0x1f1f7
leaq 0x70(%rsp), %rdi
callq 0xcc20
movb %al, 0x17(%rsp)
jmp 0x13f26
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x13f30
jmp 0x13f8c
leaq 0x60(%rsp), %rdi
callq 0x14130
jmp 0x13f3c
movq 0x28(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x141a0
leaq 0x60(%rsp), %rdi
callq 0x141d0
jmp 0x14036
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x1410d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x14042
leaq 0xb268(%rip), %rsi      # 0x1f1fb
leaq 0x70(%rsp), %rdi
callq 0xcc20
movb %al, 0x16(%rsp)
jmp 0x13fa3
movb 0x16(%rsp), %al
testb $0x1, %al
jne 0x13fad
jmp 0x13fd4
leaq 0x50(%rsp), %rdi
callq 0x141e0
jmp 0x13fb9
movq 0x28(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x14250
leaq 0x50(%rsp), %rdi
callq 0x14280
jmp 0x14034
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
leaq 0xb6e0(%rip), %rsi      # 0x1f6d0
callq 0x6100
jmp 0x13ff7
movq 0x8(%rsp), %rdi
movq 0x1afed(%rip), %rsi     # 0x2eff0
movq 0x1af9e(%rip), %rdx     # 0x2efa8
callq 0x64d0
jmp 0x14127
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
callq 0x6240
jmp 0x14042
jmp 0x14036
leaq 0x70(%rsp), %rdi
callq 0x61d0
jmp 0x14076
leaq 0x70(%rsp), %rdi
callq 0x61d0
jmp 0x1410d
movq 0x28(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x14290
jmp 0x14065
movq 0xd0(%rsp), %rdi
callq 0xcb50
jmp 0x14074
jmp 0x14076
movq 0x28(%rsp), %rdi
callq 0x9f00
movq %rax, %rsi
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq 0x30(%rsp), %rdi
callq *%rax
jmp 0x14093
movq 0x1af26(%rip), %rdi     # 0x2efc0
leaq 0x30(%rsp), %rsi
callq 0x62b0
movq %rax, (%rsp)
jmp 0x140aa
movq (%rsp), %rdi
movq 0x1aed3(%rip), %rsi     # 0x2ef88
callq 0x6340
jmp 0x140bc
leaq 0x30(%rsp), %rdi
callq 0x61d0
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x14400
leaq 0xa0(%rsp), %rdi
callq 0xc5f0
movq 0x20(%rsp), %rax
addq $0xe8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x61d0
leaq 0xa0(%rsp), %rdi
callq 0xc5f0
movq 0x98(%rsp), %rdi
callq 0x64f0
nopw (%rax,%rax)