mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-06-02 12:41:32 +00:00
Add BYE keyword, indent/outdent FOR/NEXT loops (still need to refactor to eliminate duplicate spaces between two tokens)
This commit is contained in:
parent
cfd8c21c26
commit
51f442d291
|
@ -31,6 +31,7 @@ import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
|
||||||
* Filter the given file as an Apple /// Business BASIC file.
|
* Filter the given file as an Apple /// Business BASIC file.
|
||||||
* <p>
|
* <p>
|
||||||
* Date created: Dec 15, 2008 11:12:10 PM
|
* Date created: Dec 15, 2008 11:12:10 PM
|
||||||
|
*
|
||||||
* @author David Schmidt
|
* @author David Schmidt
|
||||||
*/
|
*/
|
||||||
public class BusinessBASICFileFilter implements FileFilter {
|
public class BusinessBASICFileFilter implements FileFilter {
|
||||||
|
@ -42,7 +43,9 @@ public class BusinessBASICFileFilter implements FileFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the given FileEntry and return a text image of the Business BASIC file.
|
* Process the given FileEntry and return a text image of the Business BASIC
|
||||||
|
* file.
|
||||||
|
*
|
||||||
* @see com.webcodepro.applecommander.storage.FileFilter#filter(FileEntry)
|
* @see com.webcodepro.applecommander.storage.FileFilter#filter(FileEntry)
|
||||||
*/
|
*/
|
||||||
public byte[] filter(FileEntry fileEntry) {
|
public byte[] filter(FileEntry fileEntry) {
|
||||||
|
@ -50,6 +53,7 @@ public class BusinessBASICFileFilter implements FileFilter {
|
||||||
PrintWriter printWriter = new PrintWriter(byteArray, true);
|
PrintWriter printWriter = new PrintWriter(byteArray, true);
|
||||||
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(fileEntry);
|
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(fileEntry);
|
||||||
boolean firstLine = true;
|
boolean firstLine = true;
|
||||||
|
int nest = 0;
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
BusinessBASICToken token = tokenizer.getNextToken();
|
BusinessBASICToken token = tokenizer.getNextToken();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
|
@ -61,11 +65,21 @@ public class BusinessBASICFileFilter implements FileFilter {
|
||||||
printWriter.println();
|
printWriter.println();
|
||||||
}
|
}
|
||||||
printWriter.print(token.getLineNumber());
|
printWriter.print(token.getLineNumber());
|
||||||
printWriter.print(" "); //$NON-NLS-1$
|
if (nest > 0) {
|
||||||
|
for (int i = 1; i < nest; i++)
|
||||||
|
printWriter.print(" "); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (token.isIndenter())
|
||||||
|
nest ++;
|
||||||
|
else if (token.isOutdenter())
|
||||||
|
nest --;
|
||||||
|
*/
|
||||||
|
//printWriter.print(" "); //$NON-NLS-1$
|
||||||
} else if (token.isToken()) {
|
} else if (token.isToken()) {
|
||||||
printWriter.print(token.getTokenString());
|
printWriter.print(token.getTokenString());
|
||||||
} else {
|
} else {
|
||||||
printWriter.print(token.getStringValue());
|
printWriter.print(" "+token.getStringValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printWriter.close();
|
printWriter.close();
|
||||||
|
|
|
@ -29,7 +29,6 @@ import com.webcodepro.applecommander.ui.swt.FileViewerWindow;
|
||||||
import com.webcodepro.applecommander.ui.swt.util.contentadapter.StyledTextAdapter;
|
import com.webcodepro.applecommander.ui.swt.util.contentadapter.StyledTextAdapter;
|
||||||
import com.webcodepro.applecommander.util.BusinessBASICToken;
|
import com.webcodepro.applecommander.util.BusinessBASICToken;
|
||||||
import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
|
import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
|
||||||
import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a view of a syntax-colored Apple /// Business BASIC program listing.
|
* Provides a view of a syntax-colored Apple /// Business BASIC program listing.
|
||||||
|
@ -71,6 +70,8 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||||
|
|
||||||
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(getFileEntry());
|
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(getFileEntry());
|
||||||
boolean firstLine = true;
|
boolean firstLine = true;
|
||||||
|
boolean firstData = true;
|
||||||
|
int nestLevels = 0;
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
BusinessBASICToken token = tokenizer.getNextToken();
|
BusinessBASICToken token = tokenizer.getNextToken();
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
|
@ -81,13 +82,22 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||||
} else {
|
} else {
|
||||||
styledText.append("\n"); //$NON-NLS-1$
|
styledText.append("\n"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
firstData = true;
|
||||||
styledText.append(Integer.toString(token.getLineNumber()));
|
styledText.append(Integer.toString(token.getLineNumber()));
|
||||||
styledText.append(" "); //$NON-NLS-1$
|
styledText.append(" "); //$NON-NLS-1$
|
||||||
|
if (nestLevels > 0) {
|
||||||
|
for (int i = 0; i < nestLevels; i++)
|
||||||
|
styledText.append(" "); //$NON-NLS-1$
|
||||||
|
}
|
||||||
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
|
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
|
||||||
styledText.append(token.getStringValue());
|
styledText.append(token.getStringValue());
|
||||||
|
firstData = false;
|
||||||
} else if (token.isEndOfCommand()) {
|
} else if (token.isEndOfCommand()) {
|
||||||
styledText.append("\n"); //$NON-NLS-1$
|
styledText.append("\n"); //$NON-NLS-1$
|
||||||
|
firstData = false;
|
||||||
} else if (token.isString()) {
|
} else if (token.isString()) {
|
||||||
|
if (firstData)
|
||||||
|
styledText.append(" "); //$NON-NLS-1$
|
||||||
int caretOffset = styledText.getCharCount();
|
int caretOffset = styledText.getCharCount();
|
||||||
styledText.append(token.getStringValue());
|
styledText.append(token.getStringValue());
|
||||||
StyleRange styleRange = new StyleRange();
|
StyleRange styleRange = new StyleRange();
|
||||||
|
@ -95,6 +105,7 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||||
styleRange.length = token.getStringValue().length();
|
styleRange.length = token.getStringValue().length();
|
||||||
styleRange.foreground = getGreenColor();
|
styleRange.foreground = getGreenColor();
|
||||||
styledText.setStyleRange(styleRange);
|
styledText.setStyleRange(styleRange);
|
||||||
|
firstData = false;
|
||||||
} else if (token.isToken()) {
|
} else if (token.isToken()) {
|
||||||
int caretOffset = styledText.getCharCount();
|
int caretOffset = styledText.getCharCount();
|
||||||
styledText.append(token.getTokenString());
|
styledText.append(token.getTokenString());
|
||||||
|
@ -104,7 +115,12 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||||
//styleRange.fontStyle = SWT.BOLD;
|
//styleRange.fontStyle = SWT.BOLD;
|
||||||
styleRange.foreground = getBlueColor();
|
styleRange.foreground = getBlueColor();
|
||||||
styledText.setStyleRange(styleRange);
|
styledText.setStyleRange(styleRange);
|
||||||
|
firstData = false;
|
||||||
|
if (token.isIndenter()) {
|
||||||
|
nestLevels ++; }
|
||||||
|
else if (token.isOutdenter()) {
|
||||||
|
nestLevels --; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,46 +10,54 @@ public class BusinessBASICToken {
|
||||||
private byte tokenValue;
|
private byte tokenValue;
|
||||||
private String tokenString;
|
private String tokenString;
|
||||||
private String stringValue;
|
private String stringValue;
|
||||||
|
|
||||||
public BusinessBASICToken(int lineNumber) {
|
public BusinessBASICToken(int lineNumber) {
|
||||||
this.lineNumber = lineNumber;
|
this.lineNumber = lineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BusinessBASICToken(byte tokenValue, String tokenString) {
|
public BusinessBASICToken(byte tokenValue, String tokenString) {
|
||||||
this.tokenValue = tokenValue;
|
this.tokenValue = tokenValue;
|
||||||
this.tokenString = tokenString;
|
this.tokenString = tokenString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BusinessBASICToken(String stringValue) {
|
public BusinessBASICToken(String stringValue) {
|
||||||
this.stringValue = stringValue;
|
this.stringValue = stringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCommandSeparator() {
|
public boolean isCommandSeparator() {
|
||||||
return ":".equals(stringValue); //$NON-NLS-1$
|
return ":".equals(stringValue); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLineNumber() {
|
public boolean isLineNumber() {
|
||||||
return !isToken() && !isString();
|
return !isToken() && !isString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEndOfCommand() {
|
public boolean isEndOfCommand() {
|
||||||
return isLineNumber() || isCommandSeparator();
|
return isLineNumber() || isCommandSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isToken() {
|
public boolean isToken() {
|
||||||
return tokenString != null;
|
return tokenString != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isString() {
|
public boolean isString() {
|
||||||
return stringValue != null;
|
return stringValue != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpressionSeparator() {
|
public boolean isExpressionSeparator() {
|
||||||
return isCommandSeparator()
|
return isCommandSeparator()
|
||||||
|| ",".equals(stringValue) //$NON-NLS-1$
|
|| ",".equals(stringValue) //$NON-NLS-1$
|
||||||
|| ";".equals(stringValue); //$NON-NLS-1$
|
|| ";".equals(stringValue); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIndenter() {
|
||||||
|
return isToken() && tokenString.equals(" FOR "); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOutdenter() {
|
||||||
|
return isToken() && tokenString.equals(" NEXT "); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the line number.
|
* Get the line number.
|
||||||
*/
|
*/
|
||||||
|
@ -90,4 +98,4 @@ public class BusinessBASICToken {
|
||||||
return getStringValue();
|
return getStringValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* AppleCommander - An Apple ][ image utility.
|
* AppleCommander - An Apple ][ image utility.
|
||||||
* Copyright (C) 2008 by David Schmidt
|
* Copyright (C) 2008 by David Schmidt
|
||||||
* robgreene at users.sourceforge.net
|
* david__schmidt at users.sourceforge.net
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
@ -41,7 +41,7 @@ import com.webcodepro.applecommander.storage.FileEntry;
|
||||||
public class BusinessBASICTokenizer {
|
public class BusinessBASICTokenizer {
|
||||||
private static String tokens[] = { // starts at $80
|
private static String tokens[] = { // starts at $80
|
||||||
" END ", " FOR ", " NEXT ", " INPUT ", " OUTPUT ", " DIM ", " READ ", " WRITE ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
" END ", " FOR ", " NEXT ", " INPUT ", " OUTPUT ", " DIM ", " READ ", " WRITE ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
||||||
" OPEN ", " CLOSE ", " *error* ", " TEXT ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
" OPEN ", " CLOSE ", " *error* ", " TEXT ", " *error* ", " BYE ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
||||||
" *error* ", " *error* ", " *error* ", " WINDOW ", " INVOKE ", " PERFORM ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
" *error* ", " *error* ", " *error* ", " WINDOW ", " INVOKE ", " PERFORM ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
||||||
" FRE ", " HPOS ", " VPOS ", " ERRLIN ", " ERR ", " KBD ", " EOF ", " TIME$ ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
" FRE ", " HPOS ", " VPOS ", " ERRLIN ", " ERR ", " KBD ", " EOF ", " TIME$ ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
||||||
" DATE$ ", " PREFIX$ ", " EXFN. ", " EXFN%. ", " OUTREC ", " INDENT ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
" DATE$ ", " PREFIX$ ", " EXFN. ", " EXFN%. ", " OUTREC ", " INDENT ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
|
||||||
|
@ -78,21 +78,21 @@ public class BusinessBASICTokenizer {
|
||||||
public BusinessBASICTokenizer(FileEntry fileEntry) {
|
public BusinessBASICTokenizer(FileEntry fileEntry) {
|
||||||
this(fileEntry.getFileData());
|
this(fileEntry.getFileData());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for BusinessBASICTokenizer.
|
* Constructor for BusinessBASICTokenizer.
|
||||||
*/
|
*/
|
||||||
public BusinessBASICTokenizer(byte[] fileData) {
|
public BusinessBASICTokenizer(byte[] fileData) {
|
||||||
this.fileData = fileData;
|
this.fileData = fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if there are more tokens in the Business BASIC program.
|
* Indicates if there are more tokens in the Business BASIC program.
|
||||||
*/
|
*/
|
||||||
public boolean hasMoreTokens() {
|
public boolean hasMoreTokens() {
|
||||||
return (offset < fileData.length);
|
return (offset < fileData.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answer with the next token in the Business BASIC program. This may be
|
* Answer with the next token in the Business BASIC program. This may be
|
||||||
* code, string pieces, line numbers.
|
* code, string pieces, line numbers.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user