Skip to content

Commit

Permalink
Relax apply statement grammar to allow ws before trait
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Aug 4, 2022
1 parent 4258444 commit 9c5fbc7
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/source-2.0/spec/idl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ string support defined in `RFC 5234 <https://www.rfc-editor.org/rfc/rfc7405>`_.
TraitStructure :`TraitStructureKvp` *(*`WS` `TraitStructureKvp`)
TraitStructureKvp :`NodeObjectKey` *`WS` ":" *`WS` `NodeValue`
ApplyStatement :(`ApplyStatementSingular` / `ApplyStatementBlock`)
ApplyStatementSingular :%s"apply" `SP` `ShapeId` `SP` `Trait` `BR`
ApplyStatementBlock :%s"apply" `SP` `ShapeId` `SP` "{" `TraitStatements` "}" `BR`
ApplyStatementSingular :%s"apply" `WS` `ShapeId` `WS` `Trait` `BR`
ApplyStatementBlock :%s"apply" `SP` `ShapeId` `WS` "{" `TraitStatements` "}" `BR`
.. rubric:: Shape ID

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,24 @@ public void ws() {
}

// required space
public void rsp() {
private void rsp() {
int cc = column();
sp();
if (column() == cc) {
throw syntax("Expected one or more spaces");
}
}

// Required whitespace.
private void rws() {
int line = line();
int column = column();
ws();
if (line() == line && column == column()) {
throw syntax("Expected one or more whitespace characters");
}
}

@Override
public void sp() {
while (isSpaceOrComma(peek())) {
Expand Down Expand Up @@ -1122,10 +1132,10 @@ private void parseApplyStatement() {
expect('p');
expect('l');
expect('y');
rsp();
sp();

String name = ParserUtils.parseShapeId(this);
rsp();
rws();

// Account for singular or block apply statements.
List<TraitEntry> traitsToApply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static boolean compareEvents(ValidationEvent expected, ValidationEvent a
normalizedActualMessage += " (" + actual.getSuppressionReason().get() + ")";
}

String comparedMessage = expected.getMessage().replace("\n", "\\n");
String comparedMessage = expected.getMessage().replace("\n", "\\n").replace("\r", "\\n");
return expected.getSeverity() == actual.getSeverity()
&& expected.getId().equals(actual.getId())
&& expected.getShapeId().equals(actual.getShapeId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Parse error at line 5, column 10 near `{ `: Expected one or more spaces | Model
// Parse error at line 5, column 10 near `{ `: Expected one or more whitespace characters | Model
$version: "2.0"
namespace smithy.example

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Parse error at line 4, column 17 near `//`: Expected: '@', but found '/' | Model
// Parse error at line 5, column 1 near `string`: Expected: '@', but found 's'
namespace com.foo

apply SomeShape // comment so spaces aren't eaten
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Parse error at line 6, column 5 near `$m`: Members can only elide targets in IDL version 2 or later
// Members can only elide targets in IDL version 2 or later
$version: "1.0"
namespace smithy.example

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Parse error at line 6, column 9 near `\n}`: Members can only elide targets in IDL version 2 or later
// Members can only elide targets in IDL version 2 or later
$version: "1.0"
namespace smithy.example

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Parse error at line 3, column 9 near `\nf`: Expected one or more spaces | Model
// Parse error at line 3, column 9
$version: "2.0"
metadata
foo = "bar"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Parse error at line 5, column 10 near `\nF`: Expected one or more spaces | Model
// Parse error at line 5, column 10
$version: "2.0"
namespace smithy.example

Expand Down

0 comments on commit 9c5fbc7

Please sign in to comment.