1 / 20

Eclipse API

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 .

ferris
Download Presentation

Eclipse API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Eclipse API org.eclipse.jface.text.rules Cheng-Chia Chen

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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

  9. 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[].

  10. client next_token() ITokenScanner IToken rules unread() read() ICharacterScanner

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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.

  16. 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.

  17. 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

  18. 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

  19. PatternRule (implements IPredicteRule ) • MultiLineRule • SingleLineRule 1. EndOfLineRule 2. WordPatternRule

  20. Scanners • RuleBAsedScanner • BufferedRuleBasedScanner • RuleBasedPartitionScanner

More Related