package token;

import static sexpression.Nil.NIL;

import java.util.function.Supplier;

import error.LineColumnException;
import file.FilePosition;
import sexpression.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;
    }

    public static class StartsWithRightParenthesisException extends LineColumnException {

        private static final long serialVersionUID = 1L;

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

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

}
