Performed some minor code cleanup
This commit is contained in:
parent
6f4a319dab
commit
064f905045
|
@ -14,15 +14,15 @@ public class Eof extends Token {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SExpression parseSExpression(Supplier<Token> getNextToken) {
|
public SExpression parseSExpression(Supplier<Token> getNextToken) {
|
||||||
throw new EofEncounteredException(this);
|
throw new EofEncounteredException(getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EofEncounteredException extends LineColumnException {
|
public static class EofEncounteredException extends LineColumnException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public EofEncounteredException(Token token) {
|
public EofEncounteredException(FilePosition position) {
|
||||||
super(token.getPosition());
|
super(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessagePrefix() {
|
public String getMessagePrefix() {
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class RightParenthesis extends Token {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SExpression parseSExpression(Supplier<Token> getNextToken) {
|
public SExpression parseSExpression(Supplier<Token> getNextToken) {
|
||||||
throw new StartsWithRightParenthesisException(this);
|
throw new StartsWithRightParenthesisException(getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,12 +27,12 @@ public class RightParenthesis extends Token {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public StartsWithRightParenthesisException(Token token) {
|
public StartsWithRightParenthesisException(FilePosition position) {
|
||||||
super(token.getPosition());
|
super(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessagePrefix() {
|
public String getMessagePrefix() {
|
||||||
return "Expression begins with ')'";
|
return "expression begins with ')'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,6 @@ public abstract class Token {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
|
||||||
return position.getFileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLine() {
|
|
||||||
return position.getLineNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColumn() {
|
|
||||||
return position.getColumnNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
// sExpr ::= NUMBER | IDENTIFIER | STRING | QUOTE_MARK sExpr | LEFT_PAREN sExprTail
|
// sExpr ::= NUMBER | IDENTIFIER | STRING | QUOTE_MARK sExpr | LEFT_PAREN sExprTail
|
||||||
public abstract SExpression parseSExpression(Supplier<Token> getNextToken);
|
public abstract SExpression parseSExpression(Supplier<Token> getNextToken);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ErrorManagerTester {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.indicatorSet = new HashSet<>();
|
this.indicatorSet = new HashSet<>();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import file.FilePosition;
|
||||||
import token.Token;
|
import token.Token;
|
||||||
|
|
||||||
public class LispScannerLineColumnTester {
|
public class LispScannerLineColumnTester {
|
||||||
|
@ -24,8 +25,8 @@ public class LispScannerLineColumnTester {
|
||||||
return lineColumn;
|
return lineColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEqual(Token token) {
|
public boolean isEqual(FilePosition position) {
|
||||||
return (this.line == token.getLine()) && (this.column == token.getColumn());
|
return (this.line == position.getLineNumber()) && (this.column == position.getColumnNumber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public class LispScannerLineColumnTester {
|
||||||
|
|
||||||
for (LineColumn lineColumn : expectedLineColumnList) {
|
for (LineColumn lineColumn : expectedLineColumnList) {
|
||||||
Token nextToken = lispScanner.getNextToken();
|
Token nextToken = lispScanner.getNextToken();
|
||||||
assertTrue(lineColumn.isEqual(nextToken));
|
assertTrue(lineColumn.isEqual(nextToken.getPosition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import file.FilePosition;
|
||||||
|
|
||||||
public class LispScannerTextTester {
|
public class LispScannerTextTester {
|
||||||
|
|
||||||
private void assertTokenTextMatches(String input, String[] expectedTextList) {
|
private void assertTokenTextMatches(String input, String[] expectedTextList) {
|
||||||
|
@ -31,8 +33,9 @@ public class LispScannerTextTester {
|
||||||
private void assertInputFileNameMatches(String input, String expectedInputFileName) {
|
private void assertInputFileNameMatches(String input, String expectedInputFileName) {
|
||||||
InputStream stringInputStream = createInputStreamFromString(input);
|
InputStream stringInputStream = createInputStreamFromString(input);
|
||||||
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
|
LispScanner lispScanner = new LispScanner(stringInputStream, expectedInputFileName);
|
||||||
|
FilePosition tokenPosition = lispScanner.getNextToken().getPosition();
|
||||||
|
|
||||||
assertEquals(expectedInputFileName, lispScanner.getNextToken().getFileName());
|
assertEquals(expectedInputFileName, tokenPosition.getFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue