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

org.jparsercombinator.ParserCombinatorOptional Maven / Gradle / Ivy

package org.jparsercombinator;

import java.util.Optional;

class ParserCombinatorOptional implements ParserCombinator> {

  private ParserCombinator combinator;

  ParserCombinatorOptional(ParserCombinator combinator) {
    this.combinator = combinator;
  }

  @Override
  public Result> apply(String input) {
    Result result = combinator.apply(input);

    if (result.isAccepted()) {
      return new Accept<>(Optional.of(result.result()), result.remainingInput());
    }

    return new Accept<>(Optional.empty(), input);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy