-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from merkrafter/refactor/test-suite
Refactor/test suite
- Loading branch information
Showing
11 changed files
with
1,046 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.merkrafter.lexing; | ||
|
||
/**** | ||
* This class serves as a token and stores the (integer) number found. | ||
* | ||
* @version v0.2.0 | ||
* @author merkrafter | ||
***************************************************************/ | ||
public class NumberToken extends Token { | ||
// ATTRIBUTES | ||
//============================================================== | ||
/** | ||
* the number this token stands for | ||
*/ | ||
private final long number; | ||
|
||
// CONSTRUCTORS | ||
//============================================================== | ||
|
||
/**** | ||
* Creates a new NumberToken from a number and position data. | ||
***************************************************************/ | ||
public NumberToken(final long number, final String filename, final long line, | ||
final int position) { | ||
super(TokenType.NUMBER, filename, line, position); | ||
this.number = number; | ||
} | ||
|
||
// GETTER | ||
//============================================================== | ||
|
||
/** | ||
* @return the number this token stands for | ||
*/ | ||
long getNumber() { | ||
return number; | ||
} | ||
|
||
// METHODS | ||
//============================================================== | ||
// public methods | ||
//-------------------------------------------------------------- | ||
|
||
/** | ||
* Two NumberTokens are equal if both have the type NumberToken and their numbers, line | ||
* numbers, positions and filenames are equal. | ||
* | ||
* @param obj ideally a NumberToken to compare this with | ||
* @return whether this is equal to obj | ||
*/ | ||
@Override | ||
public boolean equals(final Object obj) { | ||
if (!super.equals(obj)) { | ||
return false; | ||
} | ||
return obj instanceof NumberToken && ((NumberToken) obj).number == number; | ||
} | ||
|
||
/** | ||
* Creates a String representation of this NumberToken in the following format: | ||
* FILENAME(LINE,POSITION): TYPE(NUMBER) | ||
* | ||
* @return a String representation of this NumberToken | ||
*/ | ||
@Override | ||
public String toString() { | ||
return super.toString() + String.format("(%d)", number); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.merkrafter.lexing; | ||
|
||
/**** | ||
* This class serves as a token and stores a string that could not be recognized as another token. | ||
* | ||
* @version v0.2.0 | ||
* @author merkrafter | ||
***************************************************************/ | ||
public class OtherToken extends Token { | ||
// ATTRIBUTES | ||
//============================================================== | ||
/** | ||
* the string that could not be recognized as another token | ||
*/ | ||
private final String string; | ||
|
||
// CONSTRUCTORS | ||
//============================================================== | ||
|
||
/**** | ||
* Creates a new OtherToken from a string and position data. | ||
***************************************************************/ | ||
public OtherToken(final String string, final String filename, final long line, | ||
final int position) { | ||
super(TokenType.OTHER, filename, line, position); | ||
this.string = string; | ||
} | ||
|
||
// GETTER | ||
//============================================================== | ||
|
||
/** | ||
* @return the string that could not be recognized as another token | ||
*/ | ||
String getString() { | ||
return string; | ||
} | ||
|
||
// METHODS | ||
//============================================================== | ||
// public methods | ||
//-------------------------------------------------------------- | ||
|
||
/** | ||
* Two OtherTokens are equal if both have the type OtherToken and their strings, line | ||
* numbers, positions and filenames are equal. | ||
* | ||
* @param obj ideally a OtherToken to compare this with | ||
* @return whether this is equal to obj | ||
*/ | ||
@Override | ||
public boolean equals(final Object obj) { | ||
if (!super.equals(obj)) { | ||
return false; | ||
} | ||
return obj instanceof OtherToken && ((OtherToken) obj).string.equals(string); | ||
} | ||
|
||
/** | ||
* Creates a String representation of this OtherToken in the following format: | ||
* FILENAME(LINE,POSITION): TYPE(STRING) | ||
* | ||
* @return a String representation of this OtherToken | ||
*/ | ||
@Override | ||
public String toString() { | ||
return super.toString() + String.format("(%s)", string); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.