Formatted the files in the scanner package
This commit is contained in:
parent
dd8f4172e4
commit
4a5f169076
|
@ -1,8 +1,8 @@
|
|||
package scanner;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Removes Lisp comments from an input stream.
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
package scanner;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* A <code>LispScanner</code> converts a stream of bytes into a stream of Lisp
|
||||
|
@ -48,9 +48,9 @@ public class LispScanner {
|
|||
* to <code>nextToken</code> have been made yet, this method returns
|
||||
* <code>null</code>.
|
||||
*
|
||||
* @return
|
||||
* the last Lisp token returned from this scanner or <code>null</code> (if
|
||||
* no tokens have been returned from this scanner yet)
|
||||
* @return the last Lisp token returned from this scanner or
|
||||
* <code>null</code> (if no tokens have been returned from this
|
||||
* scanner yet)
|
||||
*/
|
||||
public Token getCurrToken() {
|
||||
return currToken;
|
||||
|
@ -59,11 +59,11 @@ public class LispScanner {
|
|||
/**
|
||||
* Returns the next Lisp token from this scanner.
|
||||
*
|
||||
* @return
|
||||
* the next Lisp token from this scanner.
|
||||
* @return the next Lisp token from this scanner.
|
||||
* @throws RuntimeException
|
||||
* Indicates that an illegal character or an unterminated quoted string
|
||||
* was encountered in the input stream (not counting comments).
|
||||
* Indicates that an illegal character or an unterminated quoted
|
||||
* string was encountered in the input stream (not counting
|
||||
* comments).
|
||||
* @throws IOException
|
||||
* Indicates that an I/O error has occurred.
|
||||
*/
|
||||
|
@ -100,23 +100,11 @@ public class LispScanner {
|
|||
|
||||
break;
|
||||
case '(':
|
||||
return new Token(Token.Type.LEFT_PAREN,
|
||||
"(",
|
||||
fileName,
|
||||
line,
|
||||
column);
|
||||
return new Token(Token.Type.LEFT_PAREN, "(", fileName, line, column);
|
||||
case ')':
|
||||
return new Token(Token.Type.RIGHT_PAREN,
|
||||
")",
|
||||
fileName,
|
||||
line,
|
||||
column);
|
||||
return new Token(Token.Type.RIGHT_PAREN, ")", fileName, line, column);
|
||||
case '\'':
|
||||
return new Token(Token.Type.QUOTE_MARK,
|
||||
"\'",
|
||||
fileName,
|
||||
line,
|
||||
column);
|
||||
return new Token(Token.Type.QUOTE_MARK, "\'", fileName, line, column);
|
||||
case '\"':
|
||||
return retrieveString(nextChar);
|
||||
default:
|
||||
|
@ -129,10 +117,8 @@ public class LispScanner {
|
|||
} else {
|
||||
// 'nextChar' can not start any Lisp token
|
||||
|
||||
throw new RuntimeException("illegal character " +
|
||||
"\'" + nextChar + "\'" +
|
||||
" - line " + line +
|
||||
" column " + column);
|
||||
throw new RuntimeException(
|
||||
"illegal character " + "\'" + nextChar + "\'" + " - line " + line + " column " + column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +155,7 @@ public class LispScanner {
|
|||
++column;
|
||||
text.append(nextChar);
|
||||
|
||||
switch(nextChar) {
|
||||
switch (nextChar) {
|
||||
case '\n':
|
||||
++line;
|
||||
column = 0;
|
||||
|
@ -179,11 +165,7 @@ public class LispScanner {
|
|||
if (prevChar != '\\') {
|
||||
// we have found the terminating double quote
|
||||
|
||||
return new Token(Token.Type.STRING,
|
||||
text.toString(),
|
||||
fileName,
|
||||
startLine,
|
||||
startColumn);
|
||||
return new Token(Token.Type.STRING, text.toString(), fileName, startLine, startColumn);
|
||||
}
|
||||
|
||||
// this is an escaped double quote
|
||||
|
@ -195,9 +177,7 @@ public class LispScanner {
|
|||
// the end of 'inStream' was reached before the terminating double
|
||||
// quote
|
||||
|
||||
throw new RuntimeException("unterminated quoted string" +
|
||||
" - line " + startLine +
|
||||
" column " + startColumn);
|
||||
throw new RuntimeException("unterminated quoted string" + " - line " + startLine + " column " + startColumn);
|
||||
}
|
||||
|
||||
// Retrieve a number token from 'inStream'.
|
||||
|
@ -229,11 +209,7 @@ public class LispScanner {
|
|||
|
||||
inStream.reset(); // unread the last character
|
||||
|
||||
return new Token(Token.Type.NUMBER,
|
||||
text.toString(),
|
||||
fileName,
|
||||
line,
|
||||
startColumn);
|
||||
return new Token(Token.Type.NUMBER, text.toString(), fileName, line, startColumn);
|
||||
}
|
||||
|
||||
inStream.mark(1);
|
||||
|
@ -242,11 +218,7 @@ public class LispScanner {
|
|||
// there are no more bytes to be read from 'inStream' after this number
|
||||
// token
|
||||
|
||||
return new Token(Token.Type.NUMBER,
|
||||
text.toString(),
|
||||
fileName,
|
||||
line,
|
||||
startColumn);
|
||||
return new Token(Token.Type.NUMBER, text.toString(), fileName, line, startColumn);
|
||||
}
|
||||
|
||||
// Retrieve an identifier token from 'inStream'.
|
||||
|
@ -278,11 +250,7 @@ public class LispScanner {
|
|||
|
||||
inStream.reset(); // unread the last character
|
||||
|
||||
return new Token(Token.Type.IDENTIFIER,
|
||||
text.toString(),
|
||||
fileName,
|
||||
line,
|
||||
startColumn);
|
||||
return new Token(Token.Type.IDENTIFIER, text.toString(), fileName, line, startColumn);
|
||||
}
|
||||
|
||||
inStream.mark(1);
|
||||
|
@ -291,11 +259,7 @@ public class LispScanner {
|
|||
// there are no more bytes to be read from 'inStream' after this
|
||||
// identifier token
|
||||
|
||||
return new Token(Token.Type.IDENTIFIER,
|
||||
text.toString(),
|
||||
fileName,
|
||||
line,
|
||||
startColumn);
|
||||
return new Token(Token.Type.IDENTIFIER, text.toString(), fileName, line, startColumn);
|
||||
}
|
||||
|
||||
// Test if a character is legal to be contained within an identifier in
|
||||
|
@ -304,17 +268,8 @@ public class LispScanner {
|
|||
// Returns: 'true' if the character can be found within an identifier in
|
||||
// Lisp; 'false' otherwise
|
||||
private boolean isLegalIdChar(char c) {
|
||||
return ((! Character.isWhitespace(c)) && (c != '\"')
|
||||
&& (c != '\'')
|
||||
&& (c != '\\')
|
||||
&& (c != '`')
|
||||
&& (c != '(')
|
||||
&& (c != ')')
|
||||
&& (c != '[')
|
||||
&& (c != ']')
|
||||
&& (c != '#')
|
||||
&& (c != '.')
|
||||
&& (c != ';'));
|
||||
return ((!Character.isWhitespace(c)) && (c != '\"') && (c != '\'') && (c != '\\') && (c != '`') && (c != '(')
|
||||
&& (c != ')') && (c != '[') && (c != ']') && (c != '#') && (c != '.') && (c != ';'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,8 +70,7 @@ public class Token {
|
|||
/**
|
||||
* Accessor method to determine the type of this token.
|
||||
*
|
||||
* @return
|
||||
* the type of this token
|
||||
* @return the type of this token
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
|
@ -80,8 +79,7 @@ public class Token {
|
|||
/**
|
||||
* Accessor method to determine the text associated with this token.
|
||||
*
|
||||
* @return
|
||||
* the text associated with this token
|
||||
* @return the text associated with this token
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
|
@ -91,8 +89,7 @@ public class Token {
|
|||
* Accessor method to determine the name of the file that this token was
|
||||
* located in.
|
||||
*
|
||||
* @return
|
||||
* the name of the file that this token was located in
|
||||
* @return the name of the file that this token was located in
|
||||
*/
|
||||
public String getFName() {
|
||||
return fName;
|
||||
|
@ -102,8 +99,7 @@ public class Token {
|
|||
* Accessor method to determine the line number that this token was found
|
||||
* on.
|
||||
*
|
||||
* @return
|
||||
* the line number this token was found on
|
||||
* @return the line number this token was found on
|
||||
*/
|
||||
public int getLine() {
|
||||
return line;
|
||||
|
@ -113,8 +109,7 @@ public class Token {
|
|||
* Accessor method to determine the column number that this token was found
|
||||
* on.
|
||||
*
|
||||
* @return
|
||||
* the column number this token was found on
|
||||
* @return the column number this token was found on
|
||||
*/
|
||||
public int getColumn() {
|
||||
return column;
|
||||
|
|
Loading…
Reference in New Issue