Skip to main content

oak_python/builder/
build_root.rs

1use crate::{
2    ast::{Program, PythonRoot},
3    language::PythonLanguage,
4};
5use oak_core::{GreenNode, OakError, SourceText};
6
7impl<'config> super::PythonBuilder<'config> {
8    /// Builds a Python root from a green tree.
9    pub fn build_root(&self, green_tree: &GreenNode<PythonLanguage>, source: &SourceText) -> Result<PythonRoot, OakError> {
10        let statements = self.build_statement_list(green_tree.children(), 0, source)?;
11        Ok(PythonRoot { program: Program { statements }, span: (0..green_tree.text_len() as usize).into() })
12    }
13}