ExprLinter

Trait ExprLinter 

Source
pub trait ExprLinter: LSend {
    type Unit: DocumentIterator;

    // Required methods
    fn expr(&self) -> &dyn Expr;
    fn description(&self) -> &str;

    // Provided methods
    fn match_to_lint(
        &self,
        matched_tokens: &[Token],
        source: &[char],
    ) -> Option<Lint> { ... }
    fn match_to_lint_with_context(
        &self,
        matched_tokens: &[Token],
        source: &[char],
        _context: Option<(&[Token], &[Token])>,
    ) -> Option<Lint> { ... }
}
Expand description

A trait that searches for tokens that fulfil Exprs in a Document.

Makes use of TokenStringExt::iter_chunks by default, or TokenStringExt::iter_sentences to process either a chunk (clause) or a sentence at a time.

Required Associated Types§

Source

type Unit: DocumentIterator

Required Methods§

Source

fn expr(&self) -> &dyn Expr

A simple getter for the expression you want Harper to search for.

Source

fn description(&self) -> &str

A user-facing description of what kinds of grammatical errors this rule looks for. It is usually shown in settings menus.

Provided Methods§

Source

fn match_to_lint( &self, matched_tokens: &[Token], source: &[char], ) -> Option<Lint>

If any portions of a Document match Self::expr, they are passed through ExprLinter::match_to_lint or ExprLinter::match_to_lint_with_context to be transformed into a Lint for editor consumption.

Transform matched tokens into a Lint for editor consumption.

This is the simple version that only sees the matched tokens. For context-aware linting, implement match_to_lint_with_context instead.

Return None to skip producing a lint for this match.

Source

fn match_to_lint_with_context( &self, matched_tokens: &[Token], source: &[char], _context: Option<(&[Token], &[Token])>, ) -> Option<Lint>

Transform matched tokens into a Lint with access to surrounding context.

The context provides access to tokens before and after the match. When implementing this method, you can call self.match_to_lint() as a fallback if the context isn’t needed.

Return None to skip producing a lint for this match.

Implementations on Foreign Types§

Source§

impl<EL: ExprLinter + ?Sized> ExprLinter for Box<EL>

Source§

type Unit = <EL as ExprLinter>::Unit

Source§

fn expr(&self) -> &dyn Expr

Source§

fn match_to_lint( &self, matched_tokens: &[Token], source: &[char], ) -> Option<Lint>

Source§

fn match_to_lint_with_context( &self, matched_tokens: &[Token], source: &[char], _context: Option<(&[Token], &[Token])>, ) -> Option<Lint>

Source§

fn description(&self) -> &str

Implementors§