Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .github/workflows/check.yaml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: check

on:
push:
branches:
- master
- main
pull_request:

jobs:
check:
strategy:
fail-fast: false
runs-on: ubuntu-latest
continue-on-error: false
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: install
run: |
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
echo "$HOME/.moon/bin" >> $GITHUB_PATH

- name: moon version
run: |
moon version --all

- name: moon check
run: |
moon update
moon check --deny-warn

- name: moon info
run: |
moon info --target all
git diff --exit-code

- name: format diff
run: |
moon fmt
git diff --exit-code

- name: moon test
run: |
moon test --target all
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
moon version --all
moon update
moon install
moon check --deny-warn

- name: Run tests with coverage
run: |
Expand Down
50 changes: 35 additions & 15 deletions ini_file.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@
priv enum Section {
Global
NamedSection(String)
} derive(Eq, Hash, Show)
} derive(Eq, Hash)

///|
impl Show for Section with output(self, logger) {
match self {
Section::Global => logger.write_string("Global")
Section::NamedSection(name) => {
logger.write_string("NamedSection(")
name.output(logger)
logger.write_string(")")
}
}
}

///|
priv struct Key(String) derive(Eq, Hash)

///|
priv struct Value(String) derive(Show)
priv struct Value(String)

///|
impl Show for Value with output(self, logger) {
let Value(value) = self
logger.write_string("Value(")
value.output(logger)
logger.write_string(")")
}

///|
struct IniFile {
Expand Down Expand Up @@ -152,7 +172,7 @@ pub fn IniFile::to_string(self : IniFile) -> String {
'#' => "\\#"
'=' => "\\="
':' => "\\:"
_ if c.is_control() || c.is_whitespace() || not(c.is_printable()) => {
_ if c.is_control() || c.is_whitespace() || !c.is_printable() => {
let unicode = c.to_int().to_string(radix=16)
guard unicode.length() <= 4 else {
abort("Unicode escape sequence too long")
Expand Down Expand Up @@ -257,7 +277,7 @@ test "INIFile::get/basic_functionality" {
test "INIFile::get/case_sensitivity" {
let ini = {
let temp = IniFile::new(is_case_sensitive=true)
temp..set(section="Section", "Key", "value")
temp.set(section="Section", "Key", "value")
temp
}
inspect(ini.get(section="Section", "Key"), content="Some(\"value\")")
Expand All @@ -269,8 +289,8 @@ test "INIFile::get/case_sensitivity" {
test "INIFile::get/empty_strings" {
let ini = {
let temp = IniFile::new()
temp..set(section="", "key", "value")
temp..set(section="section", "", "value")
temp.set(section="", "key", "value")
temp.set(section="section", "", "value")
temp
}
inspect(ini.get(section="", "key"), content="Some(\"value\")")
Expand All @@ -281,12 +301,12 @@ test "INIFile::get/empty_strings" {
test "INIFile::get_bool/true_values" {
let ini = {
let obj = IniFile::new()
obj..set("key1", "true")
obj..set("key2", "yes")
obj..set("key3", "on")
obj..set(section="test", "key4", "TRUE")
obj..set(section="test", "key5", "Yes")
obj..set(section="test", "key6", "ON")
obj.set("key1", "true")
obj.set("key2", "yes")
obj.set("key3", "on")
obj.set(section="test", "key4", "TRUE")
obj.set(section="test", "key5", "Yes")
obj.set(section="test", "key6", "ON")
obj
}
inspect(ini.get_bool("key1"), content="Some(true)")
Expand Down Expand Up @@ -387,19 +407,19 @@ test "INIFile::to_string/escape_special_characters" {
let ini1 = IniFile::new()
kvs
.iter()
.each(fn(kv) {
.each(kv => {
let (key, value) = kv
sections.iter().each(fn(section) { ini1.set(section~, key, value) })
})
let output = ini1.to_string()
let ini2 = parse(output)
kvs
.iter()
.each(fn(kv) {
.each(kv => {
let (key, _) = kv
sections
.iter()
.each(fn(section) {
.each(section => {
let ini1_value = ini1.get(section~, key)
let ini2_value = ini2.get(section~, key)
inspect(ini1_value == ini2_value, content="true")
Expand Down
4 changes: 4 additions & 0 deletions moon.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {
"moonbitlang/core/hashmap",
"moonbitlang/core/string",
}
6 changes: 0 additions & 6 deletions moon.pkg.json

This file was deleted.

40 changes: 32 additions & 8 deletions parser.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ priv enum ReadingValueState {
None
SingleQuote
DoubleQuote
} derive(Show)
}

///|
impl Show for ReadingValueState with output(self, logger) {
match self {
ReadingValueState::None => logger.write_string("None")
ReadingValueState::SingleQuote => logger.write_string("SingleQuote")
ReadingValueState::DoubleQuote => logger.write_string("DoubleQuote")
}
}

///|
priv enum ParsePhase {
Expand All @@ -32,7 +41,22 @@ priv enum ParsePhase {
ReadingKey
ReadingValue(ReadingValueState)
InComment
} derive(Show)
}

///|
impl Show for ParsePhase with output(self, logger) {
match self {
ParsePhase::Start => logger.write_string("Start")
ParsePhase::ReadingSection => logger.write_string("ReadingSection")
ParsePhase::ReadingKey => logger.write_string("ReadingKey")
ParsePhase::ReadingValue(state) => {
logger.write_string("ReadingValue(")
state.output(logger)
logger.write_string(")")
}
ParsePhase::InComment => logger.write_string("InComment")
}
}

///|
priv struct EscapeStateHex {
Expand Down Expand Up @@ -184,7 +208,7 @@ fn IniParseState::handle_section_char(
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)) {
if !self.ctx.sections.contains(self.ctx.current_section) {
self.ctx.sections.set(self.ctx.current_section, @hashmap.new())
}
self.phase = Start
Expand Down Expand Up @@ -221,7 +245,7 @@ fn IniParseState::handle_key_char(
}
'\n' | ';' | '#' => {
let key = self.ctx.buffer.to_string().trim()
if not(key.is_empty()) {
if !key.is_empty() {
let key = self.lower_if_needed(key.to_string())
self.ctx.key = key
self.ctx.buffer.reset()
Expand Down Expand Up @@ -256,7 +280,7 @@ fn IniParseState::handle_value_char(
state.left -= 1
if state.left == 0 {
// it must be 4 digits hex
let code = try! @strconv.parse_int(state.hex.to_string(), base=16)
let code = try! @string.parse_int(state.hex.to_string(), base=16)
self.ctx.buffer.write_char(Int::unsafe_to_char(code))
self.escape_state = EscapeState::None
self.last_char_is_backslash = false
Expand Down Expand Up @@ -299,7 +323,7 @@ fn IniParseState::handle_value_char(
}
if c == '\\' {
self.escape_state = EscapeState::Escape
self.last_char_is_backslash = not(self.last_char_is_backslash) // handle consecutive backslashes
self.last_char_is_backslash = !self.last_char_is_backslash // handle consecutive backslashes
return self
}
match c {
Expand Down Expand Up @@ -362,7 +386,7 @@ fn IniParseState::handle_value_char(
_ if c.is_whitespace() => {
match self.phase {
ReadingValue(ReadingValueState::None) =>
if not(self.ctx.buffer.is_empty()) {
if !self.ctx.buffer.is_empty() {
self.ctx.buffer.write_char(c)
}
ReadingValue(ReadingValueState::SingleQuote) =>
Expand Down Expand Up @@ -413,7 +437,7 @@ fn IniParseState::commit_value(
}
let section = self.ctx.sections.get(self.ctx.current_section).unwrap()
let key = self.ctx.key
guard not(key.is_blank()) else {
guard !key.is_blank() else {
raise IniParseError::ValueWithoutSection(
line=self.ctx.line,
col=self.ctx.col,
Expand Down
Loading