ladybird/Meta
Emanuel Sprung 55450055d8 LibRegex: Add a regular expression library
This commit is a mix of several commits, squashed into one because the
commits before 'Move regex to own Library and fix all the broken stuff'
were not fixable in any elegant way.
The commits are listed below for "historical" purposes:

- AK: Add options/flags and Errors for regular expressions

Flags can be provided for any possible flavour by adding a new scoped enum.
Handling of flags is done by templated Options class and the overloaded
'|' and '&' operators.

- AK: Add Lexer for regular expressions

The lexer parses the input and extracts tokens needed to parse a regular
expression.

- AK: Add regex Parser and PosixExtendedParser

This patchset adds a abstract parser class that can be derived to implement
different parsers. A parser produces bytecode to be executed within the
regex matcher.

- AK: Add regex matcher

This patchset adds an regex matcher based on the principles of the T-REX VM.
The bytecode pruduced by the respective Parser is put into the matcher and
the VM will recursively execute the bytecode according to the available OpCodes.
Possible improvement: the recursion could be replaced by multi threading capabilities.

To match a Regular expression, e.g. for the Posix standard regular expression matcher
use the following API:

```
Pattern<PosixExtendedParser> pattern("^.*$");
auto result = pattern.match("Well, hello friends!\nHello World!"); // Match whole needle

EXPECT(result.count == 1);
EXPECT(result.matches.at(0).view.starts_with("Well"));
EXPECT(result.matches.at(0).view.end() == "!");

result = pattern.match("Well, hello friends!\nHello World!", PosixFlags::Multiline); // Match line by line

EXPECT(result.count == 2);
EXPECT(result.matches.at(0).view == "Well, hello friends!");
EXPECT(result.matches.at(1).view == "Hello World!");

EXPECT(pattern.has_match("Well,....")); // Just check if match without a result, which saves some resources.
```

- AK: Rework regex to work with opcodes objects

This patchsets reworks the matcher to work on a more structured base.
For that an abstract OpCode class and derived classes for the specific
OpCodes have been added. The respective opcode logic is contained in
each respective execute() method.

- AK: Add benchmark for regex

- AK: Some optimization in regex for runtime and memory

- LibRegex: Move regex to own Library and fix all the broken stuff

Now regex works again and grep utility is also in place for testing.
This commit also fixes the use of regex.h in C by making `regex_t`
an opaque (-ish) type, which makes its behaviour consistent between
C and C++ compilers.
Previously, <regex.h> would've blown C compilers up, and even if it
didn't, would've caused a leak in C code, and not in C++ code (due to
the existence of `OwnPtr` inside the struct).

To make this whole ordeal easier to deal with (for now), this pulls the
definitions of `reg*()` into LibRegex.

pros:
- The circular dependency between LibC and LibRegex is broken
- Eaiser to test (without accidentally pulling in the host's libc!)

cons:
- Using any of the regex.h functions will require the user to link -lregex
- The symbols will be missing from libc, which will be a big surprise
  down the line (especially with shared libs).

Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
2020-11-27 21:32:41 +01:00
..
CLion Toolchain: Upgrade to GCC 10.2.0 2020-10-12 19:53:25 +02:00
Lagom LibRegex: Add a regular expression library 2020-11-27 21:32:41 +01:00
bochsrc Meta: move Kernel/.bochsrc => Meta/bochsrc 2020-07-01 12:53:39 +02:00
build-image-grub.sh Meta: Fix style of image building scripts 2020-07-28 19:09:44 +02:00
build-image-qemu.sh Build: Modify various parts to allow the build to succeed on FreeBSD 2020-10-20 14:40:47 +02:00
build-root-filesystem.sh Build: Modify various parts to allow the build to succeed on FreeBSD 2020-10-20 14:40:47 +02:00
check-style.sh Meta: Fix wonky copyright headers in Tests 2020-09-05 14:19:38 +02:00
check-symbols.sh Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
debug-kernel.sh Build: Switch to CMake :^) 2020-05-14 20:15:18 +02:00
grub-ebr.cfg Kernel: Stop bootloader from setting video mode with Multiboot 2020-05-28 00:50:55 +02:00
grub-gpt.cfg Kernel: Stop bootloader from setting video mode with Multiboot 2020-05-28 00:50:55 +02:00
grub-mbr.cfg Kernel: Stop bootloader from setting video mode with Multiboot 2020-05-28 00:50:55 +02:00
lint-ci.sh Meta: Add script that runs all lints 2020-11-08 09:58:55 +01:00
lint-clang-format.sh Meta: Provide script to automatically flag bad formatting 2020-09-25 21:18:17 +02:00
lint-executable-resources.sh Meta: Ensure that icons and other resources remain non-executable 2020-07-29 01:34:22 +02:00
lint-ipc-ids.sh Meta: Lint for duplicate endpoint IDs 2020-08-15 20:48:52 +02:00
lint-missing-resources.sh Meta: Find potentially missing resources 2020-07-29 01:34:22 +02:00
lint-shell-scripts.sh Meta: lint-shell-scripts: Exit if shellcheck is not installed 2020-11-01 10:29:33 +01:00
notify_irc.py Meta: Reduce IRC spam 2020-11-25 20:50:22 +01:00
refresh-serenity-qtcreator.sh Meta: Include .json files in the Qt Creator refresh script 2020-09-14 19:55:18 +02:00
run.sh Meta: Add env variable SERENITY_RUN to be able to choose qemu, bochs, etc 2020-09-19 00:33:02 +02:00
screenshot-000ccc0.png Meta: Update ReadMe with a new screenshot. :^) 2019-02-12 15:47:37 +01:00
screenshot-8ea4375.png Meta: Time for a new screenshot! :^) 2020-06-02 19:29:31 +02:00
screenshot-1133aca.png Meta: Time for a new screenshot (Quake edition) :^) 2019-11-06 21:51:33 +01:00
screenshot-9145a72.png Meta: Time for a new screnshot! :^) 2019-09-18 12:15:02 +02:00
screenshot-23263aa.png Meta: Update ReadMe with a new screenshot :^) 2019-02-27 13:17:43 +01:00
screenshot-191112e.png Meta: Time for a new screenshot to keep things fresh. :^) 2019-06-07 18:14:13 +02:00
screenshot-b5521e1.png Meta: Time for a new screenshot! :^) 2019-03-08 01:10:33 +01:00
screenshot-cdb82f6.png Meta: Tweak ReadMe and add a new screenshot. 2019-03-20 15:52:37 +01:00
screenshot-d727005.png Meta: Tweak ReadMe and add a new screenshot. 2019-04-30 15:27:35 +02:00
screenshot-ef9fbef.png Meta: Time for a new screenshot :^) 2019-04-06 01:31:12 +02:00
screenshot-f8fc892.png Add a little ReadMe. 2019-02-08 11:06:34 +01:00
text-to-cpp-string.sh Meta: Make the text-to-cpp-string thingy pass shellcheck 2020-09-14 16:33:53 +02:00
write-only-on-difference.sh Meta: Provide a way to only update a file if the output changes 2020-08-04 11:27:14 +02:00