200 likes | 324 Views
Eclipse API. org.eclipse.jface.text.rules. Cheng-Chia Chen. Package Description. Provides a framework for rule based text scanning and uses the framework to provide rule-driven default implementations of IPresentationDamager, IPresentationRepairer and IDocumentPartitioner .
E N D
Eclipse API org.eclipse.jface.text.rules Cheng-Chia Chen
Package Description • Provides a framework for rule based text scanning and uses the framework to provide rule-driven default implementations of IPresentationDamager, IPresentationRepairer and IDocumentPartitioner. • RuleBasedScanner is a document-based scanner controlled by IRule objects. When evaluated an IRule always returns an IToken. • The package provides a set of rules whereby PatternRule is the most important one. PatternRule defines a pattern-configurable rule.
Interface Summary • ICharacterScanner • Defines the interface of a character scanner used by rules. • IPartitionTokenScanner • A partition token scanner returns tokens that represent partitions. • IPredicateRule • Defines the interface for a rule used in the scanning of text for the purpose of document partitioning or text styling. • IRule • Defines the interface for a rule used in the scanning of text for the purpose of document partitioning or text styling.
Interface Summary • IToken • A token to be returned by a rule. • ITokenScanner • A token scanner scans a range of a document and reports about the token it finds. • IWhitespaceDetector • Defines the interface by which WhitespaceRule determines whether a given character is to be considered whitespace in the current context. • IWordDetector • Defines the interface by which WordRule determines whether a given character is valid as part of a word in the current context.
IToken • A token to be returned by a rule • Object getData() • Return a data attached to this token. The semantics of this data kept undefined by this interface. • boolean isEOF() • Return whether this token represents End Of File. • booleanisOther() • Return whether this token is neither undefined, nor whitespace, nor EOF. • booleanisUndefined() • Return whether this token is undefined. • boolean isWhitespace() • Return whether this token represents a whitespace.
ITokenScanner • A token scanner scans a range of a document and reports about the token it finds. • A scanner has state. • When asked, the scanner returns the offset and the length of the last found token.
ITokenScannerMethod Summary • int getTokenLength() • Returns the length of the last token read by this scanner. • int getTokenOffset() • Returns the offset of the last token read by this scanner. • IToken nextToken() • Returns the next token in the document. • void setRange(IDocumentdocument, intoffset, intlength) • Configures the scanner by providing access to the document range that should be scanned.
ICharacterScanner • Defines the interface of a character scanner used by rules. • Rules may request the next character or ask the character scanner to unread(pushback) the last read character. • public final int EOF = -1; • implementing classes: • RuleBasedScanner
Method Summary • int getColumn() • Returns the column of the character scanner. • int read() • Returns the next character or EOF if end of file has been reached • void unread() • Rewinds the scanner before the last read character. • char[][] getLegalLineDelimiters() • Provides rules access to the legal line delimiters. Converted from Strnig[].
client next_token() ITokenScanner IToken rules unread() read() ICharacterScanner
IRule • Defines the interface for a rule used in the scanning of text for the purpose of document partitioning or text styling. Methods : • public IToken evaluate (ICharacterScanner) • Evaluates the rule by examining the characters available from the provided character scanner. • if text in cs not matching => evaluate(cs).isUndefined()returns true.
IPredicateRule • extends IRule • A predicate rule can only return one single token after having successfully detected content. • This token is called success token. Also, it can return a token indicating that this rule has not been successful.
Method Summary • IToken evaluate (ICharacterScannersc, booleanresume) • match => return the success token • not match => return a undefinedToken. • 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 closingsequence. In this case, resume must be set to true. • IToken getSuccessToken() • Returns the success token of this predicate rule.
IWordDetector • Defines the interface by which WordRule determines whether a given character is valid as part of a word in the current context. Method Summary • boolean isWordPart(charc) • Returns whether c is valid as a subsequent character in a word. • boolean isWordStart(charc) • Returns whether c is valid as the first character in a word.
IWhitespaceDetector • Defines the interface by which WhitespaceRule determines whether a given character is to be considered whitespace in the current context. Method Summary • boolean isWhitespace(charc) • Returns whether c is whitespace.
IPartitionTokenScanner • ITokenScanner • returns tokens that represent partitions. • For that reason, a partition token scanner is vulnerable in respect to the document offset it starts scanning. • In a simple case, a partition token scanner must always start at a partition boundary. • can also start in the middle of a partition, if it knows the type of the partition.
Method Sumamry • public void setPartialRange (IDocumentdocument, intoffset, intlength, StringcontentType, intpartitionOffset) • The range may not only contain complete partitions but starts at the beginning of a line in the middle of a partition of the given content type. • This requires that a partition delimiter can not contain a line delimiter. Parameters: • contentType - the content type at the given offset • partitionOffset - the offset at which the partition of the given offset starts
Classes Summary IRule implementations • WordRule • for detecting detecting words • also allow for the association of tokens with specific words. • WhitespaceRule • for detecting whitespace • NumberRule • for detecting numeric number. • PatternRule IPredicatRule • standard implementation of IPredicatRule
PatternRule (implements IPredicteRule ) • MultiLineRule • SingleLineRule 1. EndOfLineRule 2. WordPatternRule
Scanners • RuleBAsedScanner • BufferedRuleBasedScanner • RuleBasedPartitionScanner