/// Include and compile standard DSPython Arduino libraries
Include and compile standard DSPython Arduino libraries
Include and compile standard DSPython Arduino libraries
pub fn include_stdlib(&mut self) -> CompileResult<()> {
        let libs = read_dir("./arduino/")
            .expect("Failed to load DSPython Arduino core libraries")
            .map(|res| res.map(|entry| entry.path()))
            .collect::<Result<Vec<_>, std::io::Error>>()
            .unwrap();
        for lib in libs.iter() {
            let lib = lib.to_str().unwrap();
            // Skip `__init__.py` which is for linter
            if lib.contains("__init__.py") {
                continue;
            }
            let to_compile_error =
                |parse_error| CompileError::from_parse_error(parse_error, lib.to_string());
            let source =
                read_to_string(&lib).expect(&format!("dspython: can't open file '{}'", lib));
            let module_ast = match parse_program(&source).map_err(to_compile_error) {
                Err(e) => {
                    eprintln!("fatal: Could not include standard libraries");
                    eprintln!(
                        "An unhandled exception occurred during parsing '{}'",
                        std::path::PathBuf::from(&e.source_path)
                            .canonicalize()
                            .unwrap()
                            .display()
                    );
                    panic!("ParseError: {}", e);
                }
                Ok(module) => module,
            };
            if let Err(mut e) = self.compile_module(module_ast) {
                // Enrich error
                e.file = Some(lib.to_string());
                return Err(e);
            }
        }
        Ok(())
    }
pub fn include_stdlib ( & mut self ) -> CompileResult < ( ) > { let libs = read_dir ( " " ) . expect ( " " ) . map ( | res | res . map ( | entry | entry . path ( ) ) ) . collect :: < Result < Vec < _ > , std :: io :: Error > > ( ) . unwrap ( ) ; for lib in libs . iter ( ) { let lib = lib . to_str ( ) . unwrap ( ) ; // Skip `__init__.py` which is for linter if lib . contains ( " " ) { continue ; } let to_compile_error = | parse_error | CompileError :: from_parse_error ( parse_error , lib . to_string ( ) ) ; let source = read_to_string ( & lib ) . expect ( & format ! ( " " lib ) ) ; let module_ast = match parse_program ( & source ) . map_err ( to_compile_error ) { Err ( e ) => { eprintln ! ( " " ) ; eprintln ! ( " " std path PathBuf from ( e source_path ) canonicalize ( ) unwrap ( ) display ( ) ) ; panic ! ( " " e ) ; } Ok ( module ) => module , } ; if let Err ( mut e ) = self . compile_module ( module_ast ) { // Enrich error e . file = Some ( lib . to_string ( ) ) ; return Err ( e ) ; } } Ok ( ( ) ) }
Include and compile standard DSPython Arduino libraries
Include and compile standard DSPython Arduino libraries
&mut self