Skip to content

Commit

Permalink
tweak (moonbitlang#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang authored Jun 27, 2024
1 parent 6408a46 commit ea17168
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions json/lex_misc.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn read_char(ctx : ParseContext) -> Char? {
}
}

fn lex_skip_whitespace(ctx : ParseContext) -> Result[Unit, ParseError] {
fn lex_skip_whitespace(ctx : ParseContext) -> Unit {
for ; ; {
match read_char(ctx) {
Some('\t' | '\u000B' | '\u000C' | ' ' | '\n' | '\r') => continue
Expand All @@ -42,15 +42,15 @@ fn lex_skip_whitespace(ctx : ParseContext) -> Result[Unit, ParseError] {
continue
}
ctx.offset -= 1
return Ok(())
break
}
None => return Ok(())
None => break
}
}
}

fn lex_after_array_value(ctx : ParseContext) -> Result[Token, ParseError] {
lex_skip_whitespace(ctx)?
lex_skip_whitespace(ctx)
match read_char(ctx) {
Some(']') => Ok(Token::RBracket)
Some(',') => Ok(Token::Comma)
Expand All @@ -60,7 +60,7 @@ fn lex_after_array_value(ctx : ParseContext) -> Result[Token, ParseError] {
}

fn lex_after_property_name(ctx : ParseContext) -> Result[Token, ParseError] {
lex_skip_whitespace(ctx)?
lex_skip_whitespace(ctx)
match read_char(ctx) {
Some(':') => Ok(Token::Colon)
Some(_) => Err(invalid_char(ctx, shift=-1))
Expand All @@ -69,7 +69,7 @@ fn lex_after_property_name(ctx : ParseContext) -> Result[Token, ParseError] {
}

fn lex_after_object_value(ctx : ParseContext) -> Result[Token, ParseError] {
lex_skip_whitespace(ctx)?
lex_skip_whitespace(ctx)
match read_char(ctx) {
Some('}') => Ok(Token::RBrace)
Some(',') => Ok(Token::Comma)
Expand All @@ -86,7 +86,7 @@ fn lex_assert_char(ctx : ParseContext, c : Char) -> Result[Unit, ParseError] {
}

fn lex_property_name(ctx : ParseContext) -> Result[Token, ParseError] {
lex_skip_whitespace(ctx)?
lex_skip_whitespace(ctx)
match read_char(ctx) {
Some('}') => Ok(RBrace)
Some('"') => {
Expand All @@ -99,7 +99,7 @@ fn lex_property_name(ctx : ParseContext) -> Result[Token, ParseError] {
}

fn lex_property_name2(ctx : ParseContext) -> Result[Token, ParseError] {
lex_skip_whitespace(ctx)?
lex_skip_whitespace(ctx)
match read_char(ctx) {
Some('"') => {
let s = lex_string(ctx)?
Expand Down
2 changes: 1 addition & 1 deletion json/parse.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn valid(input : String) -> Bool {
pub fn parse(input : String) -> Result[JsonValue, ParseError] {
let ctx = ParseContext::make(input)
let val = parse_value(ctx)?
lex_skip_whitespace(ctx)?
lex_skip_whitespace(ctx)
if ctx.offset >= ctx.end_offset {
Ok(val)
} else {
Expand Down

0 comments on commit ea17168

Please sign in to comment.