ladybird/Libraries
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
..
LibAudio LibAudio: Use new format functions. 2020-10-17 23:20:31 +02:00
LibC LibRegex: Add a regular expression library 2020-11-27 21:32:41 +01:00
LibChess LibChess: Forbid King moving into check by a pawn on the home rank 2020-10-30 16:51:41 +01:00
LibCompress Everywhere: Fix typos 2020-10-02 16:03:17 +02:00
LibCore LibCore: Make `guess_mime_type_based_on_filename()' recognise CSV files 2020-11-24 21:38:13 +01:00
LibCpp LibCpp: Add library for working with c++ code 2020-09-30 21:46:59 +02:00
LibCrypt Everywhere: Port to String::copy_characters_to_buffer() 2020-08-30 17:35:27 +02:00
LibCrypto LibCrypto: Implement GCM mode 2020-11-14 10:18:54 +01:00
LibDebug LibDebug: Use FlyString for file paths 2020-11-16 09:10:49 +01:00
LibDesktop Meta+LibC through LibHTTP: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
LibDiff LibDiff: Add library for working with diffs 2020-09-15 21:43:29 +02:00
LibELF Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
LibGemini LibProtocol+LibGemini+LibHTTP: Provide root certificates to LibTLS 2020-10-30 23:42:03 +01:00
LibGfx Lagom: Make BMP fuzzer look like the other image loader fuzzers 2020-11-26 09:59:46 +01:00
LibGUI LibGUI: Remove redundant set_title() call in FilePicker (#4153) 2020-11-24 18:41:44 +01:00
LibHTTP LibProtocol+LibGemini+LibHTTP: Provide root certificates to LibTLS 2020-10-30 23:42:03 +01:00
LibImageDecoderClient AK: Add trivial structure validation to SharedBuffer 2020-10-02 15:38:07 +02:00
LibIPC LibIPC: Fix 'unused private member' error when building with clang 2020-11-25 20:00:23 +01:00
LibJS LibJS: Fix possible OOB read during Lexer construction 2020-11-25 22:43:30 +01:00
LibKeyboard Everywhere: Add missing <AK/ByteBuffer.h> includes 2020-11-15 13:11:21 +01:00
LibLine Shell+LibLine: Support HISTCONTROL environment variable 2020-10-26 11:27:54 +01:00
LibM LibM: Define some floating point classification macros 2020-11-17 09:57:06 +01:00
LibMarkdown LibMarkdown: Use JS::MarkupGenerator for "js" code blocks :^) 2020-10-31 20:52:54 +01:00
LibPCIDB LibPCIDB: Mark compilation-unit-only functions as static 2020-08-12 20:40:59 +02:00
LibProtocol AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe 2020-11-10 19:11:52 +01:00
LibPthread LibPthread: Fix broken EINVAL check in pthread_attr_setdetachstate() 2020-11-26 19:33:44 +01:00
LibRegex LibRegex: Add a regular expression library 2020-11-27 21:32:41 +01:00
LibTar Userland: tar: support extracting gzipped files 2020-10-04 00:16:40 +02:00
LibTextCodec LibTextCodec: Add a function to convert encodings to standardized names 2020-11-14 10:14:03 +01:00
LibThread LibThread: Add API to join a thread 2020-11-24 21:36:28 +01:00
LibTLS LibTLS: Count the mac size towards the packet length in CBC mode 2020-11-16 13:21:18 +01:00
LibUnwind Everywhere: Fix typos 2020-10-02 16:03:17 +02:00
LibVT LibVT: Add TerminalWidget::scroll_to_bottom() API 2020-11-10 11:55:12 +01:00
LibWeb LibWeb: Update m_previous_sibling in TreeNode::insert_before. 2020-11-27 21:29:21 +01:00
LibX86 LibX86: Pack the Instruction data structure 2020-11-17 17:09:49 +01:00
CMakeLists.txt LibRegex: Add a regular expression library 2020-11-27 21:32:41 +01:00