apply T! macro where it is possible

This commit is contained in:
Sergey Parilin 2019-05-15 15:35:47 +03:00
parent d77175ce28
commit 993abedd77
38 changed files with 619 additions and 623 deletions

View file

@ -7,6 +7,7 @@ mod strings;
use crate::{
SyntaxKind::{self, *},
TextUnit,
T,
};
use self::{
@ -90,16 +91,16 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
match c {
// Possiblily multi-byte tokens,
// but we only produce single byte token now
// DOTDOTDOT, DOTDOT, DOTDOTEQ, DOT
'.' => return DOT,
// COLONCOLON COLON
':' => return COLON,
// EQEQ FATARROW EQ
'=' => return EQ,
// NEQ EXCL
'!' => return EXCL,
// THIN_ARROW MINUS
'-' => return MINUS,
// T![...], T![..], T![..=], T![.]
'.' => return T![.],
// T![::] T![:]
':' => return T![:],
// T![==] FATARROW T![=]
'=' => return T![=],
// T![!=] T![!]
'!' => return T![!],
// T![->] T![-]
'-' => return T![-],
// If the character is an ident start not followed by another single
// quote, then this is a lifetime name:
@ -148,8 +149,8 @@ fn scan_ident(c: char, ptr: &mut Ptr) -> SyntaxKind {
ptr.bump();
true
}
('_', None) => return UNDERSCORE,
('_', Some(c)) if !is_ident_continue(c) => return UNDERSCORE,
('_', None) => return T![_],
('_', Some(c)) if !is_ident_continue(c) => return T![_],
_ => false,
};
ptr.bump_while(is_ident_continue);

View file

@ -17,7 +17,8 @@ use crate::{
text_token_source::TextTokenSource,
text_tree_sink::TextTreeSink,
lexer::{tokenize, Token},
}
},
T,
};
pub(crate) fn incremental_reparse(
@ -122,16 +123,16 @@ fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxN
fn is_balanced(tokens: &[Token]) -> bool {
if tokens.is_empty()
|| tokens.first().unwrap().kind != L_CURLY
|| tokens.last().unwrap().kind != R_CURLY
|| tokens.first().unwrap().kind != T!['{']
|| tokens.last().unwrap().kind != T!['}']
{
return false;
}
let mut balance = 0usize;
for t in &tokens[1..tokens.len() - 1] {
match t.kind {
L_CURLY => balance += 1,
R_CURLY => {
T!['{'] => balance += 1,
T!['}'] => {
balance = match balance.checked_sub(1) {
Some(b) => b,
None => return false,