harper_core/expr/
step.rs

1use crate::{LSend, Token, patterns::Pattern};
2
3/// An atomic step within a larger expression.
4///
5/// Its principle job is to identify (if any) the next position of the cursor.
6/// When cursor is moved, all tokens between the current cursor and the target position will be
7/// added to the match group.
8pub trait Step: LSend {
9    fn step(&self, tokens: &[Token], cursor: usize, source: &[char]) -> Option<isize>;
10}
11
12impl<P> Step for P
13where
14    P: Pattern,
15{
16    fn step(&self, tokens: &[Token], cursor: usize, source: &[char]) -> Option<isize> {
17        self.matches(&tokens[cursor..], source).map(|i| i as isize)
18    }
19}