1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-10 18:59:39 +02:00

Add support for different regex parsers

This commit is contained in:
Paul Schaub 2022-11-29 14:21:44 +01:00
parent 3f10efac7a
commit 21f8ba8ccf
8 changed files with 270 additions and 1 deletions

28
hsregex/build.gradle Normal file
View file

@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
plugins {
id 'java-library'
}
group 'org.pgpainless'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
implementation(project(":pgpainless-core"))
// Henry Spencers Regular Expression (RegEx packets)
implementation 'com.basistech.tclre:tcl-regex:0.14.5'
}
test {
useJUnitPlatform()
}

View file

@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.algorithm;
import com.basistech.tclre.HsrePattern;
import com.basistech.tclre.PatternFlags;
import com.basistech.tclre.RePattern;
import com.basistech.tclre.RegexException;
public class HSRegexInterpreterFactory extends RegexInterpreterFactory {
public Regex instantiate(String regex) {
return new Regex() {
private final RePattern pattern;
{
try {
pattern = HsrePattern.compile(regex, PatternFlags.ADVANCED);
} catch (RegexException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public boolean matches(String string) {
return pattern.matcher(string).find();
}
};
}
}

View file

@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
/**
* Regex interpreter implementation based on Henry Spencers Regular Expression library.
*
* @see <a href="https://www.rfc-editor.org/rfc/rfc4880#section-8">RFC4880 - §8. Regular Expressions</a>
*/
package org.pgpainless.algorithm;