diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 80c1d22e..0d2bdf70 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,7 +25,7 @@ jobs: rustup update stable cargo build --verbose - name: Run tests - run: cargo test --features large_thread --verbose + run: cargo test --features large_thread --verbose --all - uses: actions-rs/cargo@v1 with: command: clippy diff --git a/compiler/erg_common/error.rs b/compiler/erg_common/error.rs index a9f4fbff..aec6d74e 100644 --- a/compiler/erg_common/error.rs +++ b/compiler/erg_common/error.rs @@ -414,26 +414,28 @@ impl SubMessage { /// `msg` is Vec\ instead of Option\ because it can be used when there are multiple `msg`s as well as multiple lines. /// # Example /// ``` + /// # use erg_common::error::{Location, SubMessage}; + /// # use erg_common::style::{Color, StyledString}; + /// let loc = Location::Line(1); /// let msg = SubMessage::ambiguous_new(loc, vec![], None); // this code same as only_loc() /// - /// let hint = Some("hint message here".to_string()) + /// let hint = Some("hint message here".to_string()); /// let msg = SubMessage::ambiguous_new(loc, vec![], hint); /// /* example /// ------- /// `- hint message here /// */ /// - /// let hint = Some("hint here".to_string()) - /// let first = StyledString::new("1th message", Color::Red, None); - /// let second = StyledString::new("2th message", Color::White, None); - /// : - /// let nth = StyledString::new("nth message", Color::Green, None); + /// let hint = Some("hint here".to_string()); + /// let first = StyledString::new("1th message", Some(Color::Red), None); + /// let second = StyledString::new("2th message", Some(Color::White), None); + /// let nth = StyledString::new("nth message", Some(Color::Green), None); /// let msg = SubMessage::ambiguous_new( /// loc, /// vec![ /// first.to_string(), /// second.to_string(), - /// ..., + /// // ..., /// nth.to_string(), /// ], /// hint); @@ -457,6 +459,8 @@ impl SubMessage { /// In this case, error position is just modified /// # Example /// ``` + /// # use erg_common::error::{Location, SubMessage}; + /// let loc = Location::Line(1); /// let sub_msg = SubMessage::only_loc(loc); /// ``` pub fn only_loc(loc: Location) -> Self { diff --git a/compiler/erg_common/style.rs b/compiler/erg_common/style.rs index d0bbf710..8c5c6830 100644 --- a/compiler/erg_common/style.rs +++ b/compiler/erg_common/style.rs @@ -318,6 +318,7 @@ impl StyledString { /// /// # Example /// ``` + /// # use erg_common::style::StyledString; /// let s = String::from("Hello, world"); /// StyledString::new(s, None, None); /// let s = "Hello, world"; diff --git a/compiler/erg_compiler/context/mod.rs b/compiler/erg_compiler/context/mod.rs index 56fd2251..102523e4 100644 --- a/compiler/erg_compiler/context/mod.rs +++ b/compiler/erg_compiler/context/mod.rs @@ -27,7 +27,6 @@ use erg_common::vis::Visibility; use erg_common::Str; use erg_common::{fn_name, get_hash, log}; -use crate::ty::typaram::TyParam; use crate::ty::value::ValueObj; use crate::ty::{Predicate, Type}; use erg_parser::ast::DefKind; @@ -100,72 +99,6 @@ impl ClassDefType { } } -/// ``` -/// # use erg_common::ty::{Type, TyParam}; -/// # use erg_compiler::context::TyParamIdx; -/// -/// let r = Type::mono_q("R"); -/// let o = Type::mono_q("O"); -/// let search_from = Type::poly("Add", vec![TyParam::t(r.clone()), TyParam::t(o.clone())]); -/// assert_eq!(TyParamIdx::search(&search_from, &o), Some(TyParamIdx::Nth(1))); -/// let i = Type::mono_q("I"); -/// let f = Type::poly("F", vec![TyParam::t(o.clone()), TyParam::t(i.clone())]); -/// let search_from = Type::poly("Add", vec![TyParam::t(r), TyParam::t(f)]); -/// assert_eq!(TyParamIdx::search(&search_from, &o), Some(TyParamIdx::nested(1, TyParamIdx::Nth(0)))); -/// ``` -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum TyParamIdx { - Nth(usize), - Nested { idx: usize, inner: Box }, -} - -impl TyParamIdx { - pub fn search(search_from: &Type, target: &Type) -> Option { - match search_from { - Type::Poly { params, .. } => { - for (i, tp) in params.iter().enumerate() { - match tp { - TyParam::Type(t) if t.as_ref() == target => return Some(Self::Nth(i)), - TyParam::Type(t) if t.is_monomorphic() => {} - TyParam::Type(inner) => { - if let Some(inner) = Self::search(inner, target) { - return Some(Self::nested(i, inner)); - } - } - other => todo!("{other:?}"), - } - } - None - } - _ => todo!(), - } - } - - /// ```python - /// Nested(Nth(1), 0).select(F(X, G(Y, Z))) == Y - /// ``` - pub fn select(self, from: &Type) -> Type { - match self { - Self::Nth(n) => { - let tps = from.typarams(); - let tp = tps.get(n).unwrap(); - match tp { - TyParam::Type(t) => *t.clone(), - _ => todo!(), - } - } - Self::Nested { .. } => todo!(), - } - } - - pub fn nested(idx: usize, inner: Self) -> Self { - Self::Nested { - idx, - inner: Box::new(inner), - } - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum DefaultInfo { NonDefault, diff --git a/compiler/erg_compiler/ty/constructors.rs b/compiler/erg_compiler/ty/constructors.rs index 0115459f..7ffcb607 100644 --- a/compiler/erg_compiler/ty/constructors.rs +++ b/compiler/erg_compiler/ty/constructors.rs @@ -397,7 +397,7 @@ pub fn proj_call>(lhs: TyParam, attr_name: S, args: Vec) - } } -/// ```rust +/// ```erg /// {I: Int | I >= 0} /// => Refinement{ /// layout: TyParam::MonoQ "I", diff --git a/compiler/erg_compiler/ty/mod.rs b/compiler/erg_compiler/ty/mod.rs index aaeda005..6924344f 100644 --- a/compiler/erg_compiler/ty/mod.rs +++ b/compiler/erg_compiler/ty/mod.rs @@ -790,7 +790,7 @@ pub enum RefineKind { } /// e.g. -/// ``` +/// ```erg /// {I: Int | I >= 0} /// {_: StrWithLen N | N >= 0} /// {T: (Int, Int) | T.0 >= 0, T.1 >= 0} diff --git a/compiler/erg_parser/parse.rs b/compiler/erg_parser/parse.rs index 4d7d4672..f9d52b1e 100644 --- a/compiler/erg_parser/parse.rs +++ b/compiler/erg_parser/parse.rs @@ -557,7 +557,7 @@ impl Parser { /// 引数はインデントで区切ることができる(ただしコンマに戻すことはできない) /// - /// ``` + /// ```erg /// x = if True, 1, 2 /// # is equal to /// x = if True: diff --git a/compiler/erg_parser/tests/parse_test.rs b/compiler/erg_parser/tests/parse_test.rs index 15734391..599b22af 100644 --- a/compiler/erg_parser/tests/parse_test.rs +++ b/compiler/erg_parser/tests/parse_test.rs @@ -1,5 +1,6 @@ use erg_common::config::{ErgConfig, Input}; use erg_common::error::MultiErrorDisplay; +use erg_common::spawn::exec_new_thread; use erg_common::traits::Runnable; use erg_parser::error::ParserRunnerErrors; @@ -51,7 +52,7 @@ fn parse_test2_advanced_syntax() -> Result<(), ParserRunnerErrors> { expect_success("tests/test2_advanced_syntax.er") } -fn parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerErrors> { +fn _parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerErrors> { let input = Input::File(file_path.into()); let cfg = ErgConfig { input: input.clone(), @@ -76,6 +77,10 @@ fn parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerError } } +fn parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerErrors> { + exec_new_thread(move || _parse_test_from_code(file_path)) +} + fn expect_success(file_path: &'static str) -> Result<(), ParserRunnerErrors> { match parse_test_from_code(file_path) { Ok(_) => Ok(()), diff --git a/compiler/erg_parser/tests/test1_basic_syntax.er b/compiler/erg_parser/tests/test1_basic_syntax.er index 0ce45668..281683c8 100644 --- a/compiler/erg_parser/tests/test1_basic_syntax.er +++ b/compiler/erg_parser/tests/test1_basic_syntax.er @@ -10,7 +10,7 @@ Check that a parser can pass the basic syntax ]# _a = 1_234 + 1113.* 3_000.2e-4 ** 0003 * .4 -# a, _, ...b = five_elem_tuple +a, _, b = tuple f x, y = x + y if! True, do!: @@ -22,9 +22,8 @@ dedented comment 10.times! do!: if! x.y.z, do!: print! "" - # illegal indent - # do_nothing! Hello = S2c "hello" + None aあ아 = # コメント "aaa" diff --git a/compiler/erg_parser/tests/tokenize_test.rs b/compiler/erg_parser/tests/tokenize_test.rs index c87f51ac..7b57b7f1 100644 --- a/compiler/erg_parser/tests/tokenize_test.rs +++ b/compiler/erg_parser/tests/tokenize_test.rs @@ -37,10 +37,9 @@ fn test_lexer_for_basic() -> ParseResult<()> { (Comma, ","), (UBar, "_"), (Comma, ","), - (EllipsisLit, "..."), (Symbol, "b"), (Equal, "="), - (Symbol, "five_elem_tuple"), + (Symbol, "tuple"), (Newline, newline), (Symbol, "f"), (Symbol, "x"), @@ -87,13 +86,13 @@ fn test_lexer_for_basic() -> ParseResult<()> { (StrLit, "\"\""), (Newline, newline), (Dedent, ""), - (Newline, newline), - (Newline, newline), (Symbol, "Hello"), (Equal, "="), (Symbol, "S2c"), (StrLit, "\"hello\""), (Newline, newline), + (NoneLit, "None"), + (Newline, newline), (Dedent, ""), (Dedent, ""), (Symbol, "aあ아"), @@ -154,7 +153,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> { (Colon, ":"), (Symbol, "Nat"), (RParen, ")"), - (FuncArrow, "->"), + (Colon, ":"), (Symbol, "Nat"), (Equal, "="), (Symbol, "fib"), @@ -204,8 +203,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> { (Newline, newline), (LBrace, "{"), (Symbol, "pi"), - (Comma, ","), - (EllipsisLit, "..."), + (Semi, ";"), (RBrace, "}"), (Equal, "="), (Symbol, "import"),