diff --git a/compiler/erg_common/env.rs b/compiler/erg_common/env.rs index 59216200..5039b82b 100644 --- a/compiler/erg_common/env.rs +++ b/compiler/erg_common/env.rs @@ -3,24 +3,30 @@ use std::path::PathBuf; fn _erg_path() -> PathBuf { let path = var("ERG_PATH").unwrap_or_else(|_| env!("CARGO_ERG_PATH").to_string()); - PathBuf::from(path).canonicalize().unwrap() + PathBuf::from(path) + .canonicalize() + .expect("ERG_PATH not found") } fn _erg_std_path() -> PathBuf { - _erg_path().join("lib").join("std").canonicalize().unwrap() + _erg_path() + .join("lib") + .join("std") + .canonicalize() + .expect("ERG_PATH/lib/std not found") } fn _erg_pystd_path() -> PathBuf { _erg_path() .join("lib") .join("pystd") .canonicalize() - .unwrap() + .expect("ERG_PATH/lib/pystd not found") } fn _erg_external_lib_path() -> PathBuf { _erg_path() .join("lib") .join("external") .canonicalize() - .unwrap() + .expect("ERG_PATH/lib/external not found") } thread_local! { diff --git a/compiler/erg_common/error.rs b/compiler/erg_common/error.rs index e7e34c22..a76b9d21 100644 --- a/compiler/erg_common/error.rs +++ b/compiler/erg_common/error.rs @@ -218,7 +218,7 @@ impl From<&str> for ErrorKind { } /// points the location (of an error) in a code -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] pub enum Location { RangePair { ln_first: (usize, usize), @@ -234,6 +234,7 @@ pub enum Location { }, LineRange(usize, usize), Line(usize), + #[default] Unknown, } diff --git a/compiler/erg_common/python_util.rs b/compiler/erg_common/python_util.rs index d7bae2c2..05a43bfb 100644 --- a/compiler/erg_common/python_util.rs +++ b/compiler/erg_common/python_util.rs @@ -6,7 +6,7 @@ use std::process::Command; use crate::serialize::get_magic_num_from_bytes; #[cfg(unix)] -pub const BUILTIN_PYTHON_MODS: [&str; 19] = [ +pub const BUILTIN_PYTHON_MODS: [&str; 20] = [ "datetime", "glob", "http", @@ -20,6 +20,7 @@ pub const BUILTIN_PYTHON_MODS: [&str; 19] = [ "re", "shutil", "socket", + "string", "subprocess", "sys", "tarfile", @@ -28,7 +29,7 @@ pub const BUILTIN_PYTHON_MODS: [&str; 19] = [ "zipfile", ]; #[cfg(not(unix))] -pub const BUILTIN_PYTHON_MODS: [&str; 18] = [ +pub const BUILTIN_PYTHON_MODS: [&str; 19] = [ "datetime", "glob", "http", @@ -41,6 +42,7 @@ pub const BUILTIN_PYTHON_MODS: [&str; 18] = [ "re", "shutil", "socket", + "string", "subprocess", "sys", "tarfile", diff --git a/compiler/erg_compiler/lib/pystd/string.d.er b/compiler/erg_compiler/lib/pystd/string.d.er new file mode 100644 index 00000000..05f4b860 --- /dev/null +++ b/compiler/erg_compiler/lib/pystd/string.d.er @@ -0,0 +1,10 @@ +.ascii_letters: Str +.ascii_lowercase: Str +.ascii_uppercase: Str +.digits: Str +.hexdigits: Str +.octdigits: Str +.punctuation: Str +.printable: Str +.whitespace: Str +.Formatter: ClassType diff --git a/compiler/erg_parser/parse.rs b/compiler/erg_parser/parse.rs index 454254ce..938febb1 100644 --- a/compiler/erg_parser/parse.rs +++ b/compiler/erg_parser/parse.rs @@ -148,7 +148,7 @@ impl Parser { } fn skip_and_throw_syntax_err(&mut self, caused_by: &str) -> ParseError { - let loc = self.peek().unwrap().loc(); + let loc = self.peek().map(|t| t.loc()).unwrap_or_default(); log!(err "error caused by: {caused_by}"); self.next_expr(); ParseError::simple_syntax_error(0, loc) @@ -233,7 +233,7 @@ impl Parser { } }; if !self.cur_is(EOF) { - let loc = self.peek().unwrap().loc(); + let loc = self.peek().map(|t| t.loc()).unwrap_or_default(); self.errs .push(ParseError::compiler_bug(0, loc, fn_name!(), line!())); return Err(mem::take(&mut self.errs));