diff --git a/crates/snforge-scarb-plugin/src/parse.rs b/crates/snforge-scarb-plugin/src/parse.rs index 08dde7920a..e602941bf4 100644 --- a/crates/snforge-scarb-plugin/src/parse.rs +++ b/crates/snforge-scarb-plugin/src/parse.rs @@ -1,33 +1,24 @@ use crate::attributes::{AttributeInfo, ErrorExt}; -use cairo_lang_diagnostics::DiagnosticsBuilder; -use cairo_lang_filesystem::ids::{FileKind, FileLongId, VirtualFile}; use cairo_lang_macro::Diagnostic; -use cairo_lang_parser::{parser::Parser, utils::SimpleParserDatabase}; +use cairo_lang_parser::utils::SimpleParserDatabase; +use cairo_lang_syntax::node::ast::SyntaxFile; use cairo_lang_syntax::node::{ ast::{FunctionWithBody, ModuleItem, OptionArgListParenthesized}, db::SyntaxGroup, helpers::QueryAttrs, + TypedSyntaxNode, }; use cairo_lang_utils::Upcast; use indoc::formatdoc; -use std::sync::Arc; pub fn parse( code: &str, ) -> Result<(SimpleParserDatabase, FunctionWithBody), Diagnostic> { let simple_db = SimpleParserDatabase::default(); - let code = Arc::new(code.to_string()); + let (parsed_node, _diagnostics) = simple_db.parse_virtual_with_diagnostics(code); + let db: &dyn SyntaxGroup = simple_db.upcast(); - // TODO(#2357): Use `db.parse_virtual` here instead of creating the virtual file manually - let virtual_file = db.intern_file(FileLongId::Virtual(VirtualFile { - parent: None, - name: "test_function".into(), - content: Arc::from(code.as_str()), - code_mappings: Default::default(), - kind: FileKind::Module, - })); - let mut diagnostics = DiagnosticsBuilder::default(); - let elements = Parser::parse_file(&simple_db, &mut diagnostics, virtual_file, code.as_str()) + let elements = SyntaxFile::from_syntax_node(db, parsed_node) .items(db) .elements(db);