Package org.eclipse.jface.text.rules
Class PatternRule
java.lang.Object
org.eclipse.jface.text.rules.PatternRule
- All Implemented Interfaces:
IPredicateRule
,IRule
- Direct Known Subclasses:
MultiLineRule
,SingleLineRule
Standard implementation of
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.
Originally since unknown version, but moved to org.eclipse.text in 3.14- Since:
- 3.14
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Indicates whether end of file terminates the patternprotected boolean
Indicates whether end of line terminates the patternprotected int
The pattern's column constrainprotected char[]
The pattern's end sequenceprotected char
The pattern's escape characterprotected boolean
Indicates whether the escape character continues a lineprotected char[]
The pattern's start sequenceprotected IToken
The token to be returned on successprotected static final int
Internal setting for the un-initialized column constraint -
Constructor Summary
ConstructorDescriptionPatternRule
(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. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.evaluate
(ICharacterScanner scanner) Evaluates the rule by examining the characters available from the provided character scanner.evaluate
(ICharacterScanner scanner, boolean resume) Evaluates the rule by examining the characters available from the provided character scanner.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.
-
Field Details
-
UNDEFINED
protected static final int UNDEFINEDInternal setting for the un-initialized column constraint- See Also:
-
fToken
The token to be returned on success -
fStartSequence
protected char[] fStartSequenceThe pattern's start sequence -
fEndSequence
protected char[] fEndSequenceThe pattern's end sequence -
fColumn
protected int fColumnThe pattern's column constrain -
fEscapeCharacter
protected char fEscapeCharacterThe pattern's escape character -
fEscapeContinuesLine
protected boolean fEscapeContinuesLineIndicates whether the escape character continues a line- Since:
- 3.0
-
fBreaksOnEOL
protected boolean fBreaksOnEOLIndicates whether end of line terminates the pattern -
fBreaksOnEOF
protected boolean fBreaksOnEOFIndicates whether end of file terminates the pattern
-
-
Constructor Details
-
PatternRule
public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL) Creates a rule for the given starting and ending sequence. When these sequences are detected the rule will return the specified token. Alternatively, the sequence can also be ended by the end of the line. Any character which follows the given escapeCharacter will be ignored.- Parameters:
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 pattern
-
PatternRule
public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF) Creates a rule for the given starting and ending sequence. When these sequences are detected the rule will return the specified token. Alternatively, the sequence can also be ended by the end of the line or the end of the file. Any character which follows the given escapeCharacter will be ignored.- Parameters:
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 pattern- Since:
- 2.1
-
PatternRule
public 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. When these sequences are detected the rule will return the specified token. Alternatively, the sequence can also be ended by the end of the line or the end of the file. Any character which follows the given escapeCharacter will be ignored. An end of line immediately after the givenlineContinuationCharacter
will not cause the pattern to terminate even ifbreakOnEOL
is set to true.- Parameters:
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 ifbreakOnEOL
is set- Since:
- 3.0
-
-
Method Details
-
setColumnConstraint
public void setColumnConstraint(int column) Sets a column constraint for this rule. If set, the rule's token will only be returned if the pattern is detected starting at the specified column. If the column is smaller then 0, the column constraint is considered removed.- Parameters:
column
- the column in which the pattern starts
-
doEvaluate
Evaluates this rules without considering any column constraints.- Parameters:
scanner
- the character scanner to be used- Returns:
- the token resulting from this evaluation
-
doEvaluate
Evaluates this rules without considering any column constraints. Resumes detection, i.e. look sonly for the end sequence required by this rule if theresume
flag is set.- Parameters:
scanner
- the character scanner to be usedresume
-true
if detection should be resumed,false
otherwise- Returns:
- the token resulting from this evaluation
- Since:
- 2.0
-
evaluate
Description copied from interface:IRule
Evaluates the rule by examining the characters available from the provided character scanner. The token returned by this rule returnstrue
when callingisUndefined
, if the text that the rule investigated does not match the rule's requirements -
endSequenceDetected
Returns whether the end sequence was detected. As the pattern can be considered ended by a line delimiter, the result of this method istrue
if the rule breaks on the end of the line, or if the EOF character is read.- Parameters:
scanner
- the character scanner to be used- Returns:
true
if the end sequence has been detected
-
sequenceDetected
Returns whether the next characters to be read by the character scanner are an exact match with the given sequence. No escape characters are allowed within the sequence. If specified the sequence is considered to be found when reading the EOF character.- Parameters:
scanner
- the character scanner to be usedsequence
- the sequence to be detectedeofAllowed
- indicated whether EOF terminates the pattern- Returns:
true
if the given sequence has been detected
-
evaluate
Description copied from interface:IPredicateRule
Evaluates the rule by examining the characters available from the provided character scanner. The token returned by this rule returnstrue
when callingisUndefined
, 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 totrue
.- Specified by:
evaluate
in interfaceIPredicateRule
- Parameters:
scanner
- the character scanner to be used by this ruleresume
- indicates that the rule starts working between the opening and the closing character sequence- Returns:
- the token computed by the rule
-
getSuccessToken
Description copied from interface:IPredicateRule
Returns the success token of this predicate rule.- Specified by:
getSuccessToken
in interfaceIPredicateRule
- Returns:
- the success token of this rule
-