Refactor Name ready for hygienic macro

This commit is contained in:
uHOOCCOOHu 2019-09-27 02:04:47 +08:00
parent 53a30d9e69
commit 128dc5355b
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
4 changed files with 95 additions and 85 deletions

View file

@ -21,6 +21,16 @@ impl ast::NameRef {
pub fn text(&self) -> &SmolStr {
text_of_first_token(self.syntax())
}
pub fn as_tuple_field(&self) -> Option<usize> {
self.syntax().children_with_tokens().find_map(|c| {
if c.kind() == SyntaxKind::INT_NUMBER {
c.as_token().and_then(|tok| tok.text().as_str().parse().ok())
} else {
None
}
})
}
}
fn text_of_first_token(node: &SyntaxNode) -> &SmolStr {