move abstract traits to top

This commit is contained in:
Aleksey Kladov
2019-02-20 22:19:12 +03:00
parent d2bce118ae
commit 2b5e336ce7
4 changed files with 59 additions and 65 deletions

View File

@@ -1,22 +1,21 @@
use crate::{
SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
parsing::{
TokenPos,
parser_impl::TokenSource,
lexer::Token,
},
};
use std::ops::{Add, AddAssign};
impl<'t> TokenSource for ParserInput<'t> {
fn token_kind(&self, pos: InputPosition) -> SyntaxKind {
fn token_kind(&self, pos: TokenPos) -> SyntaxKind {
let idx = pos.0 as usize;
if !(idx < self.tokens.len()) {
return EOF;
}
self.tokens[idx].kind
}
fn is_token_joint_to_next(&self, pos: InputPosition) -> bool {
fn is_token_joint_to_next(&self, pos: TokenPos) -> bool {
let idx_curr = pos.0 as usize;
let idx_next = pos.0 as usize;
if !(idx_next < self.tokens.len()) {
@@ -24,7 +23,7 @@ impl<'t> TokenSource for ParserInput<'t> {
}
self.start_offsets[idx_curr] + self.tokens[idx_curr].len == self.start_offsets[idx_next]
}
fn is_keyword(&self, pos: InputPosition, kw: &str) -> bool {
fn is_keyword(&self, pos: TokenPos, kw: &str) -> bool {
let idx = pos.0 as usize;
if !(idx < self.tokens.len()) {
return false;
@@ -72,26 +71,3 @@ impl<'t> ParserInput<'t> {
ParserInput { text, start_offsets, tokens }
}
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub(crate) struct InputPosition(u32);
impl InputPosition {
pub fn new() -> Self {
InputPosition(0)
}
}
impl Add<u32> for InputPosition {
type Output = InputPosition;
fn add(self, rhs: u32) -> InputPosition {
InputPosition(self.0 + rhs)
}
}
impl AddAssign<u32> for InputPosition {
fn add_assign(&mut self, rhs: u32) {
self.0 += rhs
}
}