]> git.lizzy.rs Git - rust.git/commit
Merge #1328
authorbors[bot] <bors[bot]@users.noreply.github.com>
Mon, 27 May 2019 07:28:13 +0000 (07:28 +0000)
committerbors[bot] <bors[bot]@users.noreply.github.com>
Mon, 27 May 2019 07:28:13 +0000 (07:28 +0000)
commitce694ae11854a806031db98c51c068253f927519
tree2996ecd85ff9aa57b6f208e83d42dd03a7370d1e
parent4f4e50db908ba44f113faeb356ae2b3d0788d308
parent90764fc54b2be1e0fc5d6ac9c9e960d7bb059b14
Merge #1328

1328: Change TokenSource to iteration based r=matklad a=edwin0cheng

This PR change the `TokenSource` trait from random access to be an iteration based trait:
```rust

/// `TokenSource` abstracts the source of the tokens parser operates one.
///
/// Hopefully this will allow us to treat text and token trees in the same way!
pub trait TokenSource {
    fn current(&self) -> Token;

    /// Lookahead n token
    fn lookahead_nth(&self, n: usize) -> Token;

    /// bump cursor to next token
    fn bump(&mut self);

    /// Is the current token a specified keyword?
    fn is_keyword(&self, kw: &str) -> bool;
}

/// `TokenCursor` abstracts the cursor of `TokenSource` operates one.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Token {
    /// What is the current token?
    pub kind: SyntaxKind,

    /// Is the current token joined to the next one (`> >` vs `>>`).
    pub is_jointed_to_next: bool,
}
```

Note that the refactoring based on this new trait will be separated to incoming PRs

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>