mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Return Option<Parse<ast::Literal>>
from ast::Literal::parse
This commit is contained in:
parent
1918f9b9e0
commit
4923b8a74b
3 changed files with 11 additions and 8 deletions
|
@ -71,7 +71,7 @@ impl server::FreeFunctions for RaSpanServer {
|
|||
&mut self,
|
||||
s: &str,
|
||||
) -> Result<bridge::Literal<Self::Span, Self::Symbol>, ()> {
|
||||
let literal = ast::Literal::parse(s);
|
||||
let literal = ast::Literal::parse(s).ok_or(())?;
|
||||
let literal = literal.tree();
|
||||
|
||||
let kind = literal_to_external(literal.kind()).ok_or(())?;
|
||||
|
|
|
@ -63,7 +63,7 @@ impl server::FreeFunctions for TokenIdServer {
|
|||
&mut self,
|
||||
s: &str,
|
||||
) -> Result<bridge::Literal<Self::Span, Self::Symbol>, ()> {
|
||||
let literal = ast::Literal::parse(s);
|
||||
let literal = ast::Literal::parse(s).ok_or(())?;
|
||||
let literal = literal.tree();
|
||||
|
||||
let kind = literal_to_external(literal.kind()).ok_or(())?;
|
||||
|
|
|
@ -188,7 +188,7 @@ impl SourceFile {
|
|||
}
|
||||
|
||||
impl ast::Literal {
|
||||
pub fn parse(text: &str) -> Parse<ast::Literal> {
|
||||
pub fn parse(text: &str) -> Option<Parse<ast::Literal>> {
|
||||
let lexed = parser::LexedStr::new(text);
|
||||
let parser_input = lexed.to_input();
|
||||
let parser_output = parser::TopEntryPoint::Expr.parse(&parser_input);
|
||||
|
@ -197,11 +197,14 @@ impl ast::Literal {
|
|||
|
||||
errors.extend(validation::validate(&root));
|
||||
|
||||
assert_eq!(root.kind(), SyntaxKind::LITERAL);
|
||||
Parse {
|
||||
green,
|
||||
errors: if errors.is_empty() { None } else { Some(errors.into()) },
|
||||
_ty: PhantomData,
|
||||
if root.kind() == SyntaxKind::LITERAL {
|
||||
Some(Parse {
|
||||
green,
|
||||
errors: if errors.is_empty() { None } else { Some(errors.into()) },
|
||||
_ty: PhantomData,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue