@@ -787,7 +787,7 @@ fn array_separator(i: &mut TokenSlice) -> ModalResult<()> {
787
787
// Normally you need a comma.
788
788
comma_sep,
789
789
// But, if the array is ending, no need for a comma.
790
- peek ( preceded ( opt ( whitespace) , close_bracket) ) . void ( ) ,
790
+ peek ( preceded ( ( opt ( non_code_node ) , opt ( whitespace) ) , close_bracket) ) . void ( ) ,
791
791
) )
792
792
. parse_next ( i)
793
793
}
@@ -800,7 +800,7 @@ pub(crate) fn array_elem_by_elem(i: &mut TokenSlice) -> ModalResult<Node<ArrayEx
800
800
0 ..,
801
801
alt ( (
802
802
terminated ( expression. map ( NonCodeOr :: Code ) , array_separator) ,
803
- terminated ( non_code_node. map ( NonCodeOr :: NonCode ) , whitespace) ,
803
+ terminated ( non_code_node. map ( NonCodeOr :: NonCode ) , opt ( whitespace) ) ,
804
804
) ) ,
805
805
)
806
806
. context ( expected ( "array contents, a list of elements (like [1, 2, 3])" ) )
@@ -4841,6 +4841,26 @@ export fn cos(num: number(rad)): number(_) {}"#;
4841
4841
let _arr = array_elem_by_elem ( & mut tokens. as_slice ( ) ) . unwrap ( ) ;
4842
4842
}
4843
4843
4844
+ #[ test]
4845
+ fn array_no_trailing_comma_with_comment ( ) {
4846
+ let program = r#"[
4847
+ 1, // one
4848
+ 2, // two
4849
+ 3 // three
4850
+ ]"# ;
4851
+ let module_id = ModuleId :: default ( ) ;
4852
+ let tokens = crate :: parsing:: token:: lex ( program, module_id) . unwrap ( ) ;
4853
+ let _arr = array_elem_by_elem ( & mut tokens. as_slice ( ) ) . unwrap ( ) ;
4854
+ }
4855
+
4856
+ #[ test]
4857
+ fn array_block_comment_no_whitespace ( ) {
4858
+ let program = r#"[1/* comment*/]"# ;
4859
+ let module_id = ModuleId :: default ( ) ;
4860
+ let tokens = crate :: parsing:: token:: lex ( program, module_id) . unwrap ( ) ;
4861
+ let _arr = array_elem_by_elem ( & mut tokens. as_slice ( ) ) . unwrap ( ) ;
4862
+ }
4863
+
4844
4864
#[ test]
4845
4865
fn basic_if_else ( ) {
4846
4866
let some_program_string = "if true {
0 commit comments