Formatted the files in the scanner package

This commit is contained in:
Mike Cifelli 2016-12-08 16:12:29 -05:00
parent dd8f4172e4
commit 4a5f169076
3 changed files with 60 additions and 110 deletions

View File

@ -1,8 +1,8 @@
package scanner; package scanner;
import java.io.InputStream;
import java.io.FilterInputStream; import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
/** /**
* Removes Lisp comments from an input stream. * Removes Lisp comments from an input stream.

View File

@ -6,9 +6,9 @@
package scanner; package scanner;
import java.io.InputStream;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
/** /**
* A <code>LispScanner</code> converts a stream of bytes into a stream of Lisp * 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 * to <code>nextToken</code> have been made yet, this method returns
* <code>null</code>. * <code>null</code>.
* *
* @return * @return the last Lisp token returned from this scanner or
* the last Lisp token returned from this scanner or <code>null</code> (if * <code>null</code> (if no tokens have been returned from this
* no tokens have been returned from this scanner yet) * scanner yet)
*/ */
public Token getCurrToken() { public Token getCurrToken() {
return currToken; return currToken;
@ -59,11 +59,11 @@ public class LispScanner {
/** /**
* Returns the next Lisp token from this scanner. * Returns the next Lisp token from this scanner.
* *
* @return * @return the next Lisp token from this scanner.
* the next Lisp token from this scanner.
* @throws RuntimeException * @throws RuntimeException
* Indicates that an illegal character or an unterminated quoted string * Indicates that an illegal character or an unterminated quoted
* was encountered in the input stream (not counting comments). * string was encountered in the input stream (not counting
* comments).
* @throws IOException * @throws IOException
* Indicates that an I/O error has occurred. * Indicates that an I/O error has occurred.
*/ */
@ -100,23 +100,11 @@ public class LispScanner {
break; break;
case '(': case '(':
return new Token(Token.Type.LEFT_PAREN, return new Token(Token.Type.LEFT_PAREN, "(", fileName, line, column);
"(",
fileName,
line,
column);
case ')': case ')':
return new Token(Token.Type.RIGHT_PAREN, return new Token(Token.Type.RIGHT_PAREN, ")", fileName, line, column);
")",
fileName,
line,
column);
case '\'': case '\'':
return new Token(Token.Type.QUOTE_MARK, return new Token(Token.Type.QUOTE_MARK, "\'", fileName, line, column);
"\'",
fileName,
line,
column);
case '\"': case '\"':
return retrieveString(nextChar); return retrieveString(nextChar);
default: default:
@ -129,10 +117,8 @@ public class LispScanner {
} else { } else {
// 'nextChar' can not start any Lisp token // 'nextChar' can not start any Lisp token
throw new RuntimeException("illegal character " + throw new RuntimeException(
"\'" + nextChar + "\'" + "illegal character " + "\'" + nextChar + "\'" + " - line " + line + " column " + column);
" - line " + line +
" column " + column);
} }
} }
} }
@ -179,11 +165,7 @@ public class LispScanner {
if (prevChar != '\\') { if (prevChar != '\\') {
// we have found the terminating double quote // we have found the terminating double quote
return new Token(Token.Type.STRING, return new Token(Token.Type.STRING, text.toString(), fileName, startLine, startColumn);
text.toString(),
fileName,
startLine,
startColumn);
} }
// this is an escaped double quote // this is an escaped double quote
@ -195,9 +177,7 @@ public class LispScanner {
// the end of 'inStream' was reached before the terminating double // the end of 'inStream' was reached before the terminating double
// quote // quote
throw new RuntimeException("unterminated quoted string" + throw new RuntimeException("unterminated quoted string" + " - line " + startLine + " column " + startColumn);
" - line " + startLine +
" column " + startColumn);
} }
// Retrieve a number token from 'inStream'. // Retrieve a number token from 'inStream'.
@ -229,11 +209,7 @@ public class LispScanner {
inStream.reset(); // unread the last character inStream.reset(); // unread the last character
return new Token(Token.Type.NUMBER, return new Token(Token.Type.NUMBER, text.toString(), fileName, line, startColumn);
text.toString(),
fileName,
line,
startColumn);
} }
inStream.mark(1); inStream.mark(1);
@ -242,11 +218,7 @@ public class LispScanner {
// there are no more bytes to be read from 'inStream' after this number // there are no more bytes to be read from 'inStream' after this number
// token // token
return new Token(Token.Type.NUMBER, return new Token(Token.Type.NUMBER, text.toString(), fileName, line, startColumn);
text.toString(),
fileName,
line,
startColumn);
} }
// Retrieve an identifier token from 'inStream'. // Retrieve an identifier token from 'inStream'.
@ -278,11 +250,7 @@ public class LispScanner {
inStream.reset(); // unread the last character inStream.reset(); // unread the last character
return new Token(Token.Type.IDENTIFIER, return new Token(Token.Type.IDENTIFIER, text.toString(), fileName, line, startColumn);
text.toString(),
fileName,
line,
startColumn);
} }
inStream.mark(1); inStream.mark(1);
@ -291,11 +259,7 @@ public class LispScanner {
// there are no more bytes to be read from 'inStream' after this // there are no more bytes to be read from 'inStream' after this
// identifier token // identifier token
return new Token(Token.Type.IDENTIFIER, return new Token(Token.Type.IDENTIFIER, text.toString(), fileName, line, startColumn);
text.toString(),
fileName,
line,
startColumn);
} }
// Test if a character is legal to be contained within an identifier in // 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 // Returns: 'true' if the character can be found within an identifier in
// Lisp; 'false' otherwise // Lisp; 'false' otherwise
private boolean isLegalIdChar(char c) { private boolean isLegalIdChar(char c) {
return ((! Character.isWhitespace(c)) && (c != '\"') return ((!Character.isWhitespace(c)) && (c != '\"') && (c != '\'') && (c != '\\') && (c != '`') && (c != '(')
&& (c != '\'') && (c != ')') && (c != '[') && (c != ']') && (c != '#') && (c != '.') && (c != ';'));
&& (c != '\\')
&& (c != '`')
&& (c != '(')
&& (c != ')')
&& (c != '[')
&& (c != ']')
&& (c != '#')
&& (c != '.')
&& (c != ';'));
} }
} }

