mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Parse integer / float types
This commit is contained in:
parent
3ac605e687
commit
3899898d75
4 changed files with 58 additions and 4 deletions
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use ra_db::LocalSyntaxPtr;
|
use ra_db::LocalSyntaxPtr;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
TextRange, TextUnit,
|
TextRange, TextUnit, SmolStr,
|
||||||
algo::visit::{visitor, Visitor},
|
algo::visit::{visitor, Visitor},
|
||||||
ast::{self, AstNode, DocCommentsOwner, NameOwner, LoopBodyOwner, ArgListOwner},
|
ast::{self, AstNode, DocCommentsOwner, NameOwner, LoopBodyOwner, ArgListOwner},
|
||||||
SyntaxNodeRef
|
SyntaxNodeRef
|
||||||
|
@ -148,7 +148,25 @@ impl Ty {
|
||||||
ParenType(_inner) => Ty::Unknown, // TODO
|
ParenType(_inner) => Ty::Unknown, // TODO
|
||||||
TupleType(_inner) => Ty::Unknown, // TODO
|
TupleType(_inner) => Ty::Unknown, // TODO
|
||||||
NeverType(..) => Ty::Never,
|
NeverType(..) => Ty::Never,
|
||||||
PathType(_inner) => Ty::Unknown, // TODO
|
PathType(inner) => {
|
||||||
|
let path = if let Some(p) = inner.path() { p } else { return Ty::Unknown };
|
||||||
|
if path.qualifier().is_none() {
|
||||||
|
let name = path.segment().and_then(|s| s.name_ref()).map(|n| n.text()).unwrap_or(SmolStr::new(""));
|
||||||
|
if let Some(int_ty) = primitive::IntTy::from_string(&name) {
|
||||||
|
Ty::Int(int_ty)
|
||||||
|
} else if let Some(uint_ty) = primitive::UintTy::from_string(&name) {
|
||||||
|
Ty::Uint(uint_ty)
|
||||||
|
} else if let Some(float_ty) = primitive::FloatTy::from_string(&name) {
|
||||||
|
Ty::Float(float_ty)
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
Ty::Unknown
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
Ty::Unknown
|
||||||
|
}
|
||||||
|
},
|
||||||
PointerType(_inner) => Ty::Unknown, // TODO
|
PointerType(_inner) => Ty::Unknown, // TODO
|
||||||
ArrayType(_inner) => Ty::Unknown, // TODO
|
ArrayType(_inner) => Ty::Unknown, // TODO
|
||||||
SliceType(_inner) => Ty::Unknown, // TODO
|
SliceType(_inner) => Ty::Unknown, // TODO
|
||||||
|
|
|
@ -33,6 +33,18 @@ impl IntTy {
|
||||||
IntTy::I128 => "i128",
|
IntTy::I128 => "i128",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_string(s: &str) -> Option<IntTy> {
|
||||||
|
match s {
|
||||||
|
"isize" => Some(IntTy::Isize),
|
||||||
|
"i8" => Some(IntTy::I8),
|
||||||
|
"i16" => Some(IntTy::I16),
|
||||||
|
"i32" => Some(IntTy::I32),
|
||||||
|
"i64" => Some(IntTy::I64),
|
||||||
|
"i128" => Some(IntTy::I128),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
|
||||||
|
@ -56,6 +68,18 @@ impl UintTy {
|
||||||
UintTy::U128 => "u128",
|
UintTy::U128 => "u128",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_string(s: &str) -> Option<UintTy> {
|
||||||
|
match s {
|
||||||
|
"usize" => Some(UintTy::Usize),
|
||||||
|
"u8" => Some(UintTy::U8),
|
||||||
|
"u16" => Some(UintTy::U16),
|
||||||
|
"u32" => Some(UintTy::U32),
|
||||||
|
"u64" => Some(UintTy::U64),
|
||||||
|
"u128" => Some(UintTy::U128),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for UintTy {
|
impl fmt::Debug for UintTy {
|
||||||
|
@ -95,4 +119,12 @@ impl FloatTy {
|
||||||
FloatTy::F64 => "f64",
|
FloatTy::F64 => "f64",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_string(s: &str) -> Option<FloatTy> {
|
||||||
|
match s {
|
||||||
|
"f32" => Some(FloatTy::F32),
|
||||||
|
"f64" => Some(FloatTy::F64),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2697,7 +2697,11 @@ impl<R: TreeRoot<RaTypes>> PathTypeNode<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<'a> PathType<'a> {}
|
impl<'a> PathType<'a> {
|
||||||
|
pub fn path(self) -> Option<Path<'a>> {
|
||||||
|
super::child_opt(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PlaceholderPat
|
// PlaceholderPat
|
||||||
#[derive(Debug, Clone, Copy,)]
|
#[derive(Debug, Clone, Copy,)]
|
||||||
|
|
|
@ -304,7 +304,7 @@ Grammar(
|
||||||
"ParenType": (),
|
"ParenType": (),
|
||||||
"TupleType": (),
|
"TupleType": (),
|
||||||
"NeverType": (),
|
"NeverType": (),
|
||||||
"PathType": (),
|
"PathType": (options: ["Path"]),
|
||||||
"PointerType": (),
|
"PointerType": (),
|
||||||
"ArrayType": (),
|
"ArrayType": (),
|
||||||
"SliceType": (),
|
"SliceType": (),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue