1#![warn(missing_docs)]
5
6use oak_core::{Builder, TextEdit, builder::BuildOutput};
7use oak_python::{PythonBuilder, PythonLanguage, ast::PythonRoot};
8
9pub struct RustyPythonFrontend {
11 language: PythonLanguage,
12}
13
14impl Default for RustyPythonFrontend {
15 fn default() -> Self {
16 Self::new()
17 }
18}
19
20impl RustyPythonFrontend {
21 pub fn new() -> Self {
23 Self { language: PythonLanguage::new() }
24 }
25
26 pub fn parse(&self, source: &str) -> Result<PythonRoot, String> {
28 let builder = PythonBuilder::new(&self.language);
29 let edits: &[TextEdit] = &[];
30 let mut cache = oak_core::parser::ParseSession::default();
31 let output: BuildOutput<PythonLanguage> = builder.build(source, edits, &mut cache);
32 output.result.map_err(|e| e.to_string())
33 }
34}