Altered SYMBOL-FUNCTION behavior and cleaned up some code
This commit is contained in:
parent
2ef285e45c
commit
d3e3f52e59
|
@ -24,16 +24,21 @@ public class SYMBOL_FUNCTION extends LispFunction {
|
|||
SExpression symbol = argumentList.getFirst();
|
||||
LispFunction function = FunctionTable.lookupFunction(symbol.toString());
|
||||
|
||||
if (function != null) {
|
||||
if (function instanceof UserDefinedFunction)
|
||||
return ((UserDefinedFunction) function).getLambdaExpression();
|
||||
|
||||
return new Symbol(MessageFormat.format("#<SYSTEM-FUNCTION {0}>", symbol.toString()));
|
||||
}
|
||||
if (function != null)
|
||||
return createSymbolRepresentation(symbol, function);
|
||||
|
||||
throw new UndefinedSymbolFunctionException(symbol);
|
||||
}
|
||||
|
||||
private SExpression createSymbolRepresentation(SExpression symbol, LispFunction function) {
|
||||
if (function instanceof UserDefinedFunction)
|
||||
return ((UserDefinedFunction) function).getLambdaExpression();
|
||||
else if (function instanceof LispSpecialFunction)
|
||||
return new Symbol(MessageFormat.format("#<SPECIAL-FUNCTION {0}>", symbol.toString()));
|
||||
|
||||
return new Symbol(MessageFormat.format("#<FUNCTION {0}>", symbol.toString()));
|
||||
}
|
||||
|
||||
public static class UndefinedSymbolFunctionException extends LispException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class LispScanner {
|
|||
positionTracker.incrementLine();
|
||||
}
|
||||
|
||||
return tokenFactory.createEOFToken(positionTracker.getCurrentPosition());
|
||||
return tokenFactory.createEofToken(positionTracker.getCurrentPosition());
|
||||
}
|
||||
|
||||
private Token createTokenFromCharacter(char c) {
|
||||
|
@ -130,7 +130,7 @@ public class LispScanner {
|
|||
previousCharacter = currentCharacter;
|
||||
}
|
||||
|
||||
return terminateTokenWithEOF();
|
||||
return terminateTokenWithEof();
|
||||
}
|
||||
|
||||
private void addCharacterToToken() {
|
||||
|
@ -153,7 +153,7 @@ public class LispScanner {
|
|||
return (currentCharacter == DOUBLE_QUOTE) && (previousCharacter != BACKSLASH);
|
||||
}
|
||||
|
||||
private String terminateTokenWithEOF() {
|
||||
private String terminateTokenWithEof() {
|
||||
if (isStringToken())
|
||||
throw new UnterminatedStringException(position);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ public interface TokenFactory {
|
|||
|
||||
Token createToken(String text, FilePosition position);
|
||||
|
||||
Token createEOFToken(FilePosition position);
|
||||
Token createEofToken(FilePosition position);
|
||||
|
||||
public static class EmptyTokenTextException extends CriticalLineColumnException {
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public class TokenFactoryImpl implements TokenFactory {
|
|||
return (text.length() > 1) && isDigit(text.charAt(1));
|
||||
}
|
||||
|
||||
public Token createEOFToken(FilePosition position) {
|
||||
public Token createEofToken(FilePosition position) {
|
||||
return new Eof("EOF", position);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public final class Characters {
|
|||
public static boolean isLegalStringCharacter(char c) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isNumberPrefix(char c) {
|
||||
return c == DASH || c == PLUS;
|
||||
}
|
||||
|
|
|
@ -23,10 +23,17 @@ public class SYMBOL_FUNCTIONTester {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSymbolFunction_BuiltinFunction() {
|
||||
public void testSymbolFunction_BuiltInFunction() {
|
||||
String input = "(symbol-function '+)";
|
||||
|
||||
assertEquals("#<SYSTEM-FUNCTION +>", evaluateString(input).toString());
|
||||
assertEquals("#<FUNCTION +>", evaluateString(input).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSymbolFunction_BuiltInSpecialFunction() {
|
||||
String input = "(symbol-function 'if)";
|
||||
|
||||
assertEquals("#<SPECIAL-FUNCTION IF>", evaluateString(input).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -41,7 +41,7 @@ public class LispScannerLineColumnTester {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenNothing_RecordsCorrectEOFLocation() {
|
||||
public void givenNothing_RecordsCorrectEofLocation() {
|
||||
String input = "";
|
||||
LineColumn[] expectedLinesAndColumns = { LineColumn.create(1, 0) };
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public class LispScannerTextTester {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenEOF_ReordsCorrectText() {
|
||||
public void givenEof_ReordsCorrectText() {
|
||||
String input = "";
|
||||
String expected = "EOF";
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ public class TokenFactoryTester {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEOFTokenCreation() {
|
||||
assertTrue(tokenFactory.createEOFToken(testPosition) instanceof Eof);
|
||||
public void testEofTokenCreation() {
|
||||
assertTrue(tokenFactory.createEofToken(testPosition) instanceof Eof);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue