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

jaskell.parsec.NCh 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 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