jaskell.parsec.NCh 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.parsec;
import java.io.EOFException;
/**
* Created by Mars Liu on 2016/9/28.
* Expect State return a char not equals chr.
*/
public class NCh implements Parsec{
final private Character chr;
final private boolean caseSensitive;
public NCh(Character chr) {
this.chr = chr;
caseSensitive = true;
}
public NCh(Character chr, Boolean caseSensitive) {
this.caseSensitive = caseSensitive;
if(caseSensitive){
this.chr = chr;
}else {
this.chr = chr.toString().toLowerCase().charAt(0);
}
}
@Override
public Character parse(State s) throws EOFException, ParsecException {
Character c = s.next();
if (caseSensitive){
if(!chr.equals(c)){
return c;
}
} else {
Character lc = c.toString().toLowerCase().charAt(0);
if(!chr.equals(lc)){
return c;
}
}
throw s.trap(String.format("expect any char is not %c (case sensitive %b) at %s but %c",
chr, caseSensitive, s.status().toString(), c));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy