Class WordPatternRule

  • All Implemented Interfaces:
    IPredicateRule, IRule

    public class WordPatternRule
    extends SingleLineRule
    A specific single line rule which stipulates that the start and end sequence occur within a single word, as defined by a word detector.
    See Also:
    IWordDetector
    • Field Detail

      • fDetector

        protected IWordDetector fDetector
        The word detector used by this rule
    • Constructor Detail

      • WordPatternRule

        public WordPatternRule​(IWordDetector detector,
                               String startSequence,
                               String endSequence,
                               IToken token)
        Creates a rule for the given starting and ending word pattern which, if detected, will return the specified token. A word detector is used to identify words.
        Parameters:
        detector - the word detector to be used
        startSequence - the start sequence of the word pattern
        endSequence - the end sequence of the word pattern
        token - the token to be returned on success
      • WordPatternRule

        public WordPatternRule​(IWordDetector detector,
                               String startSequence,
                               String endSequence,
                               IToken token,
                               char escapeCharacter)
        /** Creates a rule for the given starting and ending word pattern which, if detected, will return the specified token. A word detector is used to identify words. Any character which follows the given escapeCharacter will be ignored.
        Parameters:
        detector - the word detector to be used
        startSequence - the start sequence of the word pattern
        endSequence - the end sequence of the word pattern
        token - the token to be returned on success
        escapeCharacter - the escape character
    • Method Detail

      • endSequenceDetected

        protected boolean endSequenceDetected​(ICharacterScanner scanner)
        Returns whether the end sequence was detected. The rule acquires the rest of the word, using the provided word detector, and tests to determine if it ends with the end sequence.
        Overrides:
        endSequenceDetected in class PatternRule
        Parameters:
        scanner - the scanner to be used
        Returns:
        true if the word ends on the given end sequence
      • unreadBuffer

        protected void unreadBuffer​(ICharacterScanner scanner)
        Returns the characters in the buffer to the scanner. Note that the rule must also return the characters read in as part of the start sequence expect the first one.
        Parameters:
        scanner - the scanner to be used