jaskell.expression.parser.Parser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaskell-java8 Show documentation
Show all versions of jaskell-java8 Show documentation
This is a utils library for java 8 project.
It include parsec combinators and sql generators library.
package jaskell.expression.parser;
import static jaskell.parsec.common.Combinator.ahead;
import static jaskell.parsec.common.Combinator.attempt;
import static jaskell.parsec.common.Combinator.choice;
import static jaskell.parsec.common.Txt.ch;
import static jaskell.parsec.common.Txt.skipWhiteSpaces;
import jaskell.expression.Expression;
import jaskell.parsec.ParsecException;
import jaskell.parsec.common.Eof;
import jaskell.parsec.common.Parsec;
import jaskell.parsec.common.SkipWhitespaces;
import jaskell.parsec.common.State;
import java.io.EOFException;
import static jaskell.parsec.common.Atom.eof;
/**
* TODO
*
* @author mars
* @version 1.0.0
* @since 2020/06/04 11:16
*/
public class Parser implements Parsec {
private final Parsec rq = attempt(ch(')'));
private final SkipWhitespaces skips = skipWhiteSpaces();
private final Eof e = eof();
private final Parsec end = ahead(choice(rq, e));
@Override
public Expression parse(State s) throws EOFException, ParsecException {
Parsec np = choice(attempt(new N()), attempt(new Param()), attempt(new Q()));
Expression left = np.parse(s);
skips.parse(s);
if (end.exec(s).isOk()) {
return left;
} else {
Parsec next = choice(attempt(new A(left)),
attempt(new S(left)),
attempt(new P(left)),
attempt(new D(left)));
return next.parse(s);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy