public class PatternRule extends Object implements IPredicateRule
IPredicateRule
.
Is is capable of detecting a pattern which begins with a given start
sequence and ends with a given end sequence. If the end sequence is
not specified, it can be either end of line, end or file, or both. Additionally,
the pattern can be constrained to begin in a certain column. The rule can also
be used to check whether the text to scan covers half of the pattern, i.e. contains
the end sequence required by the rule.Modifier and Type | Field and Description |
---|---|
protected boolean |
fBreaksOnEOF
Indicates whether end of file terminates the pattern
|
protected boolean |
fBreaksOnEOL
Indicates whether end of line terminates the pattern
|
protected int |
fColumn
The pattern's column constrain
|
protected char[] |
fEndSequence
The pattern's end sequence
|
protected char |
fEscapeCharacter
The pattern's escape character
|
protected boolean |
fEscapeContinuesLine
Indicates whether the escape character continues a line
|
protected char[] |
fStartSequence
The pattern's start sequence
|
protected IToken |
fToken
The token to be returned on success
|
protected static int |
UNDEFINED
Internal setting for the un-initialized column constraint
|
Constructor and Description |
---|
PatternRule(String startSequence,
String endSequence,
IToken token,
char escapeCharacter,
boolean breaksOnEOL)
Creates a rule for the given starting and ending sequence.
|
PatternRule(String startSequence,
String endSequence,
IToken token,
char escapeCharacter,
boolean breaksOnEOL,
boolean breaksOnEOF)
Creates a rule for the given starting and ending sequence.
|
PatternRule(String startSequence,
String endSequence,
IToken token,
char escapeCharacter,
boolean breaksOnEOL,
boolean breaksOnEOF,
boolean escapeContinuesLine)
Creates a rule for the given starting and ending sequence.
|
Modifier and Type | Method and Description |
---|---|
protected IToken |
doEvaluate(ICharacterScanner scanner)
Evaluates this rules without considering any column constraints.
|
protected IToken |
doEvaluate(ICharacterScanner scanner,
boolean resume)
Evaluates this rules without considering any column constraints.
|
protected boolean |
endSequenceDetected(ICharacterScanner scanner)
Returns whether the end sequence was detected.
|
IToken |
evaluate(ICharacterScanner scanner)
Evaluates the rule by examining the characters available from the provided character scanner.
|
IToken |
evaluate(ICharacterScanner scanner,
boolean resume)
Evaluates the rule by examining the characters available from
the provided character scanner.
|
IToken |
getSuccessToken()
Returns the success token of this predicate rule.
|
protected boolean |
sequenceDetected(ICharacterScanner scanner,
char[] sequence,
boolean eofAllowed)
Returns whether the next characters to be read by the character scanner
are an exact match with the given sequence.
|
void |
setColumnConstraint(int column)
Sets a column constraint for this rule.
|
protected static final int UNDEFINED
protected IToken fToken
protected char[] fStartSequence
protected char[] fEndSequence
protected int fColumn
protected char fEscapeCharacter
protected boolean fEscapeContinuesLine
protected boolean fBreaksOnEOL
protected boolean fBreaksOnEOF
public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL)
startSequence
- the pattern's start sequenceendSequence
- the pattern's end sequence, null
is a legal valuetoken
- the token which will be returned on successescapeCharacter
- any character following this one will be ignoredbreaksOnEOL
- indicates whether the end of the line also terminates the patternpublic PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF)
startSequence
- the pattern's start sequenceendSequence
- the pattern's end sequence, null
is a legal valuetoken
- the token which will be returned on successescapeCharacter
- any character following this one will be ignoredbreaksOnEOL
- indicates whether the end of the line also terminates the patternbreaksOnEOF
- indicates whether the end of the file also terminates the patternpublic PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF, boolean escapeContinuesLine)
lineContinuationCharacter
will not cause the
pattern to terminate even if breakOnEOL
is set to true.startSequence
- the pattern's start sequenceendSequence
- the pattern's end sequence, null
is a legal valuetoken
- the token which will be returned on successescapeCharacter
- any character following this one will be ignoredbreaksOnEOL
- indicates whether the end of the line also terminates the patternbreaksOnEOF
- indicates whether the end of the file also terminates the patternescapeContinuesLine
- indicates whether the specified escape character is used for line
continuation, so that an end of line immediately after the escape character does not
terminate the pattern, even if breakOnEOL
is setpublic void setColumnConstraint(int column)
column
- the column in which the pattern startsprotected IToken doEvaluate(ICharacterScanner scanner)
scanner
- the character scanner to be usedprotected IToken doEvaluate(ICharacterScanner scanner, boolean resume)
resume
flag is set.scanner
- the character scanner to be usedresume
- true
if detection should be resumed, false
otherwisepublic IToken evaluate(ICharacterScanner scanner)
IRule
true
when calling
isUndefined
, if the text that the rule investigated does not match the rule's
requirementsprotected boolean endSequenceDetected(ICharacterScanner scanner)
true
if the
rule breaks on the end of the line, or if the EOF character is read.scanner
- the character scanner to be usedtrue
if the end sequence has been detectedprotected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed)
scanner
- the character scanner to be usedsequence
- the sequence to be detectedeofAllowed
- indicated whether EOF terminates the patterntrue
if the given sequence has been detectedpublic IToken evaluate(ICharacterScanner scanner, boolean resume)
IPredicateRule
true
when calling isUndefined
,
if the text that the rule investigated does not match the rule's requirements. Otherwise,
this method returns this rule's success token. If this rules relies on a text pattern
comprising a opening and a closing character sequence this method can also be called
when the scanner is positioned already between the opening and the closing sequence.
In this case, resume
must be set to true
.evaluate
in interface IPredicateRule
scanner
- the character scanner to be used by this ruleresume
- indicates that the rule starts working between the opening and the closing character sequencepublic IToken getSuccessToken()
IPredicateRule
getSuccessToken
in interface IPredicateRule
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.