Skip to content

Fails to parse number with + prefix #38

@polarathene

Description

@polarathene

While this is a JSON5 feature rather than JSONC, the parser seems to implement support but fails?:

let parsed = jsonc_parser::parse_to_value(r#"{ "test": +42 }"#, &Default::default());
println!("{:#?}", parsed);

Outputs error:

Err(
    ParseError {
        range: Range {
            start: 10,
            end: 11,
        },
        message: "Unexpected token",
        display_message: "Unexpected token on line 1 column 11.",
    },
)

jsonc-parser/src/scanner.rs

Lines 272 to 293 in abd65a8

match self.current_char() {
Some('e') | Some('E') => {
match self.move_next_char() {
Some('-') | Some('+') => {
self.move_next_char();
if !self.is_digit() {
return Err(self.create_error_for_current_char("Expected a digit"));
}
}
_ => {
if !self.is_digit() {
return Err(self.create_error_for_current_char("Expected plus, minus, or digit in number literal"));
}
}
}
while self.is_digit() {
self.move_next_char();
}
}
_ => {}
}


Or is this observation a misunderstanding? (it was first noted here)

It does seem accurate that this crate is more of a JSON5 parser than a JSONC one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions