From a389ca239c56dd498af63a69b960d6bd29c5c2ba Mon Sep 17 00:00:00 2001 From: peter-jerry-ye Date: Tue, 6 Jan 2026 13:55:08 +0800 Subject: [PATCH 1/4] chore: update .gitignore for MoonBit artifacts --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ec52756..6746312 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ target/ .mooncakes/ .DS_Store +_build/ +target From 8eba44b8575d6082c50db3b5477c6e13d38799a7 Mon Sep 17 00:00:00 2001 From: peter-jerry-ye Date: Tue, 6 Jan 2026 13:57:36 +0800 Subject: [PATCH 2/4] chore: run moon fmt and moon info --- README.mbt.md | 133 ++++++++++++++++++++++++------------------ README_zh_CN.mbt.md | 137 +++++++++++++++++++++++++------------------- 2 files changed, 154 insertions(+), 116 deletions(-) diff --git a/README.mbt.md b/README.mbt.md index d7d07c7..e453cd3 100644 --- a/README.mbt.md +++ b/README.mbt.md @@ -52,38 +52,44 @@ max_connections=100 The simplest way to use `ini` is with the `parse` function: -```mbt test -let config_str = - #|[server] - #|host=localhost - #|port=3000 -let ini = @ini.parse(config_str) -let host = ini.get(section="server", "host").unwrap() -inspect(host, content="localhost") +```mbt check +///| +test { + let config_str = + #|[server] + #|host=localhost + #|port=3000 + let ini = @ini.parse(config_str) + let host = ini.get(section="server", "host").unwrap() + inspect(host, content="localhost") +} ``` ### **⚙️ Configuration Options** ini offers configuration options when parsing: -```mbt test -let content = - #|[server] - #|host=localhost - #|port=3000 - #|[Server] - #|host=remote +```mbt check +///| +test { + let content = + #|[server] + #|host=localhost + #|port=3000 + #|[Server] + #|host=remote -// Case-sensitive parsing + // Case-sensitive parsing -let ini = @ini.parse(content, is_case_sensitive=true) -inspect(ini.get(section="server", "host").unwrap(), content="localhost") -inspect(ini.get(section="Server", "host").unwrap(), content="remote") + let ini = @ini.parse(content, is_case_sensitive=true) + inspect(ini.get(section="server", "host").unwrap(), content="localhost") + inspect(ini.get(section="Server", "host").unwrap(), content="remote") -// Create an empty INI file object + // Create an empty INI file object -let ini = @ini.IniFile::new(is_case_sensitive=true) -ignore(ini) + let ini = @ini.IniFile::new(is_case_sensitive=true) + ignore(ini) +} ``` --- @@ -92,23 +98,26 @@ ignore(ini) After parsing, you can access values using various methods: -```mbt test -let content = - #|[server] - #|host=localhost - #|port=3000 - #|[feature] - #|foo=true -let ini = @ini.parse(content) -let host = ini.get(section="server", "host") -inspect( - host, - content=( - #|Some("localhost") - ), -) -let foo_enabled = ini.get_bool(section="feature", "foo") -inspect(foo_enabled, content="Some(true)") +```mbt check +///| +test { + let content = + #|[server] + #|host=localhost + #|port=3000 + #|[feature] + #|foo=true + let ini = @ini.parse(content) + let host = ini.get(section="server", "host") + inspect( + host, + content=( + #|Some("localhost") + ), + ) + let foo_enabled = ini.get_bool(section="feature", "foo") + inspect(foo_enabled, content="Some(true)") +} ``` --- @@ -116,24 +125,34 @@ inspect(foo_enabled, content="Some(true)") ### **🛠️ Full Example** -```mbt test -let content = - #|[server] - #|host=localhost - #|port=3000 - #|enabled=true - #| - #|[database] - #|url=mysql://localhost/db - -// Parse INI content -let ini = @ini.parse(content) - -// Access various values -let host = ini.get(section="server", "host").unwrap() -let port = ini.get(section="server", "port").unwrap_or("8080") -let enabled = ini.get_bool(section="server", "enabled").unwrap() -inspect(if enabled { "\{host}:\{port}" } else { "" }, content="localhost:3000") +```mbt check +///| +test { + let content = + #|[server] + #|host=localhost + #|port=3000 + #|enabled=true + #| + #|[database] + #|url=mysql://localhost/db + + // Parse INI content + let ini = @ini.parse(content) + + // Access various values + let host = ini.get(section="server", "host").unwrap() + let port = ini.get(section="server", "port").unwrap_or("8080") + let enabled = ini.get_bool(section="server", "enabled").unwrap() + inspect( + if enabled { + "\{host}:\{port}" + } else { + "" + }, + content="localhost:3000", + ) +} ``` ## 📜 License diff --git a/README_zh_CN.mbt.md b/README_zh_CN.mbt.md index 8cfee03..fe836a5 100644 --- a/README_zh_CN.mbt.md +++ b/README_zh_CN.mbt.md @@ -52,36 +52,42 @@ max_connections=100 使用 `ini` 最简单的方法是使用 `parse` 函数: -```mbt test -let config_str = - #|[server] - #|host=localhost - #|port=3000 -let ini = @ini.parse(config_str) -let host = ini.get(section="server", "host").unwrap() -inspect(host, content="localhost") +```mbt check +///| +test { + let config_str = + #|[server] + #|host=localhost + #|port=3000 + let ini = @ini.parse(config_str) + let host = ini.get(section="server", "host").unwrap() + inspect(host, content="localhost") +} ``` ### **⚙️ 配置选项** ini 在解析时提供配置选项: -```mbt test -let content = - #|[server] - #|host=localhost - #|port=3000 - #|[Server] - #|host=remote - -// 大小写敏感解析 -let ini = @ini.parse(content, is_case_sensitive=true) -inspect(ini.get(section="server", "host").unwrap(), content="localhost") -inspect(ini.get(section="Server", "host").unwrap(), content="remote") - -// 创建空的 INI 文件对象 -let ini = @ini.IniFile::new(is_case_sensitive=true) -ignore(ini) +```mbt check +///| +test { + let content = + #|[server] + #|host=localhost + #|port=3000 + #|[Server] + #|host=remote + + // 大小写敏感解析 + let ini = @ini.parse(content, is_case_sensitive=true) + inspect(ini.get(section="server", "host").unwrap(), content="localhost") + inspect(ini.get(section="Server", "host").unwrap(), content="remote") + + // 创建空的 INI 文件对象 + let ini = @ini.IniFile::new(is_case_sensitive=true) + ignore(ini) +} ``` --- @@ -90,47 +96,60 @@ ignore(ini) 解析后,您可以使用各种方法访问值: -```mbt test -let content = - #|[server] - #|host=localhost - #|port=3000 - #|[feature] - #|foo=true -let ini = @ini.parse(content) -let host = ini.get(section="server", "host") -inspect( - host, - content=( - #|Some("localhost") - ), -) -let foo_enabled = ini.get_bool(section="feature", "foo") -inspect(foo_enabled, content="Some(true)") +```mbt check +///| +test { + let content = + #|[server] + #|host=localhost + #|port=3000 + #|[feature] + #|foo=true + let ini = @ini.parse(content) + let host = ini.get(section="server", "host") + inspect( + host, + content=( + #|Some("localhost") + ), + ) + let foo_enabled = ini.get_bool(section="feature", "foo") + inspect(foo_enabled, content="Some(true)") +} ``` --- ### **🛠️ 完整示例** -```mbt test -let content = - #|[server] - #|host=localhost - #|port=3000 - #|enabled=true - #| - #|[database] - #|url=mysql://localhost/db - -// 解析 INI 内容 -let ini = @ini.parse(content) - -// 访问各种值 -let host = ini.get(section="server", "host").unwrap() -let port = ini.get(section="server", "port").unwrap_or("8080") -let enabled = ini.get_bool(section="server", "enabled").unwrap() -inspect(if enabled { "\{host}:\{port}" } else { "" }, content="localhost:3000") +```mbt check +///| +test { + let content = + #|[server] + #|host=localhost + #|port=3000 + #|enabled=true + #| + #|[database] + #|url=mysql://localhost/db + + // 解析 INI 内容 + let ini = @ini.parse(content) + + // 访问各种值 + let host = ini.get(section="server", "host").unwrap() + let port = ini.get(section="server", "port").unwrap_or("8080") + let enabled = ini.get_bool(section="server", "enabled").unwrap() + inspect( + if enabled { + "\{host}:\{port}" + } else { + "" + }, + content="localhost:3000", + ) +} ``` ## 📜 许可证 From 0b0ca36e6c61283fb6f1c2e02131070be0954004 Mon Sep 17 00:00:00 2001 From: peter-jerry-ye Date: Tue, 6 Jan 2026 15:11:04 +0800 Subject: [PATCH 3/4] Fix deprecated trim and update gitignore --- .gitignore | 3 +-- parser.mbt | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 6746312..7d08f82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ target/ +_build/ .mooncakes/ .DS_Store -_build/ -target diff --git a/parser.mbt b/parser.mbt index a3a587c..c8cf36b 100644 --- a/parser.mbt +++ b/parser.mbt @@ -181,7 +181,7 @@ fn IniParseState::handle_section_char( if self.ctx.buffer.is_empty() { raise IniParseError::EmptySection(line=self.ctx.line, col=self.ctx.col) } - let section_name = self.ctx.buffer.to_string().trim_space() + let section_name = self.ctx.buffer.to_string().trim() let section_name = self.lower_if_needed(section_name.to_string()) self.ctx.current_section = Section::NamedSection(section_name) if not(self.ctx.sections.contains(self.ctx.current_section)) { @@ -212,7 +212,7 @@ fn IniParseState::handle_key_char( col=self.ctx.col, ) } - let key = self.ctx.buffer.to_string().trim_space() + let key = self.ctx.buffer.to_string().trim() let key = self.lower_if_needed(key.to_string()) self.ctx.buffer.reset() self.phase = ReadingValue(ReadingValueState::None) @@ -220,7 +220,7 @@ fn IniParseState::handle_key_char( self } '\n' | ';' | '#' => { - let key = self.ctx.buffer.to_string().trim_space() + let key = self.ctx.buffer.to_string().trim() if not(key.is_empty()) { let key = self.lower_if_needed(key.to_string()) self.ctx.key = key From e6f51182eb110dbd8eda58ec1f906368339ab040 Mon Sep 17 00:00:00 2001 From: peter-jerry-ye Date: Tue, 6 Jan 2026 15:12:56 +0800 Subject: [PATCH 4/4] Ignore build artifacts --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7d08f82..edd913a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -target/ -_build/ +target +_build .mooncakes/ .DS_Store