View File

@ -70,8 +70,7 @@ public class Token {
/** /**
* Accessor method to determine the type of this token. * Accessor method to determine the type of this token.
* *
* @return * @return the type of this token
* the type of this token
*/ */
public Type getType() { public Type getType() {
return type; return type;
@ -80,8 +79,7 @@ public class Token {
/** /**
* Accessor method to determine the text associated with this token. * Accessor method to determine the text associated with this token.
* *
* @return * @return the text associated with this token
* the text associated with this token
*/ */
public String getText() { public String getText() {
return text; return text;
@ -91,8 +89,7 @@ public class Token {
* Accessor method to determine the name of the file that this token was * Accessor method to determine the name of the file that this token was
* located in. * located in.
* *
* @return * @return the name of the file that this token was located in
* the name of the file that this token was located in
*/ */
public String getFName() { public String getFName() {
return fName; return fName;
@ -102,8 +99,7 @@ public class Token {
* Accessor method to determine the line number that this token was found * Accessor method to determine the line number that this token was found
* on. * on.
* *
* @return * @return the line number this token was found on
* the line number this token was found on
*/ */
public int getLine() { public int getLine() {
return line; return line;
@ -113,8 +109,7 @@ public class Token {
* Accessor method to determine the column number that this token was found * Accessor method to determine the column number that this token was found
* on. * on.
* *
* @return * @return the column number this token was found on
* the column number this token was found on
*/ */
public int getColumn() { public int getColumn() {
return column; return column;