• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Things which exist to solve practical issues, but which shouldn't exist.
2 //!
3 //! Please avoid adding new usages of the functions in this module
4 
5 use crate::{ast, AstNode};
6 
parse_expr_from_str(s: &str) -> Option<ast::Expr>7 pub fn parse_expr_from_str(s: &str) -> Option<ast::Expr> {
8     let s = s.trim();
9     let file = ast::SourceFile::parse(&format!("const _: () = {s};"));
10     let expr = file.syntax_node().descendants().find_map(ast::Expr::cast)?;
11     if expr.syntax().text() != s {
12         return None;
13     }
14     Some(expr)
15 }
16