2022-08-17 08:44:58 -05:00
|
|
|
//! Things which exist to solve practical issues, but which shouldn't exist.
|
2021-12-28 09:57:13 -06:00
|
|
|
//!
|
|
|
|
//! Please avoid adding new usages of the functions in this module
|
|
|
|
|
|
|
|
use crate::{ast, AstNode};
|
|
|
|
|
|
|
|
pub fn parse_expr_from_str(s: &str) -> Option<ast::Expr> {
|
2021-12-28 10:13:30 -06:00
|
|
|
let s = s.trim();
|
2022-12-23 12:42:58 -06:00
|
|
|
let file = ast::SourceFile::parse(&format!("const _: () = {s};"));
|
2021-12-28 09:57:13 -06:00
|
|
|
let expr = file.syntax_node().descendants().find_map(ast::Expr::cast)?;
|
|
|
|
if expr.syntax().text() != s {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
Some(expr)
|
|
|
|
}
|