Package mireka.address.parser

Source Code of mireka.address.parser.ReversePathParser

package mireka.address.parser;

import java.text.ParseException;

import mireka.address.parser.ast.NullReversePathAST;
import mireka.address.parser.ast.PathAST;
import mireka.address.parser.ast.RealReversePathAST;
import mireka.address.parser.ast.ReversePathAST;
import mireka.address.parser.base.CharParser;

public class ReversePathParser extends CharParser {

    public ReversePathParser(String source) {
        super(source);
    }

    public ReversePathAST parse() throws ParseException {
        ReversePathAST reversePathAST = parseReversePath();
        if (currentToken.ch != -1)
            throw currentToken.otherSyntaxException("Superfluous characters "
                    + "after reverse path: {0}");
        return reversePathAST;
    }

    private ReversePathAST parseReversePath() throws ParseException {
        pushPosition();
        if (inputEquals("<>")) {
            accept('<');
            accept('>');
            return new NullReversePathAST(popPosition());
        } else {
            PathAST pathAST = parsePath();
            return new RealReversePathAST(popPosition(), pathAST);
        }
    }

    private boolean inputEquals(String s) {
        return peekString(s.length()).equals(s);
    }

    private PathAST parsePath() throws ParseException {
        scanner.pushBack(currentToken);
        PathAST pathAST = new PathParser(scanner).parseLeft();
        currentToken = scanner.scan();
        return pathAST;
    }

}
TOP

Related Classes of mireka.address.parser.ReversePathParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.