package token;

import java.util.function.Supplier;

import error.LineColumnException;
import file.FilePosition;
import sexpression.*;

public class RightParenthesis extends Token {

    public RightParenthesis(String text, FilePosition position) {
        super(text, position);
    }

    @Override
    public SExpression parseSExpression(Supplier<Token> getNextToken) {
        throw new StartsWithRightParenthesisException(getPosition());
    }

    @Override
    public SExpression parseSExpressionTail(Supplier<Token> getNextToken) {
        return Nil.getInstance();
    }

    public static class StartsWithRightParenthesisException extends LineColumnException {

        private static final long serialVersionUID = 1L;

        public StartsWithRightParenthesisException(FilePosition position) {
            super(position);
        }

        public String getMessagePrefix() {
            return "expression begins with ')'";
        }
    }

}
