// File: /workspace/github_cpp_makefile_star2_O2/WayfireWM[P]wf-utils/wayfire/parser/lambda_rule_parser.cpp
// Function: wf::lambda_rule_parser_t::parse(wf::lexer_t&, std::function<bool ()>, std::function<bool ()>)
std::shared_ptr<lambda_rule_t> lambda_rule_parser_t::parse(lexer_t &lexer, lambda_t if_lambda, lambda_t else_lambda)
{
    std::string signal;
    std::shared_ptr<condition_t> condition;

    try
    {
        // Expect the first symbol to be the 'on' keyword.
        auto symbol = lexer.parse_symbol();
        if ((symbol.type != symbol_t::type_t::KEYWORD) || (get_string(symbol.value) != "on"))
        {
            throw std::runtime_error("Lambda rule parser error. Expected 'on' keyword.");
        }

        // Expect a signal next.
        symbol = lexer.parse_symbol();
        if (symbol.type != symbol_t::type_t::SIGNAL)
        {
            throw std::runtime_error("Lambda rule parser error. Expected signal.");
        }
        signal = get_string(symbol.value);

        // Expect the 'if' keyword next.
        symbol = lexer.parse_symbol();
        if ((symbol.type != symbol_t::type_t::KEYWORD) || (get_string(symbol.value) != "if"))
        {
            throw std::runtime_error("Lambda rule parser error. Expected 'if' keyword.");
        }

        // Delegate to logical condition parser.
        condition = condition_parser_t().parse(lexer);

        // Expect the lexer to be at the end - 1.
        lexer.parse_symbol();
        symbol = lexer.parse_symbol();
        if (symbol.type != symbol_t::type_t::END)
        {
            std::string error = "Lambda rule parser error. Unexpected symbol: ";
            error.append(to_string(symbol));
            throw std::runtime_error(error);
        }
    }
    catch (std::runtime_error &e)
    {
        std::cout << "Malformed input:" << std::endl;
        std::cout << lexer.text() << std::endl;
        std::string pad;
        auto pos = lexer.current_symbol_position();
        for (std::size_t i = 0; i < pos; ++i)
        {
            pad.append(" ");
        }
        pad.append("^ ");
        std::cout << pad << e.what() << std::endl;
    }

    auto rule = std::make_shared<lambda_rule_t>(signal, condition);
    if (rule != nullptr)
    {
        rule->setIfLambda(if_lambda);
        rule->setElseLambda(else_lambda);
    }
    return rule;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
leaq 0xc8(%rsp), %rax
vxorps %xmm0, %xmm0, %xmm0
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %rbx
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
vmovaps %xmm0, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
movq %rdx, %rsi
callq 0x6fde
cmpl $0x4, 0x88(%rsp)
jne 0xa429
leaq 0x90(%rsp), %r13
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xad75
leaq 0x1fd4(%rip), %rsi      # 0xc1d5
leaq 0x10(%rsp), %rdi
callq 0x9467
leaq 0x10(%rsp), %rdi
movl %eax, %ebp
callq 0x50e0
testb %bpl, %bpl
jne 0xa429
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x6fde
leaq 0x88(%rsp), %rbp
leaq 0x10(%rsp), %rsi
movq %rbp, %rdi
callq 0x89ca
leaq 0x18(%rsp), %rdi
callq 0x62d0
cmpl $0x6, (%rbp)
jne 0xa461
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xad75
leaq 0x10(%rsp), %rbp
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
callq 0x5260
movq %rbp, %rdi
callq 0x50e0
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x6fde
leaq 0x88(%rsp), %rbp
leaq 0x10(%rsp), %rsi
movq %rbp, %rdi
callq 0x89ca
leaq 0x18(%rsp), %rdi
callq 0x62d0
cmpl $0x4, (%rbp)
jne 0xa445
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xad75
leaq 0x1efe(%rip), %rsi      # 0xc1c8
leaq 0x10(%rsp), %rdi
callq 0x9467
leaq 0x10(%rsp), %rdi
movl %eax, %ebp
callq 0x50e0
testb %bpl, %bpl
jne 0xa445
leaq 0x10(%rsp), %rdi
callq 0x8c30
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x8c68
leaq 0x50(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xa7cc
leaq 0x70(%rsp), %rdi
callq 0x67d4
leaq 0x10(%rsp), %rdi
callq 0xa790
leaq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x6fde
leaq 0x120(%rsp), %rdi
callq 0x62d0
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x6fde
leaq 0x88(%rsp), %rbp
leaq 0x10(%rsp), %rsi
movq %rbp, %rdi
callq 0x89ca
leaq 0x18(%rsp), %rdi
callq 0x62d0
cmpl $0x0, (%rbp)
jne 0xa491
movq %r13, %rdi
callq 0x62d0
leaq 0xb8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0xa7aa
movq (%rbx), %r12
testq %r12, %r12
je 0xa3fd
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0xa708
leaq 0xf8(%rsp), %rsi
movq %r12, %rdi
callq 0xaa30
leaq 0xf8(%rsp), %rdi
callq 0xa75a
movq (%rbx), %r15
leaq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0xa708
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0xaa9c
leaq 0xd8(%rsp), %rdi
callq 0xa75a
leaq 0x58(%rsp), %rdi
callq 0x67d4
leaq 0xb8(%rsp), %rdi
callq 0x50e0
movq %rbx, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r13
leaq 0x24f0(%rip), %rsi      # 0xc92b
movq %rax, %rdi
callq 0x50a0
jmp 0xa47b
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r13
leaq 0x2530(%rip), %rsi      # 0xc987
movq %rax, %rdi
callq 0x50a0
jmp 0xa47b
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r13
leaq 0x24e9(%rip), %rsi      # 0xc95c
movq %rax, %rdi
callq 0x50a0
movq 0x9b6e(%rip), %rsi      # 0x13ff0
movq 0x9b1f(%rip), %rdx      # 0x13fa8
movq %r13, %rdi
callq 0x5320
leaq 0x2520(%rip), %rsi      # 0xc9b8
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x61ca
leaq 0x68(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x879b
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x5390
leaq 0x68(%rsp), %rdi
callq 0x50e0
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5300
movq 0x9aff(%rip), %rsi      # 0x13ff0
movq 0x9ab0(%rip), %rdx      # 0x13fa8
movq %r13, %rdi
callq 0x5320
jmp 0xa579
movq %r13, %rdi
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
callq 0x5180
jmp 0xa581
leaq 0x68(%rsp), %rdi
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
callq 0x50e0
jmp 0xa581
jmp 0xa579
jmp 0xa5e4
jmp 0xa58d
leaq 0xd8(%rsp), %rdi
jmp 0xa543
leaq 0xf8(%rsp), %rdi
movq %rax, 0x8(%rsp)
callq 0xa75a
jmp 0xa5b7
jmp 0xa5e4
leaq 0x10(%rsp), %rdi
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
callq 0xa790
jmp 0xa5ec
jmp 0xa5e4
jmp 0xa579
jmp 0xa58d
jmp 0xa5e4
jmp 0xa5e4
jmp 0xa5e4
jmp 0xa5e4
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x50e0
jmp 0xa5ec
movq %r13, %rdi
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
callq 0x5180
jmp 0xa5ec
jmp 0xa5e4
movq %rax, 0x8(%rsp)
jmp 0xa5c3
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
jmp 0xa5f9
movq %rax, 0x8(%rsp)
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x67d4
leaq 0x58(%rsp), %rdi
callq 0x67d4
leaq 0xb8(%rsp), %rdi
callq 0x50e0
movq 0x8(%rsp), %rdi
callq 0x5340
movq %rdx, %rbp
movq %rax, 0x8(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x62d0
cmpl $0x1, %ebp
jne 0xa5c3
movq 0x8(%rsp), %rdi
callq 0x50b0
movq %rax, 0x8(%rsp)
movq 0x99a4(%rip), %rdi      # 0x13fb8
leaq 0x23cb(%rip), %rsi      # 0xc9e6
callq 0x51e0
movq %rax, %rdi
callq 0x50f0
movq %r12, %rdi
callq 0x739a
movq 0x9981(%rip), %rdi      # 0x13fb8
movq %rax, %rsi
callq 0x51d0
movq %rax, %rdi
callq 0x50f0
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x73a0
leaq 0x1a03(%rip), %rbp      # 0xc06a
leaq 0x10(%rsp), %r13
movq %rax, %r12
subq $0x1, %r12
jb 0xa682
movq %r13, %rdi
movq %rbp, %rsi
callq 0x5360
jmp 0xa66f
leaq 0x236e(%rip), %rsi      # 0xc9f7
leaq 0x10(%rsp), %rdi
callq 0x5360
movq 0x991e(%rip), %rdi      # 0x13fb8
leaq 0x10(%rsp), %rsi
callq 0x51d0
movq 0x8(%rsp), %rdi
movq %rax, %r12
movq (%rdi), %rax
callq *0x10(%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x51e0
movq %rax, %rdi
callq 0x50f0
leaq 0x10(%rsp), %rdi
callq 0x50e0
callq 0x5310
jmp 0xa383
jmp 0xa5a1
jmp 0xa6e7
movq %rax, 0x8(%rsp)
jmp 0xa6f6
leaq 0x10(%rsp), %rdi
movq %rax, 0x8(%rsp)
callq 0x50e0
callq 0x5310
jmp 0xa5c3
movq %rax, %rdi
callq 0x6205