Skip to content

Commit

Permalink
fix(compiler): Parse array set with newline correctly (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Sep 25, 2021
1 parent e80de43 commit 14e1822
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/parsing/parser.dyp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ array_get :
| left_accessor_expr lbrack expr rbrack { Exp.array_get ~loc:(symbol_rloc dyp) $1 $3 }

array_set :
| expr lbrack expr rbrack equal eols? expr { Exp.array_set ~loc:(symbol_rloc dyp) $1 $3 $7 }
| expr lbrack expr rbrack equal expr { Exp.array_set ~loc:(symbol_rloc dyp) $1 $3 $6 }

record_get :
| left_accessor_expr dot simple_id { no_uppercase_ident $1; Exp.record_get $1 $3 }
Expand Down
24 changes: 24 additions & 0 deletions compiler/test/suites/arrays.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe("arrays", ({test}) => {
let assertCompileError = makeCompileErrorRunner(test);
let assertRun = makeRunner(test);
let assertRunError = makeErrorRunner(test);
let assertParse = makeParseRunner(test);

assertRun("array1", "print([> 1, 2, 3])", "[> 1, 2, 3]\n");
assertRun("array2", "print([>])", "[> ]\n");
Expand Down Expand Up @@ -79,4 +80,27 @@ describe("arrays", ({test}) => {
"[> ,]",
"Error: Syntax error",
);
// parsing
Grain_parsing.(
Ast_helper.(
assertParse(
"issue_925_parse_array_set_newline",
"state[0] =
5",
{
statements: [
Top.expr(
Exp.array_set(
Exp.ident(Location.mknoloc(Identifier.IdentName("state"))),
Exp.constant(Const.number(PConstNumberInt("0"))),
Exp.constant(Const.number(PConstNumberInt("5"))),
),
),
],
comments: [],
prog_loc: Location.dummy_loc,
},
)
)
);
});

0 comments on commit 14e1822

Please sign in to comment.