Skip to content

Commit 6ef1a8c

Browse files
committed
fix
1 parent a6bfc0f commit 6ef1a8c

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

parser.mbt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// Simplified version based on js-yaml v3.13.1
44
55
// Parser state
6-
struct ParserState {
6+
priv struct ParserState {
77
input : String
88
mut position : Int
99
mut line : Int
@@ -69,12 +69,12 @@ fn ParserState::skip_whitespace(self : ParserState) -> Unit {
6969
fn ParserState::read_until(
7070
self : ParserState,
7171
predicate : (Int) -> Bool,
72-
) -> String {
72+
) -> String raise {
7373
let start = self.position
7474
while self.position < self.length && predicate(self.current_char()) {
7575
self.advance()
7676
}
77-
self.input.substring(start~, end=self.position)
77+
self.input[start:self.position].to_string()
7878
}
7979

8080
///|
@@ -92,7 +92,7 @@ fn sanitize_input_internal(input : String) -> String {
9292

9393
///|
9494
/// Parse a scalar value
95-
fn parse_scalar(state : ParserState) -> YamlValue raise YamlParseError {
95+
fn parse_scalar(state : ParserState) -> YamlValue raise {
9696
state.skip_whitespace()
9797
if state.current_char() == 0 {
9898
return YamlValue::Null
@@ -128,11 +128,11 @@ fn parse_double_quoted_string(
128128
0x09 => result += "\t" // \t
129129
_ => {
130130
result += "\\"
131-
result += Char::from_int(escaped).to_string()
131+
result += Int::unsafe_to_char(escaped).to_string()
132132
}
133133
}
134134
} else {
135-
result += Char::from_int(ch).to_string()
135+
result += Int::unsafe_to_char(ch).to_string()
136136
}
137137
state.advance()
138138
}
@@ -159,7 +159,7 @@ fn parse_single_quoted_string(
159159
state.advance()
160160
state.advance()
161161
} else {
162-
result += Char::from_int(ch).to_string()
162+
result += Int::unsafe_to_char(ch).to_string()
163163
state.advance()
164164
}
165165
}
@@ -173,7 +173,7 @@ fn parse_single_quoted_string(
173173

174174
///|
175175
/// Parse plain scalar (unquoted)
176-
fn parse_plain_scalar(state : ParserState) -> YamlValue {
176+
fn parse_plain_scalar(state : ParserState) -> YamlValue raise {
177177
let text = state.read_until(fn(ch) {
178178
!is_whitespace_or_eol(ch) &&
179179
!is_flow_indicator(ch) &&
@@ -247,7 +247,7 @@ fn contains_dot(text : String) -> Bool {
247247

248248
///|
249249
/// Simple integer parsing
250-
fn parse_int_simple(text : @string.View) -> Int {
250+
fn parse_int_simple(text : StringView) -> Int {
251251
let mut result = 0
252252
let mut negative = false
253253
let start = if text[0] == 45 { // 45 is '-'
@@ -295,7 +295,7 @@ fn power_of_10(n : Int) -> Int {
295295

296296
///|
297297
/// Parse array (sequence)
298-
fn parse_array(state : ParserState) -> YamlValue raise YamlParseError {
298+
fn parse_array(state : ParserState) -> YamlValue raise {
299299
state.advance() // Skip '['
300300
state.skip_whitespace()
301301
let result = []
@@ -325,7 +325,7 @@ fn parse_array(state : ParserState) -> YamlValue raise YamlParseError {
325325

326326
///|
327327
/// Parse object (mapping)
328-
fn parse_object(state : ParserState) -> YamlValue raise YamlParseError {
328+
fn parse_object(state : ParserState) -> YamlValue raise {
329329
state.advance() // Skip '{'
330330
state.skip_whitespace()
331331
let result = Map::new()
@@ -372,7 +372,7 @@ fn parse_object(state : ParserState) -> YamlValue raise YamlParseError {
372372

373373
///|
374374
/// Parse any YAML value
375-
fn parse_value(state : ParserState) -> YamlValue raise YamlParseError {
375+
fn parse_value(state : ParserState) -> YamlValue raise {
376376
state.skip_whitespace()
377377
let ch = state.current_char()
378378
if ch == 0 {
@@ -408,9 +408,7 @@ fn ParserState::skip_document_separator(self : ParserState) -> Unit {
408408

409409
///|
410410
/// Read all documents from the input
411-
fn ParserState::read_documents(
412-
self : ParserState,
413-
) -> Array[YamlValue] raise YamlParseError {
411+
fn ParserState::read_documents(self : ParserState) -> Array[YamlValue] raise {
414412
let documents = []
415413
self.skip_whitespace()
416414

@@ -439,7 +437,7 @@ fn ParserState::read_documents(
439437
pub fn parse(
440438
content : String,
441439
options? : ParseOptions = ParseOptions::new(),
442-
) -> YamlValue raise YamlParseError {
440+
) -> YamlValue raise {
443441
let state = ParserState::new(content, options)
444442

445443
// Use read_documents to get all documents
@@ -461,7 +459,7 @@ pub fn parse(
461459
pub fn parse_all(
462460
content : String,
463461
options? : ParseOptions = ParseOptions::new(),
464-
) -> Array[YamlValue] raise YamlParseError {
462+
) -> Array[YamlValue] raise {
465463
let state = ParserState::new(content, options)
466464
state.read_documents()
467465
}

pkg.generated.mbti

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ fn pad_string(String, Int) -> String
148148

149149
fn pairs_type() -> YamlType[Array[(String, YamlValue)]]
150150

151-
fn parse(String, options? : ParseOptions) -> YamlValue raise YamlParseError
151+
fn parse(String, options? : ParseOptions) -> YamlValue raise
152152

153-
fn parse_all(String, options? : ParseOptions) -> Array[YamlValue] raise YamlParseError
153+
fn parse_all(String, options? : ParseOptions) -> Array[YamlValue] raise
154154

155155
fn process_folded_string(String) -> String
156156

157-
fn process_literal_string(String) -> String
157+
fn process_literal_string(String) -> String raise
158158

159159
fn resolve_scalar(String, Schema) -> YamlValue
160160

@@ -221,6 +221,11 @@ pub enum KindType {
221221
Scalar
222222
Mapping
223223
}
224+
fn KindType::equal(Self, Self) -> Bool // from trait `Eq`
225+
#deprecated
226+
fn KindType::op_equal(Self, Self) -> Bool // from trait `Eq`
227+
fn KindType::output(Self, &Logger) -> Unit // from trait `Show`
228+
fn KindType::to_string(Self) -> String // from trait `Show`
224229
impl Eq for KindType
225230
impl Show for KindType
226231

@@ -232,13 +237,16 @@ pub struct ParseOptions {
232237
fn ParseOptions::default() -> Self
233238
fn ParseOptions::new() -> Self
234239

235-
type ParserState
236-
237240
pub struct Position {
238241
line : Int
239242
column : Int
240243
index : Int
241244
}
245+
fn Position::equal(Self, Self) -> Bool // from trait `Eq`
246+
#deprecated
247+
fn Position::op_equal(Self, Self) -> Bool // from trait `Eq`
248+
fn Position::output(Self, &Logger) -> Unit // from trait `Show`
249+
fn Position::to_string(Self) -> String // from trait `Show`
242250
impl Eq for Position
243251
impl Show for Position
244252

@@ -255,6 +263,11 @@ pub enum SchemaType {
255263
Default
256264
Extended
257265
}
266+
fn SchemaType::equal(Self, Self) -> Bool // from trait `Eq`
267+
#deprecated
268+
fn SchemaType::op_equal(Self, Self) -> Bool // from trait `Eq`
269+
fn SchemaType::output(Self, &Logger) -> Unit // from trait `Show`
270+
fn SchemaType::to_string(Self) -> String // from trait `Show`
258271
impl Eq for SchemaType
259272
impl Show for SchemaType
260273

@@ -272,6 +285,8 @@ pub struct StringifyOptions {
272285
condense_flow : Bool
273286
}
274287
fn StringifyOptions::default() -> Self
288+
fn StringifyOptions::output(Self, &Logger) -> Unit // from trait `Show`
289+
fn StringifyOptions::to_string(Self) -> String // from trait `Show`
275290
impl Show for StringifyOptions
276291

277292
pub enum StyleVariant {
@@ -288,6 +303,11 @@ pub enum StyleVariant {
288303
DoubleQuoted
289304
SingleQuoted
290305
}
306+
fn StyleVariant::equal(Self, Self) -> Bool // from trait `Eq`
307+
#deprecated
308+
fn StyleVariant::op_equal(Self, Self) -> Bool // from trait `Eq`
309+
fn StyleVariant::output(Self, &Logger) -> Unit // from trait `Show`
310+
fn StyleVariant::to_string(Self) -> String // from trait `Show`
291311
impl Eq for StyleVariant
292312
impl Show for StyleVariant
293313

@@ -305,6 +325,11 @@ pub enum YamlError {
305325
ResolveError(String)
306326
ConstructError(String)
307327
}
328+
fn YamlError::equal(Self, Self) -> Bool // from trait `Eq`
329+
#deprecated
330+
fn YamlError::op_equal(Self, Self) -> Bool // from trait `Eq`
331+
fn YamlError::output(Self, &Logger) -> Unit // from trait `Show`
332+
fn YamlError::to_string(Self) -> String // from trait `Show`
308333
impl Eq for YamlError
309334
impl Show for YamlError
310335

@@ -327,6 +352,11 @@ pub enum YamlValue {
327352
Array(Array[YamlValue])
328353
Object(Map[String, YamlValue])
329354
}
355+
fn YamlValue::equal(Self, Self) -> Bool // from trait `Eq`
356+
#deprecated
357+
fn YamlValue::op_equal(Self, Self) -> Bool // from trait `Eq`
358+
fn YamlValue::output(Self, &Logger) -> Unit // from trait `Show`
359+
fn YamlValue::to_string(Self) -> String // from trait `Show`
330360
impl Eq for YamlValue
331361
impl Show for YamlValue
332362

schema.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn str_yaml_type() -> YamlType[YamlValue] {
109109
}
110110
}),
111111
default_style: None,
112-
resolve: fn(value) {
112+
resolve: fn(_) {
113113
true // Strings always resolve to themselves
114114
},
115115
construct: fn(value) {

utils.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub fn process_folded_string(s : String) -> String {
518518
///|
519519
/// Process literal string (YAML |)
520520
/// Preserves line breaks exactly as written
521-
pub fn process_literal_string(s : String) -> String {
521+
pub fn process_literal_string(s : String) -> String raise {
522522
// Remove common leading indentation
523523
let lines = split_lines(s)
524524
if lines.length() == 0 {
@@ -548,7 +548,7 @@ pub fn process_literal_string(s : String) -> String {
548548
processed_lines.push("")
549549
} else {
550550
let spaces_to_remove = min_indent.min(count_leading_whitespace(line))
551-
processed_lines.push(line.substring(start=spaces_to_remove))
551+
processed_lines.push(line[spaces_to_remove:].to_string())
552552
}
553553
}
554554
processed_lines.join("\n")
@@ -1096,7 +1096,7 @@ pub fn is_yaml_empty(value : YamlValue) -> Bool {
10961096
Null => true
10971097
String(s) => s.length() == 0
10981098
Array(arr) => arr.length() == 0
1099-
Object(obj) => obj.size() == 0
1099+
Object(obj) => obj.length() == 0
11001100
_ => false
11011101
}
11021102
}

0 commit comments

Comments
 (0)