// File: /workspace/github_cpp_makefile_star2_O3/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
movabsq $0x100000001, %r9       # imm = 0x100000001
movq %rax, %r14
leaq 0x739b(%rip), %rdi      # 0x12d18
vxorps %xmm0, %xmm0, %xmm0
movq %rax, %rbx
movq %r9, 0x8(%r14)
leaq 0x28(%r14), %r9
movq %rdi, (%r14)
vmovups %ymm0, 0x10(%r14)
vmovups %ymm0, 0x20(%r14)
leaq 0x18(%r14), %rdi
movq %r9, 0x18(%r14)
movl $0x4, 0x10(%r14)
leaq 0x13e3(%rip), %rcx      # 0xcd95
movl $0x9, %r8d
xorl %esi, %esi
xorl %edx, %edx
vzeroupper
callq 0x5320
movq 0x75f5(%rip), %rax      # 0x12fc0
addq $0x10, %r14
leaq 0x72f2(%rip), %r15      # 0x12cc8
cmpb $0x0, (%rax)
je 0xb9ef
incl 0x8(%rbx)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
jmp 0xba0b
lock
incl 0x8(%rbx)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
cmpb $0x0, (%rax)
je 0xbc3e
incl 0x8(%rbx)
movq %rbx, %rdi
callq 0x6972
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1378(%rip), %rsi      # 0xcd9f
leaq 0x13b4(%rip), %rdx      # 0xcde2
leaq 0x58(%rsp), %rdi
callq 0x6386
leaq 0x98(%rsp), %rcx
leaq -0x187(%rip), %rdx      # 0xb8c0
leaq 0x78(%rsp), %r8
xorl %eax, %eax
leaq 0x45d(%rip), %rsi       # 0xbeb2
movq %rax, 0x8(%rcx)
movq %rdx, (%rcx)
leaq 0x44d(%rip), %rdx       # 0xbeb0
movq %rax, 0x8(%r8)
leaq -0x167(%rip), %rax      # 0xb907
movq %rdx, 0x18(%rcx)
movq %rax, (%r8)
movq %rdx, 0x18(%r8)
movq %rsi, 0x10(%rcx)
movq %rsi, 0x10(%r8)
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0xa36a
movq 0x88(%rsp), %rax
testq %rax, %rax
je 0xbab1
leaq 0x78(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
movq 0xa8(%rsp), %rax
testq %rax, %rax
je 0xbad0
leaq 0x98(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
movq 0x74f1(%rip), %rdi      # 0x12fc8
leaq 0x1305(%rip), %rsi      # 0xcde3
movl $0x6, %edx
callq 0x5270
movq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdi
callq 0xb062
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rsi
movq 0x74c0(%rip), %rdi      # 0x12fc8
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 0x38(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0xbb52
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x48(%rsp), %r14
leaq 0x28(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x642(%rip), %rsi       # 0xc1a8
leaq 0x647(%rip), %rdx       # 0xc1b4
callq 0x6386
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0xafc0
movq 0x28(%rsp), %rdi
movl %eax, %ebp
cmpq %r13, %rdi
je 0xbb9d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5230
testb %bpl, %bpl
je 0xbbe8
movq 0x741f(%rip), %r14      # 0x12fc8
leaq 0x123a(%rip), %rsi      # 0xcdea
movl $0x6, %edx
movq %r14, %rdi
callq 0x5270
movq (%r14), %rax
addq -0x18(%rax), %r14
movl $0xa, %esi
movq %r14, %rdi
callq 0x5200
movq 0x73f0(%rip), %rdi      # 0x12fc8
movsbl %al, %esi
callq 0x5030
movq %rax, %rdi
callq 0x5160
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xbbf7
callq 0x6972
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0xbc0e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5230
movq %r15, 0x10(%rsp)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xbc22
callq 0x6972
movq %rbx, %rdi
callq 0x6972
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
lock
incl 0x8(%rbx)
jmp 0xba0e
jmp 0xbca2
jmp 0xbca2
movq 0x28(%rsp), %rdi
movq %rax, %r14
cmpq %r13, %rdi
jne 0xbcca
jmp 0xbcd7
jmp 0xbcb4
jmp 0xbcb4
jmp 0xbcb4
movq %rax, %r14
movq 0x88(%rsp), %rax
testq %rax, %rax
je 0xbc7f
leaq 0x78(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
movq 0xa8(%rsp), %rax
testq %rax, %rax
je 0xbce6
leaq 0x98(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
jmp 0xbce6
jmp 0xbca2
movq %rax, %rdi
callq 0x6209
movq %rax, %r14
jmp 0xbcfd
movq %rax, %r14
jmp 0xbd11
movq %rax, %r14
jmp 0xbcd7
leaq 0x38(%rsp), %rcx
movq %rax, %r14
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0xbcd7
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x5230
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xbce6
callq 0x6972
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0xbcfd
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x5230
movq %r15, 0x10(%rsp)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xbd11
callq 0x6972
movq %rbx, %rdi
callq 0x6972
movq %r14, %rdi
callq 0x5390
nop