From cbfdd0f76064dda09b438fb8e5744335a84e6fca Mon Sep 17 00:00:00 2001 From: myfreess Date: Tue, 31 Mar 2026 14:16:07 +0800 Subject: [PATCH] update --- attribute/pkg.generated.mbti | 12 ++++-------- basic/pkg.generated.mbti | 11 ++--------- lexer/lex.mbt | 2 +- lexer/lex_env.mbt | 4 ++-- lexer/lexer.mbt | 12 ++++++------ lexer/moon.pkg | 2 +- mbti_ast/pkg.generated.mbti | 3 +-- mbti_parser/pkg.generated.mbti | 3 +-- pkg_parser/pkg.generated.mbti | 4 +--- test/mbti_parser_test/helper_test.mbt | 2 +- tokens/pkg.generated.mbti | 26 ++++++-------------------- yacc_parser/pkg.generated.mbti | 3 +-- 12 files changed, 27 insertions(+), 57 deletions(-) diff --git a/attribute/pkg.generated.mbti b/attribute/pkg.generated.mbti index 5b920d3e..8f6c253d 100644 --- a/attribute/pkg.generated.mbti +++ b/attribute/pkg.generated.mbti @@ -15,27 +15,24 @@ pub fn payloads(Array[(@tokens.Token, @basic.Position, @basic.Position)], initia pub suberror ParseError { UnexpectedToken(@tokens.Token, (@basic.Position, @basic.Position), Array[@tokens.TokenKind]) UnexpectedEndOfInput(@basic.Position, Array[@tokens.TokenKind]) -} -pub impl @debug.Debug for ParseError +} derive(@debug.Debug) // Types and methods pub(all) struct Attribute { loc : @basic.Location raw : String parsed : Expr? -} +} derive(@debug.Debug) pub fn Attribute::name(Self) -> String? pub fn Attribute::new(loc~ : @basic.Location, (String, String?, String)) -> Self pub impl ToJson for Attribute -pub impl @debug.Debug for Attribute pub(all) enum Expr { Ident(Id) String(String) Apply(Id, @list.List[Prop]) Bool(Bool) -} -pub impl @debug.Debug for Expr +} derive(@debug.Debug) pub(all) struct Id { qual : String? @@ -47,8 +44,7 @@ pub impl @debug.Debug for Id pub(all) enum Prop { Labeled(String, Expr) Expr(Expr) -} -pub impl @debug.Debug for Prop +} derive(@debug.Debug) // Type aliases diff --git a/basic/pkg.generated.mbti b/basic/pkg.generated.mbti index 16bf1c11..c9776219 100644 --- a/basic/pkg.generated.mbti +++ b/basic/pkg.generated.mbti @@ -25,30 +25,23 @@ pub(all) enum LocStyle { pub(all) struct Location { start : Position end : Position -} +} derive(Compare, Eq, Hash, @debug.Debug) pub fn Location::merge(Self, Self) -> Self pub fn Location::trim_first_char(Self) -> Self pub fn Location::trim_last_char(Self) -> Self -pub impl Compare for Location -pub impl Eq for Location -pub impl Hash for Location pub impl Show for Location pub impl ToJson for Location -pub impl @debug.Debug for Location pub(all) struct Position { fname : String lnum : Int bol : Int cnum : Int -} +} derive(Hash, ToJson, @debug.Debug) pub fn Position::column(Self) -> Int pub impl Compare for Position pub impl Eq for Position -pub impl Hash for Position pub impl Show for Position -pub impl ToJson for Position -pub impl @debug.Debug for Position pub(all) struct Report { loc : Location diff --git a/lexer/lex.mbt b/lexer/lex.mbt index fdc18eb9..d3e2ef31 100644 --- a/lexer/lex.mbt +++ b/lexer/lex.mbt @@ -35,7 +35,7 @@ pub fn tokens_from_string( } lex_tokens(str, base=str, env~, preserve_comment=env.preserve_comment()) let docstrings = env.docstrings - if not(docstrings.is_empty()) { + if !docstrings.is_empty() { let last_idx = docstrings.length() - 1 docstrings[last_idx] = docstrings[last_idx].rev() } diff --git a/lexer/lex_env.mbt b/lexer/lex_env.mbt index 978ec9c8..7917d59d 100644 --- a/lexer/lex_env.mbt +++ b/lexer/lex_env.mbt @@ -90,11 +90,11 @@ fn LexEnv::add_token( // Make sure add trailing newline if the comment is at end of file let trailing_newlines = @cmp.minimum(2, count_newlines(i, 1)) let (_, start, end) = self.tokens[i] - let kind = if leading_newlines == 0 && not(at_file_start) { + let kind = if leading_newlines == 0 && !at_file_start { CommentKind::InlineTrailing } else { Ownline( - leading_blank_line=leading_newlines == 2 && not(at_file_start), + leading_blank_line=leading_newlines == 2 && !at_file_start, trailing_blank_line=trailing_newlines == 2, ) } diff --git a/lexer/lexer.mbt b/lexer/lexer.mbt index 3a103413..e1860c98 100644 --- a/lexer/lexer.mbt +++ b/lexer/lexer.mbt @@ -611,7 +611,7 @@ fn lex_tokens( // Dot with number ("\.[0-9]+" as dot_int, rest) => { let digits_str = dot_int.sub(start=1, end=dot_int.length()) // Remove the '.' - let idx = @strconv.parse_int(digits_str) catch { + let idx = @string.parse_int(digits_str) catch { _ => { let full_str = dot_int.to_string() env.add_lexing_error( @@ -1057,7 +1057,7 @@ fn lex_string( string_repr_buf.write_char('"') process_string(rest, start_pos) } else { - if not(string_repr_buf.is_empty()) { + if !string_repr_buf.is_empty() { add_literal( string_repr_buf.to_string(), start_pos, @@ -1104,7 +1104,7 @@ fn lex_string( rest ) => if allow_interp { - if not(string_repr_buf.is_empty()) { + if !string_repr_buf.is_empty() { add_literal( string_repr_buf.to_string(), start_pos, @@ -1144,7 +1144,7 @@ fn lex_string( end=env.calc_offset(base~, input), UnterminatedString, ) - if not(string_repr_buf.is_empty()) { + if !string_repr_buf.is_empty() { add_literal( string_repr_buf.to_string(), start_pos, @@ -1157,10 +1157,10 @@ fn lex_string( // CRLF ("[\r\n]", rest) => { let end_pos = env.calc_offset(base~, rest) - if not(end_with_newline) { + if !end_with_newline { env.add_lexing_error(start=start_pos, end=end_pos, UnterminatedString) } - if not(string_repr_buf.is_empty()) { + if !string_repr_buf.is_empty() { add_literal(string_repr_buf.to_string(), start_pos, end_pos) } // Need to back off to handle NEWLINE token diff --git a/lexer/moon.pkg b/lexer/moon.pkg index 8736366a..87ee9289 100644 --- a/lexer/moon.pkg +++ b/lexer/moon.pkg @@ -2,7 +2,7 @@ import { "moonbitlang/parser/tokens", "moonbitlang/parser/basic", "moonbitlang/core/list", - "moonbitlang/core/strconv", + "moonbitlang/core/string", "moonbitlang/core/cmp", "moonbitlang/core/ref", "moonbitlang/core/hashset", diff --git a/mbti_ast/pkg.generated.mbti b/mbti_ast/pkg.generated.mbti index 78151ef1..c03aeda8 100644 --- a/mbti_ast/pkg.generated.mbti +++ b/mbti_ast/pkg.generated.mbti @@ -59,8 +59,7 @@ pub(all) struct MethodSelfType { pub(all) struct Name { name : String loc : @basic.Location -} -pub impl ToJson for Name +} derive(ToJson) pub(all) struct PackageImport { name : String diff --git a/mbti_parser/pkg.generated.mbti b/mbti_parser/pkg.generated.mbti index 54b4f8eb..b2a544b3 100644 --- a/mbti_parser/pkg.generated.mbti +++ b/mbti_parser/pkg.generated.mbti @@ -15,8 +15,7 @@ pub fn mbti(Array[(@tokens.Token, @basic.Position, @basic.Position)], initial_po pub suberror ParseError { UnexpectedToken(@tokens.Token, (@basic.Position, @basic.Position), Array[@tokens.TokenKind]) UnexpectedEndOfInput(@basic.Position, Array[@tokens.TokenKind]) -} -pub impl @debug.Debug for ParseError +} derive(@debug.Debug) // Types and methods diff --git a/pkg_parser/pkg.generated.mbti b/pkg_parser/pkg.generated.mbti index 2534a61b..0e71b779 100644 --- a/pkg_parser/pkg.generated.mbti +++ b/pkg_parser/pkg.generated.mbti @@ -26,16 +26,14 @@ pub(all) enum Ast { Float(float~ : String, loc~ : @basic.Location) Arr(content~ : Array[Ast], loc~ : @basic.Location) Obj(map~ : Map[String, Ast], loc~ : @basic.Location) -} +} derive(Eq, @debug.Debug) pub fn Ast::as_array(Self) -> Array[Self]? pub fn Ast::as_bool(Self) -> Bool? pub fn Ast::as_number(Self) -> String? pub fn Ast::as_object(Self) -> Map[String, Self]? pub fn Ast::as_string(Self) -> String? pub fn Ast::loc(Self) -> @basic.Location -pub impl Eq for Ast pub impl ToJson for Ast -pub impl @debug.Debug for Ast // Type aliases diff --git a/test/mbti_parser_test/helper_test.mbt b/test/mbti_parser_test/helper_test.mbt index de0a84ea..bd1f4570 100644 --- a/test/mbti_parser_test/helper_test.mbt +++ b/test/mbti_parser_test/helper_test.mbt @@ -13,7 +13,7 @@ fn @test.Test::run(t : Self, filename : String) -> Unit raise { ) let mbti = @mbti_parser.mbti( lex_result.tokens.filter(fn(triple) { - not(triple.0 is (NEWLINE | COMMENT(_))) + !(triple.0 is (NEWLINE | COMMENT(_))) }), initial_pos=@basic.Position::{ fname: filename, lnum: 1, bol: 0, cnum: 0 }, ) diff --git a/tokens/pkg.generated.mbti b/tokens/pkg.generated.mbti index dc5920ea..8c74accd 100644 --- a/tokens/pkg.generated.mbti +++ b/tokens/pkg.generated.mbti @@ -15,33 +15,24 @@ pub(all) struct Comment { content : String kind : CommentKind mut consumed_by_docstring : Bool -} -pub impl Eq for Comment +} derive(Eq, @debug.Debug) pub impl ToJson for Comment -pub impl @debug.Debug for Comment pub(all) enum CommentKind { InlineTrailing Ownline(leading_blank_line~ : Bool, trailing_blank_line~ : Bool) -} -pub impl Eq for CommentKind +} derive(Eq, @debug.Debug) pub impl ToJson for CommentKind -pub impl @debug.Debug for CommentKind pub(all) enum InterpElem { InterpLit(repr~ : String, loc~ : @basic.Location) InterpSource(InterpSource) -} -pub impl Eq for InterpElem -pub impl @debug.Debug for InterpElem +} derive(Eq, @debug.Debug) pub(all) struct InterpSource { source : String loc : @basic.Location -} -pub impl Eq for InterpSource -pub impl ToJson for InterpSource -pub impl @debug.Debug for InterpSource +} derive(Eq, ToJson, @debug.Debug) pub(all) enum Token { CHAR(String) @@ -159,11 +150,10 @@ pub(all) enum Token { LEXMATCH LEXMATCH_QUESTION PACKAGE -} +} derive(@debug.Debug) pub fn Token::kind(Self) -> TokenKind pub fn Token::to_expect_string(Self) -> String pub impl ToJson for Token -pub impl @debug.Debug for Token pub(all) enum TokenKind { TK_CHAR @@ -281,13 +271,9 @@ pub(all) enum TokenKind { TK_LEXMATCH TK_LEXMATCH_QUESTION TK_PACKAGE -} +} derive(Compare, Eq, Hash, @debug.Debug) pub fn TokenKind::to_expect_string(Self) -> String -pub impl Compare for TokenKind -pub impl Eq for TokenKind -pub impl Hash for TokenKind pub impl Show for TokenKind -pub impl @debug.Debug for TokenKind // Type aliases pub type ByteLiteral = String diff --git a/yacc_parser/pkg.generated.mbti b/yacc_parser/pkg.generated.mbti index 26f0e917..3b9465e6 100644 --- a/yacc_parser/pkg.generated.mbti +++ b/yacc_parser/pkg.generated.mbti @@ -18,8 +18,7 @@ pub fn structure(Array[(@tokens.Token, @basic.Position, @basic.Position)], initi pub suberror ParseError { UnexpectedToken(@tokens.Token, (@basic.Position, @basic.Position), Array[@tokens.TokenKind]) UnexpectedEndOfInput(@basic.Position, Array[@tokens.TokenKind]) -} -pub impl @debug.Debug for ParseError +} derive(@debug.Debug) // Types and methods