Skip to content

Commit

Permalink
Simplify is_ident function (#104)
Browse files Browse the repository at this point in the history
It's a way over-complicated
  • Loading branch information
CreepySkeleton authored and dtolnay committed May 24, 2019
1 parent 57038ba commit a5227da
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/runtime.rs
Expand Up @@ -10,21 +10,10 @@ fn is_ident_continue(c: u8) -> bool {
}

fn is_ident(token: &str) -> bool {
if token.bytes().all(|digit| digit >= b'0' && digit <= b'9') {
return false;
}

let mut bytes = token.bytes();
let first = bytes.next().unwrap();
if !is_ident_start(first) {
return false;
}
for ch in bytes {
if !is_ident_continue(ch) {
return false;
}
}
true
let mut iter = token.bytes();
let first_ok = iter.next().map(is_ident_start).unwrap_or(false);

first_ok && iter.all(is_ident_continue)
}

pub fn parse(tokens: &mut TokenStream, span: Span, s: &str) {
Expand Down

0 comments on commit a5227da

Please sign in to comment.