Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/hacks.rs')
-rw-r--r--crates/syntax/src/hacks.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/syntax/src/hacks.rs b/crates/syntax/src/hacks.rs
new file mode 100644
index 0000000000..112b912ade
--- /dev/null
+++ b/crates/syntax/src/hacks.rs
@@ -0,0 +1,14 @@
+//! Things which exist to solve practial issues, but which shouldn't exist.
+//!
+//! 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> {
+ let file = ast::SourceFile::parse(&format!("const _: () = {};", s));
+ let expr = file.syntax_node().descendants().find_map(ast::Expr::cast)?;
+ if expr.syntax().text() != s {
+ return None;
+ }
+ Some(expr)
+}