From 9d5a20e76a1ba04c330b06fd7b85bae8e4cfd568 Mon Sep 17 00:00:00 2001 From: sofia Date: Sun, 27 Jul 2025 22:55:34 +0300 Subject: [PATCH] Allow pub-keyword for impl-block --- examples/hello_world_harder.reid | 3 +-- reid/lib/std.reid | 11 +++++++++++ reid/src/ast/parse.rs | 23 ++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/examples/hello_world_harder.reid b/examples/hello_world_harder.reid index c9abe1e..22e1681 100644 --- a/examples/hello_world_harder.reid +++ b/examples/hello_world_harder.reid @@ -1,5 +1,4 @@ import std::print; -import std::from_str; import std::add_char; import std::set_char; import std::free_string; @@ -8,7 +7,7 @@ import std::add_num_to_str; import std::concat_strings; fn main() { - let mut test = from_str("hello"); + let mut test = String::new(); concat_strings(&mut test, from_str(" world")); diff --git a/reid/lib/std.reid b/reid/lib/std.reid index e7dbf9b..5787497 100644 --- a/reid/lib/std.reid +++ b/reid/lib/std.reid @@ -11,6 +11,17 @@ struct String { must_be_freed: bool, } +impl String { + pub fn new() -> String { + String { + inner: char::alloca(0), + length: 0, + max_length: 0, + must_be_freed: true, + } + } +} + impl binop (lhs: String) + (rhs: *char) -> String { let mut new = lhs; let added = from_str(rhs); diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index 526c244..b78685e 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -1052,15 +1052,20 @@ impl Parse for AssociatedFunctionBlock { let ty = stream.parse::()?; stream.expect(Token::BraceOpen)?; let mut functions = Vec::new(); - while let Some(Token::FnKeyword) = stream.peek() { - let mut fun: FunctionDefinition = stream.parse()?; - fun.0.self_kind = match fun.0.self_kind { - SelfKind::Owned(_) => SelfKind::Owned(ty.0.clone()), - SelfKind::Borrow(_) => SelfKind::Borrow(ty.0.clone()), - SelfKind::MutBorrow(_) => SelfKind::MutBorrow(ty.0.clone()), - SelfKind::None => SelfKind::None, - }; - functions.push(fun); + loop { + match stream.peek() { + Some(Token::FnKeyword) | Some(Token::PubKeyword) => { + let mut fun: FunctionDefinition = stream.parse()?; + fun.0.self_kind = match fun.0.self_kind { + SelfKind::Owned(_) => SelfKind::Owned(ty.0.clone()), + SelfKind::Borrow(_) => SelfKind::Borrow(ty.0.clone()), + SelfKind::MutBorrow(_) => SelfKind::MutBorrow(ty.0.clone()), + SelfKind::None => SelfKind::None, + }; + functions.push(fun); + } + _ => break, + } } stream.expect(Token::BraceClose)?;