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

jaskell.parsec.Parsec Maven / Gradle / Ivy

Go to download

This is a utils library for java 8 project. It include parsec combinators and sql generators library.

There is a newer version: 2.9.2
Show newest version
package jaskell.parsec;

import jaskell.sql.Equal;
import jaskell.util.Result;

import java.io.EOFException;

/**
 * Created by Mars Liu on 2016-01-02.
 * Parsec defined base functions of parsec parsers.
 */
@FunctionalInterface
public interface Parsec {
  T parse(State s)
      throws EOFException, ParsecException;

  default Result exec(State s) {
    try {
      return new Result<>(Parsec.this.parse(s));
    } catch (Exception e) {
      return new Result<>(e);
    }
  }

  default  Parsec bind(Binder binder) {
    return s -> {
      T value = Parsec.this.parse(s);
      return binder.bind(value).parse(s);
    };
  }

  default  Parsec then(Parsec parsec) {
    return s -> {
      Parsec.this.parse(s);
      return parsec.parse(s);
    };
  }

  default  Parsec over(Parsec parsec) {
    return s -> {
      T value = Parsec.this.parse(s);
      parsec.parse(s);
      return value;
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy