summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibRegex
AgeCommit message (Collapse)Author
2021-08-13AK+Everywhere: Delete Variant's default constructorAli Mohammad Pur
This was exposed to the user by mistake, and even accumulated a bunch of users that didn't blow up out of sheer luck.
2021-08-11LibRegex: Disallow invalid interval qualifiers in Unicode modeTimothy Flynn
Fixes all remaining 'built-ins/RegExp/property-escapes' test262 tests.
2021-08-04LibRegex: Support property escapes of Unicode script extensionsTimothy Flynn
2021-08-04LibRegex: Support property escapes of the Unicode script propertyTimothy Flynn
Note that unlike binary properties and general categories, scripts must be specified in the non-binary (Script=Value) form.
2021-08-04LibRegex: Track string position in both code units and code pointsTimothy Flynn
In non-Unicode mode, the existing MatchState::string_position is tracked in code units; in Unicode mode, it is tracked in code points. In order for some RegexStringView operations to be performant, it is useful for the MatchState to have a field to always track the position in code units. This will allow RegexStringView methods (e.g. operator[]) to perform lookups based on code unit offsets, rather than needing to iterate over the entire string to find a code point offset.
2021-08-04AK+LibRegex: Add Utf16View::code_point_at and use it in RegexStringViewTimothy Flynn
The current method of iterating through the string to access a code point hurts performance quite badly for very large strings. The test262 test "RegExp/property-escapes/generated/Any.js" previously took 3 hours to complete; this one change brings it down to under 10 seconds.
2021-08-02LibRegex: Generate negated property escapes as a single instructionTimothy Flynn
These were previously generated as two instructions, Compare [Inverse] and Compare [Property].
2021-08-02LibRegex: Support property escapes of the form \p{Type=Value}Timothy Flynn
Before now, only binary properties could be parsed. Non-binary props are of the form "Type=Value", where "Type" may be General_Category, Script, or Script_Extension (or their aliases). Of these, LibUnicode currently supports General_Category, so LibRegex can parse only that type.
2021-08-02LibRegex: Support property escapes of Unicode General CategoriesTimothy Flynn
This changes LibRegex to parse the property escape as a Variant of Unicode Property & General Category values. A byte code instruction is added to perform matching based on General Category values.
2021-08-02LibRegex: Make Matcher<>::match(Vector<>) take a reference to the vectorAli Mohammad Pur
It was previously copying the entire vector every time, which is not a nice thing to do. :^)
2021-08-02LibRegex: Use a bump-allocated linked list for fork save statesAli Mohammad Pur
This makes it avoid the excessively high malloc() traffic.
2021-08-02LibRegex: Make Fork{Jump,Stay} non-recursiveAli Mohammad Pur
This makes very fork-heavy expressions (like `(aa)*`) not run out of stack space when matching very long strings.
2021-08-01Libraries: Remove unused header includesBrian Gianforcaro
2021-07-30LibRegex+LibUnicode: Begin implementing Unicode property escapesTimothy Flynn
This supports some binary property matching. It does not support any properties not yet parsed by LibUnicode, nor does it support value matching (such as Script_Extensions=Latin).
2021-07-30LibRegex: Allow separately parsing patterns and creating Regex objectsTimothy Flynn
Adds a static method to parse a regex pattern and return the result, and a constructor to accept a parse result. This is to allow LibJS to parse the pattern string of a RegExpLiteral once and hand off regex objects any number of times thereafter.
2021-07-30LibRegex: Take ownership of pattern string and fix move operationsTimothy Flynn
The Regex object created a copy of the pattern string anyways, so tweak the constructor to allow callers to move() pattern strings into the regex. The Regex move constructor and assignment operator currently result in memory corruption. The Regex object stores a Matcher object, which holds a reference to the Regex object. So when the Regex object is moved, that reference is no longer valid. To fix this, the reference stored in the Matcher must be updated when the Regex is moved.
2021-07-30LibRegex: Allow RegexOptions to be declared at compile timeTimothy Flynn
2021-07-24LibRegex: Make unclosed-at-eof brace quantifiers an errorAli Mohammad Pur
Otherwise we'd just loop trying to parse it over and over again, for instance in `/a{/` or `/a{1,/`. Unless we're parsing in Annex B mode, which allows `{` as a normal ExtendedSourceCharacter.
2021-07-24LibRegex: Preserve the type of the match when clearing capture groupsAli Mohammad Pur
Even though the contents are supposed to be reset, the type should stay unchanged, as that's an assumption the engine is making.
2021-07-23LibRegex: Support ECMA-262 Unicode escapes of the form "\u{code_point}"Timothy Flynn
When the Unicode flag is set, regular expressions may escape code points by surrounding the hexadecimal code point with curly braces, e.g. \u{41} is the character "A". When the Unicode flag is not set, this should be considered a repetition symbol - \u{41} is the character "u" repeated 41 times. This is left as a TODO for now.
2021-07-23AK+LibRegex: Partially implement case insensitive UTF-16 comparisonTimothy Flynn
This will work for ASCII code points. Unicode case folding will be needed for non-ASCII.
2021-07-23LibRegex: Support UTF-16 RegexStringView and improve Unicode matchingTimothy Flynn
When the Unicode option is not set, regular expressions should match based on code units; when it is set, they should match based on code points. To do so, the regex parser must combine surrogate pairs when the Unicode option is set. Further, RegexStringView needs to know if the flag is set in order to return code point vs. code unit based string lengths and substrings.
2021-07-23LibRegex: Switch to east-const styleAli Mohammad Pur
2021-07-23LibRegex: Clear previous capture group contents in ECMA262 modeAli Mohammad Pur
ECMA262 requires that the capture groups only contain the values from the last iteration, e.g. `((c)(a)?(b))` should _not_ contain 'a' in the second capture group when matching "cabcb".
2021-07-22Everywhere: Prefer using {:#x} over 0x{:x}Gunnar Beutner
We have a dedicated format specifier which adds the "0x" prefix, so let's use that instead of adding it manually.
2021-07-18LibRegex+Everywhere: Make LibRegex more unicode-awareAli Mohammad Pur
This commit makes LibRegex (mostly) capable of operating on any of the three main string views: - StringView for raw strings - Utf8View for utf-8 encoded strings - Utf32View for raw unicode strings As a result, regexps with unicode strings should be able to properly handle utf-8 and not stop in the middle of a code point. A future commit will update LibJS to use the correct type of string depending on the flags.
2021-07-18LibRegex: Use <...> includes in RegexMatch.hAli Mohammad Pur
2021-07-18LibRegex: Also print a newline after each debug lineAli Mohammad Pur
Otherwise the new debug line would be printed right after the previous one without a newline.
2021-07-18LibRegex: Partially implement string compare for Utf32ViewAli Mohammad Pur
2021-07-18LibRegex: Implement line splitting for Utf32ViewAli Mohammad Pur
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2021-07-13LibRegex: Consider EOF in the middle of a range an errorAli Mohammad Pur
2021-07-13LibRegex: Don't attempt to insert invalid bytecode in {B,E}REAli Mohammad Pur
2021-07-13LibRegex: Implement lookaround in EREAli Mohammad Pur
2021-07-13LibRegex: Allow empty character classes in {B,E}REAli Mohammad Pur
2021-07-13LibRegex: Disallow excessively large repetition counts in {B,E}REAli Mohammad Pur
2021-07-13LibRegex+LibC: Make re_nsub available to the userAli Mohammad Pur
To comply with Dr.POSIX, this field has to be user-accessible.
2021-07-10LibRegex: Use the parser state capture group count in BREAli Mohammad Pur
Otherwise the users won't know how many capture groups are in the parsed regular expression.
2021-07-10LibRegex: Correctly parse BRE bracket expressionsAli Mohammad Pur
Commonly, bracket expressions are in fact, enclosed in brackets.
2021-07-10LibRegex: Add support for non-extended regular expressions in regcomp()Ali Mohammad Pur
Fixes part of #8506.
2021-07-10LibRegex: Add support for the Basic POSIX regular expressionsAli Mohammad Pur
This implements the internal regex stuff for #8506.
2021-07-10LibRegex: Make the bytecode transformation functions staticAli Mohammad Pur
They were pretty confusing when compared with other non-transforming functions.
2021-07-09LibRegex: Break from execution loop when the sticky flag is setTimothy Flynn
If the sticky flag is set, the regex execution loop should break immediately even if the execution was a failure. The specification for several RegExp.prototype methods (e.g. exec and @@split) rely on this behavior.
2021-07-06LibRegex: Allow dollar signs in ECMA262 named capture groupsTimothy Flynn
Fixes 1 test262 test.
2021-06-30LibRegex: Make regex::Regex move-constructible and move-assignableAndrew Kaster
For some reason the default move constructor and default move-assign operator were deleted, so we explicitly default them instead.
2021-06-24Userland: Replace VERIFY(is<T>) with verify_cast<T>Andreas Kling
Instead of doing a VERIFY(is<T>(x)) and *then* casting it to T, we can just do the cast right away with verify_cast<T>. :^)
2021-06-16LibRegex: Display correct position for Compare in REGEX_DEBUGsin-ack
When REGEX_DEBUG is enabled, LibRegex dumps a table of information regarding the state of the regex bytecode execution. The Compare opcode manipulates state.string_position directly, so the string_position value cannot be used to display where the comparison started; therefore, this patch introduces a new variable to keep track of where we were before the comparison happened.
2021-06-16LibRegex: Fix incorrect case-sensitive comparisonssin-ack
A tiny typo was introduced in bc8d16ad which caused all case insensitive comparisons to fail.
2021-06-14LibRegex: Remove unused codeGunnar Beutner
2021-06-14LibRegex: Use a plain pointer for OpCode::m_stateGunnar Beutner
2021-06-14LibRegex: Avoid initialization checks in get_opcode_by_id()Gunnar Beutner