// File: /workspace/github_cpp_makefile_star2_O1/WayfireWM[P]wf-utils/main.cpp
// Function: main
int main()
{
    /*
    lexer_t lexer("(a equals 3 | a equals 2) & (! x equals 4)");
    condition_parser_t parser;

    try
    {
        auto condition = parser.parse(lexer);
    }
    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;

    }
    */

    /*
    std::string text_reverse = "one two three four five";

    auto data = std::make_shared<test_t>();
    data->property_a = 4;
    data->title = "Alacritty";

    test_access_interface_t access_interface(data);
    test_action_interface_t action_interface(data);

    std::vector<std::string> text = {
        "on created if property_a equals 4 then set property_b 0.4",
        "on created if (property_a equals 4) | (property_a equals 8) then maximize else minimize",
        "on created then minimize",
        "on created then maximize else minimize",
        "on created if title contains \"   Alacritty   \" then maximize"
    };

    wf::lexer_t lexer;
    wf::rule_parser_t rule_parser;

    std::vector<std::shared_ptr<wf::rule_t>> rules;

    for (const auto &t : text)
    {
        lexer.reset(t);
        rules.push_back(rule_parser.parse(lexer));
    }

    for (auto rule : rules)
    {
        rule->apply("created", access_interface, action_interface);
    }
    */

    auto data = std::make_shared<test_t>();
    data->property_a = 4;
    data->title = "Alacritty";

    test_access_interface_t access_interface(data);
//    test_action_interface_t action_interface(data);

//    std::vector<std::string> text = {
//        "property_a equals 4",
//        "all",
//        "none",
//        "then",
//        "title contains \"   Alacritty   \""
//    };

//    wf::lexer_t lexer;
//    wf::condition_parser_t parser;

//    std::vector<std::shared_ptr<wf::condition_t>> conditions;

//    for (const auto &t : text)
//    {
//        lexer.reset(t);
//        conditions.push_back(parser.parse(lexer));
//    }

    std::string text = "on fullscreened if title contains \"Alacritty\" & property_a equals 4";
    wf::lambda_rule_parser_t parser;

    auto rule = parser.parse(text, &if_function, &else_function);

    std::cout << "rule: " << rule->to_string() << std::endl;

    auto error = rule->apply("fullscreened", access_interface);
    if (error)
    {
        std::cout << "Error!" << std::endl;
    }


    /*

    lexer.reset(text_reverse);

    auto s = lexer.parse_symbol();
    auto p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    lexer.reverse();
    p = lexer.current_symbol_position();
    std::cout << "reversed to p: " << p << std::endl;

    s = lexer.parse_symbol();
    p = lexer.current_symbol_position();
    std::cout << "p: " << p << " s: " << s.to_string() << std::endl;
*/
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl $0x40, %edi
callq 0x5220
movq %rax, %r14
movq %rax, %rbx
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x81e8(%rip), %rax      # 0x13d18
movq %rax, (%r14)
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x10(%r14)
vmovups %ymm0, 0x20(%r14)
leaq 0x18(%r14), %rdi
leaq 0x28(%r14), %rax
movq %rax, 0x18(%r14)
movq $0x0, 0x20(%r14)
movb $0x0, 0x28(%r14)
movl $0x4, 0x10(%r14)
leaq 0x224a(%rip), %rcx      # 0xddb5
movl $0x9, %r8d
xorl %esi, %esi
xorl %edx, %edx
vzeroupper
callq 0x5320
addq $0x10, %r14
movq 0x8438(%rip), %rax      # 0x13fc0
cmpb $0x0, (%rax)
je 0xbb92
incl 0x8(%rbx)
jmp 0xbb96
lock
incl 0x8(%rbx)
leaq 0x812b(%rip), %r15      # 0x13cc8
movq %r15, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
cmpb $0x0, (%rax)
je 0xbbb6
incl 0x8(%rbx)
jmp 0xbbba
lock
incl 0x8(%rbx)
movq %rbx, %rdi
callq 0x6968
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x21ec(%rip), %rsi      # 0xddbf
leaq 0x2228(%rip), %rdx      # 0xde02
leaq 0x50(%rsp), %rdi
callq 0x6382
vxorps %xmm0, %xmm0, %xmm0
leaq 0x90(%rsp), %rcx
vmovups %ymm0, (%rcx)
leaq -0x18f(%rip), %rax      # 0xba6c
movq %rax, (%rcx)
leaq 0x459(%rip), %rax       # 0xc05e
movq %rax, 0x18(%rcx)
leaq 0x450(%rip), %rdx       # 0xc060
movq %rdx, 0x10(%rcx)
leaq 0x70(%rsp), %r8
vmovups %ymm0, (%r8)
leaq -0x172(%rip), %rsi      # 0xbab3
movq %rsi, (%r8)
movq %rax, 0x18(%r8)
movq %rdx, 0x10(%r8)
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rsi
leaq 0x50(%rsp), %rdx
vzeroupper
callq 0xa4dc
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0xbc63
leaq 0x70(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0xbc82
leaq 0x90(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x833f(%rip), %rdi      # 0x13fc8
leaq 0x2173(%rip), %rsi      # 0xde03
movl $0x6, %edx
callq 0x5270
movq 0x40(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0xb204
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x830e(%rip), %rdi      # 0x13fc8
callq 0x5270
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5200
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5160
leaq 0x18(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0xbd04
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x40(%rsp), %r14
leaq 0x8(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x1490(%rip), %rsi      # 0xd1a8
leaq 0x1495(%rip), %rdx      # 0xd1b4
callq 0x6382
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
callq 0xb168
movl %eax, %ebp
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0xbd4f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5230
testb %bpl, %bpl
je 0xbd9a
movq 0x826d(%rip), %r14      # 0x13fc8
leaq 0x20a8(%rip), %rsi      # 0xde0a
movl $0x6, %edx
movq %r14, %rdi
callq 0x5270
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x5200
movsbl %al, %esi
movq 0x823b(%rip), %rdi      # 0x13fc8
callq 0x5030
movq %rax, %rdi
callq 0x5160
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xbda9
callq 0x6968
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0xbdc0
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5230
movq %r15, 0x28(%rsp)
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xbdd4
callq 0x6968
movq %rbx, %rdi
callq 0x6968
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xbe4b
jmp 0xbe4b
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
jne 0xbe73
jmp 0xbe80
jmp 0xbe5d
jmp 0xbe5d
jmp 0xbe5d
movq %rax, %r14
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0xbe28
leaq 0x70(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0xbe8f
leaq 0x90(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xbe8f
jmp 0xbe4b
movq %rax, %rdi
callq 0x6209
movq %rax, %r14
jmp 0xbea6
movq %rax, %r14
jmp 0xbeba
movq %rax, %r14
jmp 0xbe80
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbe80
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xbe8f
callq 0x6968
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0xbea6
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5230
movq %r15, 0x28(%rsp)
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xbeba
callq 0x6968
movq %rbx, %rdi
callq 0x6968
movq %r14, %rdi
callq 0x5390