All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.firemage.autograder.treeg.ast.Lookaround Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package de.firemage.autograder.treeg.ast;

import de.firemage.autograder.treeg.TreePrinter;

public record Lookaround(RegExNode child, Type type) implements RegExNode {
    @Override
    public String toRegEx() {
        return "(" + switch (this.type) {
            case LOOKBEHIND -> "?<=";
            case NEGATIVE_LOOKBEHIND -> "? "?=";
            case NEGATIVE_LOOKAHEAD -> "?!";
        } + this.child.toRegEx() + ")";
    }

    @Override
    public void toTree(TreePrinter printer) {
        printer.addLine(this.type.toString());
        printer.indent();
        this.child.toTree(printer);
        printer.unindent();
    }

    public enum Type {
        LOOKBEHIND,
        NEGATIVE_LOOKBEHIND,
        LOOKAHEAD,
        NEGATIVE_LOOKAHEAD,
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy