Class TokenMarker
java.lang.Object
mars.venus.editor.jeditsyntax.tokenmarker.TokenMarker
- Direct Known Subclasses:
MIPSTokenMarker
A token marker that splits lines of text into tokens. Each token carries
a length field and an identification tag that can be mapped to a color
for painting that token.
For performance reasons, the linked list of tokens is reused after each
line is tokenized. Therefore, the return value of markTokens
should only be used for immediate painting. Notably, it cannot be
cached.
- Version:
- $Id: TokenMarker.java,v 1.32 1999/12/13 03:40:30 sp Exp $
- Author:
- Slava Pestov
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Inner class for storing information about tokenized lines. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Token
The first token in the list.protected int
The last tokenized line.protected Token
The last token in the list.protected int
The number of lines in the model being tokenized.protected TokenMarker.LineInfo[]
An array for storing information about lines.protected boolean
True if the next line should be painted. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToken
(int length, byte id) Adds a token to the token list.void
deleteLines
(int index, int lines) Informs the token marker that line have been deleted from the document.protected void
ensureCapacity
(int index) Ensures that thelineInfo
array can contain the specified index.int
Returns the number of lines in this token marker.getTokenExactMatchHelp
(Token token, String tokenText) Construct and return any appropriate help information for the given token.getTokenPrefixMatchHelp
(String line, Token tokenList, Token tokenAtOffset, String tokenText) Construct and return any appropriate help information for the given token or "token prefix".void
insertLines
(int index, int lines) Informs the token marker that lines have been inserted into the document.boolean
Returns true if the next line should be repainted.markTokens
(Segment line, int lineIndex) A wrapper for the lower-levelmarkTokensImpl(byte, Segment, int)
method that is called to split a line up into tokens.protected abstract byte
markTokensImpl
(byte token, Segment line, int lineIndex) An abstract method that splits a line up into tokens.boolean
Returns if the token marker supports tokens that span multiple lines.
-
Field Details
-
firstToken
The first token in the list. This should be used as the return value frommarkTokens(Segment, int)
. -
lastToken
The last token in the list. New tokens are added here. This should be set to null before a new line is to be tokenized. -
lineInfo
An array for storing information about lines. It is enlarged and shrunk automatically by theinsertLines(int, int)
anddeleteLines(int, int)
methods. -
length
protected int lengthThe number of lines in the model being tokenized. This can be less than the length of thelineInfo
array. -
lastLine
protected int lastLineThe last tokenized line. -
nextLineRequested
protected boolean nextLineRequestedTrue if the next line should be painted.
-
-
Constructor Details
-
TokenMarker
protected TokenMarker()Creates a newTokenMarker
. This DOES NOT create alineInfo
array; an initial call toinsertLines(int, int)
does that.
-
-
Method Details
-
markTokens
A wrapper for the lower-levelmarkTokensImpl(byte, Segment, int)
method that is called to split a line up into tokens.- Parameters:
line
- The linelineIndex
- The index of the line
-
markTokensImpl
An abstract method that splits a line up into tokens. It should parse the line, and calladdToken(int, byte)
to add syntax tokens to the token list. Then, it should return the initial token type for the next line.For example, if the current line contains the start of a multiline comment that doesn't end on that line, this method should return the comment token type so that it continues on the next line.
- Parameters:
token
- The initial token type for this lineline
- The line to be tokenizedlineIndex
- The index of the line in the document, starting at 0- Returns:
- The initial token type for the next line
-
supportsMultilineTokens
public boolean supportsMultilineTokens()Returns if the token marker supports tokens that span multiple lines. If this is true, the object using this token marker is required to pass all lines in the document to themarkTokens(Segment, int)
method (in turn).The default implementation returns true; it should be overridden to return false on simpler token markers for increased speed.
-
insertLines
public void insertLines(int index, int lines) Informs the token marker that lines have been inserted into the document. This inserts a gap in thelineInfo
array.- Parameters:
index
- The first line numberlines
- The number of lines
-
deleteLines
public void deleteLines(int index, int lines) Informs the token marker that line have been deleted from the document. This removes the lines in question from thelineInfo
array.- Parameters:
index
- The first line numberlines
- The number of lines
-
getLineCount
public int getLineCount()Returns the number of lines in this token marker. -
isNextLineRequested
public boolean isNextLineRequested()Returns true if the next line should be repainted. This will return true after a line has been tokenized that starts a multiline token that continues onto the next line. -
getTokenExactMatchHelp
Construct and return any appropriate help information for the given token. This default definition returns null; override it in language-specific subclasses.- Parameters:
token
- the pertinent Token objecttokenText
- the source String that matched to the token- Returns:
- ArrayList containing PopupHelpItem objects, one per match.
-
getTokenPrefixMatchHelp
public ArrayList<PopupHelpItem> getTokenPrefixMatchHelp(String line, Token tokenList, Token tokenAtOffset, String tokenText) Construct and return any appropriate help information for the given token or "token prefix". Will match instruction prefixes, e.g. "s" matches "sw". This default definition returns null; override it in language-specific subclasses.- Parameters:
line
- String containing current linetokenList
- first Token on the current linetokenAtOffset
- the pertinent Token objecttokenText
- the source String that matched to the token- Returns:
- ArrayList containing PopupHelpItem objects, one per match.
-
ensureCapacity
protected void ensureCapacity(int index) Ensures that thelineInfo
array can contain the specified index. This enlarges it if necessary. No action is taken if the array is large enough already.It should be unnecessary to call this under normal circumstances;
insertLines(int, int)
should take care of enlarging the line info array automatically.- Parameters:
index
- The array index
-
addToken
protected void addToken(int length, byte id) Adds a token to the token list.- Parameters:
length
- The length of the tokenid
- The id of the token
-