|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.borland.primetime.editor.AbstractScanner
This class is the abstract base for language scanner classes used for syntax highlighting.
The scanner operates on one line at a time, and it's built to be able to do incremental updates of the syntax information. It starts scanning on the line on which the change began, and stops scanning when it reaches a line that has no style changes from what it was in the previous scan.
Subclasses will override this class to deal with the keywords specific to the language the scanner is being built for. Note that all of the token recognition methods were built for the Java language, but all of them can be overridden in a subclass to deal with languages that have different rules. For example, if the language has different comment rules, the checkComment(...) method will also need to be overridden.
EditorDocument.StyledLeafElement
,
EditorDocument.RunInfo
,
Scanner
Field Summary | |
protected int |
bp
The buffer pointer. |
protected char[] |
buf
The input buffer. |
protected char |
ch
The character which the scanner is currently considering. |
protected EditorDocument |
currentDocument
The current document containing the lines we are parsing. |
protected int |
currentIndex
The document line we're currently parsing. |
protected int |
endIndex
The line of the document after which we will consider stopping parsing. |
static char |
EOF
The scanner adds '\0' as the EOF marker to each token stream |
static int |
IN_COMMENT
One of the scanner states: scanner is processing a comment. |
static int |
IN_JAVA_DOC
One of the scanner states: scanner is processing a JavaDoc comment. |
static int |
NORMAL
One of the scanner states: scanner is not in any special state |
protected int |
startIndex
The line of the document where we started parsing. |
protected int |
stateFlags
The scanner state after the last token was read. |
Constructor Summary | |
AbstractScanner()
|
Method Summary | |
protected int |
checkComment(int initialState)
Check if the current character, in 'ch', is part of a Java comment, and if so, advance the buffer pointer past the entire comment. |
protected int |
checkIdentifier(int initialState)
Check if the current character, in 'ch', is the start of a Java identifier, and if so, advance the buffer pointer past the identifier. |
protected int |
checkNumber(int initialState)
Check if the current character, in 'ch', is part of a Java number, and if so, advance the buffer pointer past the entire number. |
protected int |
checkString(int initialState)
Check if the current character, in 'ch', is part of a Java string, and if so, advance the buffer pointer past the entire string. |
protected int |
checkSymbol(int initialState)
Check if the current character, in 'ch', is part of a Java symbol, and if so, advance the buffer pointer past the entire symbol. |
protected int |
checkWhitespace(int initialState)
Check if the current character, in 'ch', is a Java whitespace character, and if so, advance the buffer pointer till the next non-whitespace character. |
protected void |
initialize(javax.swing.text.Segment text)
Called before starting a scan. |
protected void |
initialize(javax.swing.text.Segment text,
javax.swing.text.Segment text2)
Specialized (internal) version of initialize. |
protected static int |
initMap(java.util.HashMap map,
java.lang.String[] words,
boolean caseSensitive)
Internal routine to intialize a HashMap with an array of strings. |
protected abstract boolean |
isExtendedKeyword(java.lang.String str)
One of the abstract functions that a scanner derived from AbstractScanner has to implement. |
protected abstract boolean |
isKeyword(java.lang.String str)
One of the abstract functions that a scanner derived from AbstractScanner has to implement. |
protected boolean |
isSymbol(char ch)
The default implementation of checkSymbol will call this method to determine whether or not a particular character is a valid Java symbol. |
protected boolean |
isValidIdentifierPart(char ch)
The default implementation of checkIdentifier will call this method to determine whether or not a particular character can be a part of a Java identifier. |
protected boolean |
isValidIdentifierStart(char ch)
The default implementation of checkIdentifier will call this method to determine whether or not a particular character can be the start of a Java identifier. |
protected int |
nextToken(int initialState)
Normally called by scanLine to read the next token. |
void |
parse(javax.swing.event.DocumentEvent e)
Called externally to do a parse. |
protected boolean |
scanLine(EditorDocument.StyledLeafElement leaf,
EditorDocument.StyledLeafElement leaf2,
int initialState)
Specialized (internal) version of scanLine. |
protected boolean |
scanLine(EditorDocument.StyledLeafElement leaf,
int initialState)
Called by parse to actually scan a leaf of the document (which corresponds to a line of text). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final char EOF
public static final int NORMAL
public static final int IN_COMMENT
public static final int IN_JAVA_DOC
protected int stateFlags
protected char[] buf
protected int bp
protected char ch
protected int currentIndex
protected EditorDocument currentDocument
protected int startIndex
protected int endIndex
Constructor Detail |
public AbstractScanner()
Method Detail |
protected static int initMap(java.util.HashMap map, java.lang.String[] words, boolean caseSensitive)
map
- the HashMap to fillwords
- the words to put into the hash map as keyscaseSensitive
- if true, store the words as is,
if false, store the words after uppercasing them.public void parse(javax.swing.event.DocumentEvent e)
parse
in interface Scanner
e
- The DocumentEvent that generated this parse call. From the
offset and length of this event, the scanner determines where
to start parsing and how much of the document must be processed.scanLine(com.borland.primetime.editor.EditorDocument.StyledLeafElement, int)
protected boolean scanLine(EditorDocument.StyledLeafElement leaf, int initialState)
leaf
- The leaf of the document that needs to be scanned.initialState
- The flags in effect at the start of this line. This
state carries over from previous lines, and retains information
such as whether the scanner should treat this line as part of a
multi-line comment block.protected boolean scanLine(EditorDocument.StyledLeafElement leaf, EditorDocument.StyledLeafElement leaf2, int initialState)
leaf
- The leaf of the document that needs to be scanned.leaf2
- The second leaf of the document that needs to be scanned.initialState
- The flags in effect at the start of this line. This
state carries over from previous lines, and retains information
such as whether the scanner should treat this line as part of a
multi-line comment block.protected void initialize(javax.swing.text.Segment text)
text
- A Segment object that contains the text that needs to be scanned.protected void initialize(javax.swing.text.Segment text, javax.swing.text.Segment text2)
text
- A Segment object that contains the first part of the
text that needs to be scanned.text2
- A Segment object that contains the second part of the
text that needs to be scanned.protected int nextToken(int initialState)
initalState
- The state of the scanner when nextToken was called.-1
in case of EOF.BasicStyleMap.CARET
,
BasicStyleMap.SELECTION
,
BasicStyleMap.INPUT_METHOD
,
BasicStyleMap.PLAIN
,
BasicStyleMap.WHITESPACE
,
BasicStyleMap.COMMENT
,
BasicStyleMap.RESERVED_WORD
,
BasicStyleMap.IDENTIFIER
,
BasicStyleMap.SYMBOL
,
BasicStyleMap.STRING
,
BasicStyleMap.NUMBER
,
BasicStyleMap.EXTRA_KEYWORD
,
BasicStyleMap.ILLEGAL
,
BasicStyleMap.PREPROCESSOR
protected abstract boolean isKeyword(java.lang.String str)
str
- The string to be checkedcheckIdentifier(int)
protected abstract boolean isExtendedKeyword(java.lang.String str)
str
- the string to be checkedcheckIdentifier(int)
protected boolean isValidIdentifierStart(char ch)
ch
- the char to be checkedcheckIdentifier(int)
protected boolean isValidIdentifierPart(char ch)
ch
- the char to be checkedcheckIdentifier(int)
protected boolean isSymbol(char ch)
ch
- the char to be checkedcheckSymbol(int)
protected int checkWhitespace(int initialState)
initialState
- The current parser state-1
otherwise.BasicStyleMap.WHITESPACE
protected int checkComment(int initialState)
initialState
- The current parser state-1
otherwise.BasicStyleMap.COMMENT
protected int checkIdentifier(int initialState)
initialState
- The current parser state-1
otherwise.
Returns one of:
BasicStyleMap.RESERVED_WORD
BasicStyleMap.EXTRA_KEYWORD
BasicStyleMap.IDENTIFIERBasicStyleMap.RESERVED_WORD
,
BasicStyleMap.EXTRA_KEYWORD
,
BasicStyleMap.IDENTIFIER
,
isValidIdentifierStart(char)
,
isValidIdentifierPart(char)
,
isKeyword(java.lang.String)
,
isExtendedKeyword(java.lang.String)
protected int checkNumber(int initialState)
initialState
- The current parser state-1
otherwise.BasicStyleMap.NUMBER
protected int checkString(int initialState)
initialState
- The current parser state-1
otherwise.BasicStyleMap.STRING
protected int checkSymbol(int initialState)
initialState
- The current parser state-1
otherwise.BasicStyleMap.SYMBOL
,
isSymbol(char)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |