Skip to content

Commit

Permalink
fix: wording on unexpected character in arrays and objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPridham authored and jtran committed Feb 2, 2025
1 parent e877db0 commit 620ea21
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/lang/abstractSyntaxTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ describe('parsing errors', () => {
const result = parse(code)
if (err(result)) throw result
const error = result.errors[0]
expect(error.message).toBe('Array is missing a closing bracket(`]`)')
expect(error.sourceRange).toEqual([28, 29, 0])
expect(error.message).toBe(
'Unexpected character encountered. You might be missing a comma in between elements.'
)
expect(error.sourceRange).toEqual([29, 31, 0])
})
})
33 changes: 27 additions & 6 deletions src/wasm-lib/kcl/src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ pub(crate) fn array_elem_by_elem(i: &mut TokenSlice) -> PResult<Node<ArrayExpres
context: vec![],
cause: Some(CompilationError::fatal(
start_range,
"Array is missing a comma in between elements",
"Unexpected character encountered. You might be missing a comma in between elements.",
)),
};
return Err(ErrMode::Cut(e));
Expand Down Expand Up @@ -943,7 +943,7 @@ pub(crate) fn object(i: &mut TokenSlice) -> PResult<Node<ObjectExpression>> {
context: vec![],
cause: Some(CompilationError::fatal(
start_range,
"Object is missing a comma in between properties",
"Unexpected character encountered. You might be missing a comma in between properties.",
)),
};
return Err(ErrMode::Cut(e));
Expand Down Expand Up @@ -3917,7 +3917,7 @@ z(-[["#,
assert_err(
r#"zz({{{{{{{{)iegAng{{{{{{{##"#,
"Object is missing a closing brace(`}`)",
[2, 3],
[3, 4],
);
}

Expand Down Expand Up @@ -4491,10 +4491,20 @@ sketch001 = startSketchOn('XZ') |> startProfileAt([90.45, 119.09, %)"#;
sketch001 = startSketchOn('XZ') |> startProfileAt([90.45 119.09], %)"#;
assert_err(
some_program_string,
"Array is missing a comma in between elements",
"Unexpected character encountered. You might be missing a comma in between elements.",
[52, 65],
);
}
#[test]
fn test_parse_array_random_brace() {
let some_program_string = r#"
sketch001 = startSketchOn('XZ') |> startProfileAt([}], %)"#;
assert_err(
some_program_string,
"Unexpected character encountered. You might be missing a comma in between elements.",
[52, 54],
);
}

#[test]
fn test_parse_object_missing_closing_brace() {
Expand All @@ -4514,11 +4524,22 @@ sketch001 = startSketchOn('XZ') |> startProfileAt([90.45 119.09], %)"#;

assert_err(
some_program_string,
"Object is missing a comma in between properties",
"Unexpected character encountered. You might be missing a comma in between properties.",
[37, 78],
);
}

#[test]
fn test_parse_object_random_bracket() {
let some_program_string = r#"{]}"#;

assert_err(
some_program_string,
"Unexpected character encountered. You might be missing a comma in between properties.",
[1, 3],
);
}

#[test]
fn test_parse_object_shorthand_missing_comma() {
let some_program_string = r#"
Expand All @@ -4531,7 +4552,7 @@ bar = 1

assert_err(
some_program_string,
"Object is missing a comma in between properties",
"Unexpected character encountered. You might be missing a comma in between properties.",
[54, 89],
);
}
Expand Down

0 comments on commit 620ea21

Please sign in to comment.