Package org.eclipse.jface.text.rules
Class RuleBasedScanner
java.lang.Object
org.eclipse.jface.text.rules.RuleBasedScanner
- All Implemented Interfaces:
ICharacterScanner,ITokenScanner
- Direct Known Subclasses:
BufferedRuleBasedScanner
A generic scanner which can be "programmed" with a sequence of rules.
The scanner is used to get the next token by evaluating its rule in sequence until
one is successful. If a rule returns a token which is undefined, the scanner will proceed to
the next rule. Otherwise the token provided by the rule will be returned by
the scanner. If no rule returned a defined token, this scanner returns a token
which returns
true when calling isOther, unless the end
of the file is reached. In this case the token returns true when calling
isEOF.
Originally since unknown version, but moved to org.eclipse.text in 3.14- Since:
- 3.14
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe cached column of the current scanner positionprotected ITokenThe token to be returned by default if no rule firesprotected char[][]The cached legal line delimiters of the documentprotected IDocumentThe document to be scannedprotected intThe offset of the next character to be readprotected intThe end offset of the range to be scannedprotected IRule[]The list of rules of this scannerprotected intThe offset of the last read tokenprotected static final intInternal setting for the un-initialized column cache.Fields inherited from interface org.eclipse.jface.text.rules.ICharacterScanner
EOF -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new rule based scanner which does not have any rule. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the column of the character scanner.char[][]Provides rules access to the legal line delimiters.intReturns the length of the last token read by this scanner.intReturns the offset of the last token read by this scanner.Returns the next token in the document.intread()Returns the next character or EOF if end of file has been reachedvoidsetDefaultReturnToken(IToken defaultReturnToken) Configures the scanner's default return token.voidConfigures the scanner by providing access to the document range that should be scanned.voidConfigures the scanner with the given sequence of rules.voidunread()Rewinds the scanner before the last read character.
-
Field Details
-
fRules
The list of rules of this scanner -
fDefaultReturnToken
The token to be returned by default if no rule fires -
fDocument
The document to be scanned -
fDelimiters
protected char[][] fDelimitersThe cached legal line delimiters of the document -
fOffset
protected int fOffsetThe offset of the next character to be read -
fRangeEnd
protected int fRangeEndThe end offset of the range to be scanned -
fTokenOffset
protected int fTokenOffsetThe offset of the last read token -
fColumn
protected int fColumnThe cached column of the current scanner position -
UNDEFINED
protected static final int UNDEFINEDInternal setting for the un-initialized column cache.- See Also:
-
-
Constructor Details
-
RuleBasedScanner
public RuleBasedScanner()Creates a new rule based scanner which does not have any rule.
-
-
Method Details
-
setRules
Configures the scanner with the given sequence of rules.- Parameters:
rules- the sequence of rules controlling this scanner
-
setDefaultReturnToken
Configures the scanner's default return token. This is the token which is returned when none of the rules fired and EOF has not been reached.- Parameters:
defaultReturnToken- the default return token- Since:
- 2.0
-
setRange
Description copied from interface:ITokenScannerConfigures the scanner by providing access to the document range that should be scanned.- Specified by:
setRangein interfaceITokenScanner- Parameters:
document- the document to scanoffset- the offset of the document range to scanlength- the length of the document range to scan
-
getTokenOffset
public int getTokenOffset()Description copied from interface:ITokenScannerReturns the offset of the last token read by this scanner.- Specified by:
getTokenOffsetin interfaceITokenScanner- Returns:
- the offset of the last token read by this scanner
-
getTokenLength
public int getTokenLength()Description copied from interface:ITokenScannerReturns the length of the last token read by this scanner.- Specified by:
getTokenLengthin interfaceITokenScanner- Returns:
- the length of the last token read by this scanner
-
getColumn
public int getColumn()Description copied from interface:ICharacterScannerReturns the column of the character scanner.- Specified by:
getColumnin interfaceICharacterScanner- Returns:
- the column of the character scanner
-
getLegalLineDelimiters
public char[][] getLegalLineDelimiters()Description copied from interface:ICharacterScannerProvides rules access to the legal line delimiters. The returned object may not be modified by clients.- Specified by:
getLegalLineDelimitersin interfaceICharacterScanner- Returns:
- the legal line delimiters
-
nextToken
Description copied from interface:ITokenScannerReturns the next token in the document.- Specified by:
nextTokenin interfaceITokenScanner- Returns:
- the next token in the document
-
read
public int read()Description copied from interface:ICharacterScannerReturns the next character or EOF if end of file has been reached- Specified by:
readin interfaceICharacterScanner- Returns:
- the next character or EOF
-
unread
public void unread()Description copied from interface:ICharacterScannerRewinds the scanner before the last read character.- Specified by:
unreadin interfaceICharacterScanner
-