mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
fix: retry path resolution if failed
This commit is contained in:
parent
a9025507d3
commit
dab9def08a
2 changed files with 51 additions and 7 deletions
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! コマンドオプション(パーサー)を定義する
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::{stdin, BufRead, BufReader, Read, Write};
|
||||
|
@ -319,6 +320,26 @@ impl Input {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn module_name(&self) -> String {
|
||||
match &self.kind {
|
||||
InputKind::File(filename) => {
|
||||
let file_stem = if filename.file_stem() == Some(OsStr::new("__init__")) {
|
||||
filename.parent().and_then(|p| p.file_stem())
|
||||
} else {
|
||||
filename.file_stem()
|
||||
};
|
||||
file_stem
|
||||
.and_then(|f| f.to_str())
|
||||
.unwrap_or("_")
|
||||
.to_string()
|
||||
}
|
||||
InputKind::REPL | InputKind::Pipe(_) => "<stdin>".to_string(),
|
||||
InputKind::DummyREPL(stdin) => stdin.name.clone(),
|
||||
InputKind::Str(_) => "<string>".to_string(),
|
||||
InputKind::Dummy => "<dummy>".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read(&mut self) -> String {
|
||||
match &mut self.kind {
|
||||
InputKind::File(filename) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue