Skip to content

Commit

Permalink
Address IDL CR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Dec 10, 2019
1 parent 04a1f70 commit 02aee1a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 51 deletions.
2 changes: 0 additions & 2 deletions docs/source/spec/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2365,8 +2365,6 @@ Consider the following metadata definition:
String: String,
}
string String
The object key remains the same literal string value of ``String`` while the
value is treated as a shape ID and resolves to the string literal
``"smithy.api#String"``. This IDL model is equivalent to the following
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,55 @@ private Token expect(TokenType... tokens) {
}
}

/**
* Tests if a lookahead token matches the given type.
*
* @param type Token type to test for.
* @return Returns true if the next token is of the given type.
*/
private boolean test(TokenType type) {
return !eof() && lexer.peek().type == type;
}

/**
* Peeks at the next token.
*
* @return Returns the optionally present next token.
*/
private Optional<Token> peek() {
return Optional.ofNullable(lexer.peek());
}

/**
* Expects either EOF or that the next token is on a new line.
*/
private void expectNewline() {
if (peek().isPresent() && peek().get().line == current().line) {
next();
throw syntax("Expected a new line before this token");
}
}

/**
* Creates a syntax error using the provided message.
*
* @param message Syntax error message.
* @return Returns the created syntax error.
*/
private ModelSyntaxException syntax(String message) {
return syntax(message, 0);
}

private ModelSyntaxException syntax(String message, int offset) {
Token token = current();
int line = token.line;
int column = token.column + offset;
String lexeme = token.lexeme;
String formatted = format(
"Parse error at line %d, column %d near `%s`: %s", line, column, lexeme, message);
return new ModelSyntaxException(formatted, new SourceLocation(filename, line, column));
}

private void parseService() {
SourceLocation sourceLocation = currentLocation();
ShapeId shapeId = parseShapeName();
Expand Down Expand Up @@ -827,53 +876,4 @@ private void parseOperation() {

expectNewline();
}

/**
* Tests if a lookahead token matches the given type.
*
* @param type Token type to test for.
* @return Returns true if the next token is of the given type.
*/
private boolean test(TokenType type) {
return !eof() && lexer.peek().type == type;
}

/**
* Peeks at the next token.
*
* @return Returns the optionally present next token.
*/
private Optional<Token> peek() {
return Optional.ofNullable(lexer.peek());
}

/**
* Expects either EOF or that the next token is on a new line.
*/
private void expectNewline() {
if (peek().isPresent() && peek().get().line == current().line) {
next();
throw syntax("Expected a new line before this token");
}
}

/**
* Creates a syntax error using the provided message.
*
* @param message Syntax error message.
* @return Returns the created syntax error.
*/
private ModelSyntaxException syntax(String message) {
return syntax(message, 0);
}

private ModelSyntaxException syntax(String message, int offset) {
Token token = current();
int line = token.line;
int column = token.column + offset;
String lexeme = token.lexeme;
String formatted = format(
"Parse error at line %d, column %d near `%s`: %s", line, column, lexeme, message);
return new ModelSyntaxException(formatted, new SourceLocation(filename, line, column));
}
}

0 comments on commit 02aee1a

Please sign in to comment.