edu.princeton.toy
public class TProgramDocument extends HighlightedDocument
Modifier and Type | Class and Description |
---|---|
static class |
TProgramDocument.WarningInfoStruct
WarningInfoStruct is a simple class which encapsulates all of the info that getWarnings()
has to return.
|
HighlightedDocument.Position, HighlightedDocument.PositionTriplet, HighlightedDocument.UndoableEdit
Modifier and Type | Field and Description |
---|---|
static int |
COMMENT_COLUMN
The column at which normal (non-autocomment) comments begin.
|
static java.lang.String |
DEFAULT_TITLE
The default title a workspace should take if no program line was found.
|
static java.lang.String |
HEADER_BAR
The bar the separates the description of a program from the code of the program.
|
static int |
MAX_WARNINGS
The maximum number of warnings before a fatal error is thrown.
|
static int |
OUTSIDE_MARGIN_COLUMN
The column at which text is considered past the margin.
|
static byte |
STYLE_AUTO_COMMENT
The index of the auto-comment style.
|
static byte |
STYLE_COMMENT
The index of the comment style.
|
static byte |
STYLE_IDENTIFIER
The index of the header style.
|
static byte |
STYLE_INSTRUCTION
The index of the instruction style.
|
static byte |
STYLE_KEYWORD
The index of the keyword style.
|
static byte |
STYLE_OUTSIDE_MARGIN
The index of the outside-margin style.
|
CHARACTER_ALLOWED, charCount, chars, charStyles, lineCount, lineOffsets, MAX_ALLOWED_CHARACTER, maxLineLength
Constructor and Description |
---|
TProgramDocument()
Constructs a TProgramDocument with a template program.
|
TProgramDocument(java.lang.String text)
Constructs a TProgramDocument with the given program.
|
Modifier and Type | Method and Description |
---|---|
void |
assignStyles()
Parses toy code and uses it to highlight the syntax, update the title, and and update the
warning list.
|
void |
autocomment()
Updates pseudocode comments and performs minor stylistic changes (standardizing
capitalization and putting '//'s before all comments).
|
TWordBuffer |
getInitialStdin()
Returns the initial values which should be in stdin whenever the workspace is reset.
|
TWordBuffer |
getInitialStdin(TWordBuffer buffer)
Returns the initial values which should be in stdin whenever the workspace is reset.
|
int |
getLineDefined(int address,
boolean returnLastLine)
Returns the line on which the given memory address was defined.
|
int |
getStyleCount()
Returns the number of distinct styles used by this type of document.
|
int |
getTabSize()
Returns the number of spaces to replace all tabs with.
|
java.lang.String |
getTitle()
Returns the title of the workspace.
|
TProgramDocument.WarningInfoStruct |
getWarnings(boolean ignoreWarnings)
Returns a list of warnings along with character indices of the start and end of the relevant
text.
|
TProgramDocument.WarningInfoStruct |
getWarnings(TProgramDocument.WarningInfoStruct warningInfo,
boolean ignoreWarnings)
Returns a list of warnings along with character indices of the start and end of the relevant
text.
|
void |
reset(TVirtualMachine virtualMachine)
Resets the virtual machine then copies the program and initial stdin back in.
|
void |
setInitialStdin(TWordBuffer initialStdin)
Sets the initial values which should be in stdin whenever the workspace is reset.
|
void |
setTitle(java.lang.String title) |
void |
stripComments()
Strips all comments (except header comments) off the program.
|
addTextListener, addUndoableEditListener, allowRender, coordinateToOffset, coordinateToOffset, createPosition, createPositionTriplet, filterString, freePosition, freePositionTriplet, getLength, getLineCount, getMaxLineLength, getPositionOffsets, getText, getText, getWordBounds, insertString, offsetToCoordinate, readLock, readUnlock, remove, removeTextListener, removeUndoableEditListener, replace, replace, setText, utilReplace, writeLock, writeUnlock
public static final int MAX_WARNINGS
public static final byte STYLE_IDENTIFIER
public static final byte STYLE_INSTRUCTION
public static final byte STYLE_KEYWORD
public static final byte STYLE_COMMENT
public static final byte STYLE_AUTO_COMMENT
public static final byte STYLE_OUTSIDE_MARGIN
public static final java.lang.String DEFAULT_TITLE
public static final java.lang.String HEADER_BAR
public static final int COMMENT_COLUMN
public static final int OUTSIDE_MARGIN_COLUMN
public TProgramDocument()
public TProgramDocument(java.lang.String text)
public int getLineDefined(int address, boolean returnLastLine)
address
- The address in question. An invalid value will result in an
ArrayIndexOutOfBounds exception.returnLastLine
- Wheter or not to return the last line if the address was never
defined.public TProgramDocument.WarningInfoStruct getWarnings(boolean ignoreWarnings)
ignoreWarnings
- Wheter or not to ignore normal warnings and only report fatal errors.public TProgramDocument.WarningInfoStruct getWarnings(TProgramDocument.WarningInfoStruct warningInfo, boolean ignoreWarnings)
warningInfo
- A WarningInfoStruct which can be reused. If this is null, a new
WarningInfoStruct will be returned.ignoreWarnings
- Wheter or not to ignore normal warnings and only report fatal errors.public TWordBuffer getInitialStdin()
public TWordBuffer getInitialStdin(TWordBuffer buffer)
buffer
- The buffer to copy the data onto. The buffer will be cleared before the copy.public void setInitialStdin(TWordBuffer initialStdin)
initialStdin
- The new values which should be in stdin whenever the workspace is
reset.public java.lang.String getTitle()
public void setTitle(java.lang.String title)
public void reset(TVirtualMachine virtualMachine)
public int getStyleCount()
getStyleCount
in class HighlightedDocument
public int getTabSize()
getTabSize
in class HighlightedDocument
public void assignStyles()
assignStyles
in class HighlightedDocument
public void autocomment()
public void stripComments()