mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +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,
|
&mut self,
|
||||||
s: &str,
|
s: &str,
|
||||||
) -> Result<bridge::Literal<Self::Span, Self::Symbol>, ()> {
|
) -> 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 literal = literal.tree();
|
||||||
|
|
||||||
let kind = literal_to_external(literal.kind()).ok_or(())?;
|
let kind = literal_to_external(literal.kind()).ok_or(())?;
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl server::FreeFunctions for TokenIdServer {
|
||||||
&mut self,
|
&mut self,
|
||||||
s: &str,
|
s: &str,
|
||||||
) -> Result<bridge::Literal<Self::Span, Self::Symbol>, ()> {
|
) -> 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 literal = literal.tree();
|
||||||
|
|
||||||
let kind = literal_to_external(literal.kind()).ok_or(())?;
|
let kind = literal_to_external(literal.kind()).ok_or(())?;
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl SourceFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ast::Literal {
|
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 lexed = parser::LexedStr::new(text);
|
||||||
let parser_input = lexed.to_input();
|
let parser_input = lexed.to_input();
|
||||||
let parser_output = parser::TopEntryPoint::Expr.parse(&parser_input);
|
let parser_output = parser::TopEntryPoint::Expr.parse(&parser_input);
|
||||||
|
@ -197,11 +197,14 @@ impl ast::Literal {
|
||||||
|
|
||||||
errors.extend(validation::validate(&root));
|
errors.extend(validation::validate(&root));
|
||||||
|
|
||||||
assert_eq!(root.kind(), SyntaxKind::LITERAL);
|
if root.kind() == SyntaxKind::LITERAL {
|
||||||
Parse {
|
Some(Parse {
|
||||||
green,
|
green,
|
||||||
errors: if errors.is_empty() { None } else { Some(errors.into()) },
|
errors: if errors.is_empty() { None } else { Some(errors.into()) },
|
||||||
_ty: PhantomData,
|
_ty: PhantomData,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue