mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 14:04:33 +00:00
Add string module
This commit is contained in:
parent
f99c788b85
commit
1356ce399b
5 changed files with 28 additions and 9 deletions
|
@ -3,24 +3,30 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
fn _erg_path() -> PathBuf {
|
fn _erg_path() -> PathBuf {
|
||||||
let path = var("ERG_PATH").unwrap_or_else(|_| env!("CARGO_ERG_PATH").to_string());
|
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 {
|
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 {
|
fn _erg_pystd_path() -> PathBuf {
|
||||||
_erg_path()
|
_erg_path()
|
||||||
.join("lib")
|
.join("lib")
|
||||||
.join("pystd")
|
.join("pystd")
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.unwrap()
|
.expect("ERG_PATH/lib/pystd not found")
|
||||||
}
|
}
|
||||||
fn _erg_external_lib_path() -> PathBuf {
|
fn _erg_external_lib_path() -> PathBuf {
|
||||||
_erg_path()
|
_erg_path()
|
||||||
.join("lib")
|
.join("lib")
|
||||||
.join("external")
|
.join("external")
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.unwrap()
|
.expect("ERG_PATH/lib/external not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
|
|
@ -218,7 +218,7 @@ impl From<&str> for ErrorKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// points the location (of an error) in a code
|
/// 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 {
|
pub enum Location {
|
||||||
RangePair {
|
RangePair {
|
||||||
ln_first: (usize, usize),
|
ln_first: (usize, usize),
|
||||||
|
@ -234,6 +234,7 @@ pub enum Location {
|
||||||
},
|
},
|
||||||
LineRange(usize, usize),
|
LineRange(usize, usize),
|
||||||
Line(usize),
|
Line(usize),
|
||||||
|
#[default]
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::process::Command;
|
||||||
use crate::serialize::get_magic_num_from_bytes;
|
use crate::serialize::get_magic_num_from_bytes;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub const BUILTIN_PYTHON_MODS: [&str; 19] = [
|
pub const BUILTIN_PYTHON_MODS: [&str; 20] = [
|
||||||
"datetime",
|
"datetime",
|
||||||
"glob",
|
"glob",
|
||||||
"http",
|
"http",
|
||||||
|
@ -20,6 +20,7 @@ pub const BUILTIN_PYTHON_MODS: [&str; 19] = [
|
||||||
"re",
|
"re",
|
||||||
"shutil",
|
"shutil",
|
||||||
"socket",
|
"socket",
|
||||||
|
"string",
|
||||||
"subprocess",
|
"subprocess",
|
||||||
"sys",
|
"sys",
|
||||||
"tarfile",
|
"tarfile",
|
||||||
|
@ -28,7 +29,7 @@ pub const BUILTIN_PYTHON_MODS: [&str; 19] = [
|
||||||
"zipfile",
|
"zipfile",
|
||||||
];
|
];
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
pub const BUILTIN_PYTHON_MODS: [&str; 18] = [
|
pub const BUILTIN_PYTHON_MODS: [&str; 19] = [
|
||||||
"datetime",
|
"datetime",
|
||||||
"glob",
|
"glob",
|
||||||
"http",
|
"http",
|
||||||
|
@ -41,6 +42,7 @@ pub const BUILTIN_PYTHON_MODS: [&str; 18] = [
|
||||||
"re",
|
"re",
|
||||||
"shutil",
|
"shutil",
|
||||||
"socket",
|
"socket",
|
||||||
|
"string",
|
||||||
"subprocess",
|
"subprocess",
|
||||||
"sys",
|
"sys",
|
||||||
"tarfile",
|
"tarfile",
|
||||||
|
|
10
compiler/erg_compiler/lib/pystd/string.d.er
Normal file
10
compiler/erg_compiler/lib/pystd/string.d.er
Normal file
|
@ -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
|
|
@ -148,7 +148,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn skip_and_throw_syntax_err(&mut self, caused_by: &str) -> ParseError {
|
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}");
|
log!(err "error caused by: {caused_by}");
|
||||||
self.next_expr();
|
self.next_expr();
|
||||||
ParseError::simple_syntax_error(0, loc)
|
ParseError::simple_syntax_error(0, loc)
|
||||||
|
@ -233,7 +233,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if !self.cur_is(EOF) {
|
if !self.cur_is(EOF) {
|
||||||
let loc = self.peek().unwrap().loc();
|
let loc = self.peek().map(|t| t.loc()).unwrap_or_default();
|
||||||
self.errs
|
self.errs
|
||||||
.push(ParseError::compiler_bug(0, loc, fn_name!(), line!()));
|
.push(ParseError::compiler_bug(0, loc, fn_name!(), line!()));
|
||||||
return Err(mem::take(&mut self.errs));
|
return Err(mem::take(&mut self.errs));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue