Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cedar-policy-core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,20 +1190,20 @@ mod tests {
"permit(principal,",
"unexpected end of input",
"",
"expected identifier",
"expected `)` or identifier",
);
assert_labeled_span(
"permit(principal,action,",
"unexpected end of input",
"",
"expected identifier",
"expected `)` or identifier",
);
// Nothing will actually convert to an AST here.
assert_labeled_span(
"permit(principal,action,resource,",
"unexpected end of input",
"",
"expected identifier",
"expected `)` or identifier",
);
// We still list out `if` as an expected token because it doesn't get
// parsed as an ident in this position.
Expand Down
12 changes: 7 additions & 5 deletions cedar-policy-core/src/parser/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ match {
}

Comma<E>: Vec<E> = {
<e:E?> => e.into_iter().collect(),
<mut es:(<E> ",")+> <e:E> => {
es.push(e);
es
},
<mut es:(<E> ",")*> <e:E?> => match e {
None => es,
Some(e) => {
es.push(e);
es
}
}
}

// Policies := {Policy}
Expand Down
22 changes: 18 additions & 4 deletions cedar-policy-core/src/parser/text_to_cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ mod tests {
src,
&errs,
&ExpectedErrorMessageBuilder::error("unexpected token `!`")
.exactly_one_underline_with_label("!", "expected identifier")
.exactly_one_underline_with_label("!", "expected `)` or identifier")
.build(),
);

Expand All @@ -1269,14 +1269,14 @@ mod tests {
src,
&errs,
&ExpectedErrorMessageBuilder::error("unexpected token `!`")
.exactly_one_underline_with_label("!", "expected identifier")
.exactly_one_underline_with_label("!", "expected `)` or identifier")
.build(),
);
expect_some_error_matches(
src,
&errs,
&ExpectedErrorMessageBuilder::error("unexpected token `+`")
.exactly_one_underline_with_label("+", "expected identifier")
.exactly_one_underline_with_label("+", "expected `)` or identifier")
.build(),
);
expect_n_errors(src, &errs, 2);
Expand All @@ -1290,7 +1290,7 @@ mod tests {
src,
&errs,
&ExpectedErrorMessageBuilder::error("unexpected token `!`")
.exactly_one_underline_with_label("!", "expected identifier")
.exactly_one_underline_with_label("!", "expected `)` or identifier")
.build(),
);
}
Expand Down Expand Up @@ -1721,6 +1721,20 @@ mod tests {
}
}

#[test]
fn trailing_comma() {
assert_parse_succeeds(
parse_policy,
r#"
permit(principal, action, resource,);
"#,
);
assert_parse_succeeds(parse_expr, r#"foo(a, b, c,)"#);
assert_parse_succeeds(parse_expr, r#"[A, B, C,]"#);
assert_parse_succeeds(parse_expr, r#"{ A: B, C: D, }"#);
assert_parse_succeeds(parse_ref, r#"Principal::{uid: "123", role: "admin",}"#);
}

#[test]
#[cfg(feature = "tolerant-ast")]
fn policies_tolerant_success() {
Expand Down
2 changes: 2 additions & 0 deletions cedar-policy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Cedar Language Version: TBD
`PolicySet`, `Policy`, and `Template`. These APIs don't retain source code information, trading detailed error
reporting for reduced memory usage and faster parsing. The feature is only intended for use with raw parsing
APIs, as regular parsing performance is degraded when the `raw-parsing` feature is enabled.
- Implemented [RFC 71 (trailing commas)](https://github.com/cedar-policy/rfcs/blob/main/text/0071-trailing-commas.md)
for Cedar policy files. (#1606)

### Changed

Expand Down