49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
package token;
|
|
|
|
import error.LineColumnException;
|
|
import file.FilePosition;
|
|
import recursion.TailCall;
|
|
import sexpression.Cons;
|
|
import sexpression.SExpression;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
import static recursion.TailCalls.done;
|
|
import static sexpression.Nil.NIL;
|
|
|
|
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
|
|
protected TailCall<Cons> parseListTail(Supplier<Token> getNextToken) {
|
|
return done(NIL);
|
|
}
|
|
|
|
@Override
|
|
protected TailCall<Cons> parseListTailRecursive(Cons start, Cons end, Supplier<Token> getNextToken) {
|
|
return done(start);
|
|
}
|
|
|
|
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 ')'";
|
|
}
|
|
}
|
|
}
|