org.parsky.sequence.SequenceMatchers Maven / Gradle / Ivy
package org.parsky.sequence;
import com.google.common.collect.ImmutableList;
import org.parsky.character.CharacterMatcher;
import org.parsky.character.WhiteSpaceCharacterMatcher;
import org.parsky.sequence.transform.Transformation;
import java.util.List;
import static org.parsky.character.CharacterMatchers.whiteSpace;
public class SequenceMatchers {
public static SequenceMatcher match (CharacterMatcher characterMatcher) {
return new CharacterSequenceMatcher<>(characterMatcher);
}
public static SequenceMatcher match (String label, CharacterMatcher characterMatcher) {
return new LabelledSequenceMatcher<>(label, SequenceMatchers.match(characterMatcher));
}
public static SequenceMatcher string (String text) {
return new StringSequenceMatcher<>(text);
}
public static SequenceMatcher string (String label, String text) {
return new LabelledSequenceMatcher<>(label, SequenceMatchers.string(text));
}
public static SequenceMatcher> sequence (SequenceMatcher first, SequenceMatcher... others) {
return new ConsecutiveSequenceMatcher<>(ImmutableList.>builder().add(first).add(others).build());
}
public static SequenceMatcher> sequence (String label, SequenceMatcher first, SequenceMatcher... others) {
return new LabelledSequenceMatcher<>(label, sequence(first, others));
}
public static SequenceMatcher> sequence (List> list) {
return new ConsecutiveSequenceMatcher<>(list);
}
public static SequenceMatcher> sequence (String label, List> list) {
return new LabelledSequenceMatcher<>(label, sequence(list));
}
public static SequenceMatcher mandatory(SequenceMatcher sequenceMatcher) {
return new MandatorySequenceMatcher<>(sequenceMatcher);
}
public static SequenceMatcher mandatory(String label, SequenceMatcher sequenceMatcher) {
return new LabelledSequenceMatcher<>(label, mandatory(sequenceMatcher));
}
public static SequenceMatcher> zeroOrMore(SequenceMatcher sequenceMatcher) {
return new ZeroOrMoreSequenceMatcher<>(sequenceMatcher);
}
public static SequenceMatcher> zeroOrMore(String label, SequenceMatcher sequenceMatcher) {
return new LabelledSequenceMatcher<>(label, zeroOrMore(sequenceMatcher));
}
public static SequenceMatcher test (SequenceMatcher sequenceMatcher) {
return new TestSequenceMatcher(sequenceMatcher);
}
public static SequenceMatcher test (String label, SequenceMatcher sequenceMatcher) {
return new LabelledSequenceMatcher<>(label, new TestSequenceMatcher<>(sequenceMatcher));
}
public static SequenceMatcher until (SequenceMatcher sequenceMatcher) {
return new UntilSequenceMatcher<>(sequenceMatcher);
}
public static SequenceMatcher until (String label, SequenceMatcher sequenceMatcher) {
return new LabelledSequenceMatcher<>(label, until(sequenceMatcher));
}
public static SequenceMatcher firstOf (SequenceMatcher first, SequenceMatcher... sequenceMatchers) {
return new FirstOfSequenceMatcher<>(ImmutableList.>builder().add(first).add(sequenceMatchers).build());
}
public static SequenceMatcher firstOf (String label, SequenceMatcher first, SequenceMatcher... sequenceMatchers) {
return new LabelledSequenceMatcher<>(label, firstOf(first, sequenceMatchers));
}
public static SequenceMatcher firstOf (List> sequenceMatchers) {
return new FirstOfSequenceMatcher<>(sequenceMatchers);
}
public static SequenceMatcher firstOf (String label, List> sequenceMatchers) {
return new LabelledSequenceMatcher<>(label, firstOf(sequenceMatchers));
}
public static SequenceMatcher not (SequenceMatcher sequenceMatcher) {
return new NotSequenceMatcher<>(sequenceMatcher);
}
public static SequenceMatcher not (String label, SequenceMatcher sequenceMatcher) {
return new LabelledSequenceMatcher<>(label, not(sequenceMatcher));
}
public static SequenceMatcher transform (SequenceMatcher sequenceMatcher, Transformation transform) {
return new TransformSequenceMatcher<>(sequenceMatcher, transform);
}
public static SequenceMatcher transform (String label, SequenceMatcher sequenceMatcher, Transformation transform) {
return new LabelledSequenceMatcher<>(label, transform(sequenceMatcher, transform));
}
public static SequenceMatcher matchedText(SequenceMatcher sequenceMatcher) {
return new MatchedTextSequenceMatcher<>(sequenceMatcher);
}
public static SequenceMatcher whitespaces () {
return SequenceMatchers.matchedText(
SequenceMatchers.zeroOrMore(
SequenceMatchers.match(
whiteSpace()
)
)
);
}
public static SequenceMatcher skipWhitespaces (SequenceMatcher sequenceMatcher) {
return new SkipWhiteSpacesSequenceMatcher<>(WhiteSpaceCharacterMatcher.whitespace(), sequenceMatcher);
}
public static SequenceMatcher optional (SequenceMatcher matcher) {
return new OptionalSequenceMatcher<>(matcher);
}
public static SequenceMatcher optional (String label, SequenceMatcher matcher) {
return new LabelledSequenceMatcher<>(label, new OptionalSequenceMatcher<>(matcher));
}
public static SequenceMatcher> oneOrMore(SequenceMatcher delegate) {
return new OneOrMoreSequenceMatcher<>(delegate);
}
public static SequenceMatcher> oneOrMore(String label, SequenceMatcher delegate) {
return new LabelledSequenceMatcher<>(label, oneOrMore(delegate));
}
public static SequenceMatcher> flatten(SequenceMatcher> sequenceMatcher) {
return new FlattenSequenceMatcher<>(sequenceMatcher);
}
public static ReferenceSequenceMatcher reference () {
return new ReferenceSequenceMatcher<>();
}
public static ConstantSequenceMatcher constant (T value) {
return new ConstantSequenceMatcher<>(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy