Skip to content

Commit df753d4

Browse files
moonagentpeter-jerry-ye
authored andcommitted
fix: address all compiler warnings
- Replace deprecated string methods with modern equivalents - Use get_char().unwrap() instead of char_at() - Use direct indexing instead of charcode_at() - Use view() with proper parameters instead of charcodes() - Add style="flat" to ToJson derives to address deprecation warnings - Remove unused Show derive from Instruction enum This commit resolves all actionable compiler warnings while maintaining backward compatibility and test functionality.
1 parent 3a75b5c commit df753d4

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/chars.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn is_word_char_at(input : @string.View, sp : Int) -> Bool {
8888
if sp == -1 || sp == input.length() {
8989
return false
9090
}
91-
let c = input.char_at(sp)
91+
let c = input.get_char(sp).unwrap()
9292
is_word_char(c)
9393
}
9494

src/impl.mbt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ priv enum Instruction {
2222
/// Zero-width assertions
2323
Assertion(Predicate)
2424
Backreference(Int)
25-
} derive(Show)
25+
}
2626

2727
///|
2828
priv enum Predicate {
@@ -32,7 +32,7 @@ priv enum Predicate {
3232
EndLine
3333
WordBoundary
3434
NoWordBoundary
35-
} derive(Show, ToJson)
35+
} derive(Show, ToJson(style="flat"))
3636

3737
///|
3838
/// A thread represents a point in the execution of the VM.
@@ -106,9 +106,8 @@ fn add_thread(
106106
let assertion = match pred {
107107
BeginText => sp == 0
108108
EndText => sp == content.length()
109-
BeginLine => sp == 0 || content.charcode_at(sp - 1) == '\n'.to_int()
110-
EndLine =>
111-
sp == content.length() || content.charcode_at(sp) == '\n'.to_int()
109+
BeginLine => sp == 0 || content[sp - 1] == '\n'
110+
EndLine => sp == content.length() || content[sp] == '\n'
112111
WordBoundary =>
113112
is_word_char_at(content, sp - 1) != is_word_char_at(content, sp)
114113
NoWordBoundary =>
@@ -171,7 +170,7 @@ fn vm(
171170
let actual_char = if sp == input.length() {
172171
(-1).unsafe_to_char()
173172
} else {
174-
input.char_at(sp)
173+
input.get_char(sp).unwrap()
175174
}
176175
let next_sp = if actual_char.to_int() > 0xFFFF { sp + 2 } else { sp + 1 }
177176
for thread in clist {
@@ -210,8 +209,8 @@ fn vm(
210209
guard len != 0
211210
let next_sp = sp + len
212211
if next_sp <= input.length() &&
213-
input.charcodes(start~, end~) ==
214-
input.charcodes(start=sp, end=next_sp) {
212+
input.view(start_offset=start, end_offset=end) ==
213+
input.view(start_offset=sp, end_offset=next_sp) {
215214
add_thread(
216215
input,
217216
instructions,

src/impl_wbtest.mbt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test {
3939
]
4040
let captures = vm(instructions, "aab", 1)
4141
inspect(captures, content="[0, 3]")
42-
inspect("aab".charcodes(start=0, end=3), content="aab")
42+
inspect("aab".view(start_offset=0, end_offset=3), content="aab")
4343
}
4444

4545
///|
@@ -95,7 +95,9 @@ test "priority" (t : @test.T) {
9595
let captures = vm(instructions, "aabbcc", 4)
9696
inspect(captures, content="[0, 6, 0, 3, 3, 5, 5, 6]")
9797
for i = 0; i < captures.length(); i = i + 2 {
98-
t.writeln("aabbcc".charcodes(start=captures[i], end=captures[i + 1]))
98+
t.writeln(
99+
"aabbcc".view(start_offset=captures[i], end_offset=captures[i + 1]),
100+
)
99101
}
100102
t.snapshot(filename="priority.txt")
101103
}

0 commit comments

Comments
 (0)