aboutsummaryrefslogtreecommitdiff
path: root/java/com
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2018-12-14 15:36:51 -0800
committerLiam Miller-Cushon <cushon@google.com>2019-01-28 21:35:24 -0800
commit49fc8eaf64a247dc8e93127e7bb9344a1c7d5c6d (patch)
treed7d5195be5670a18093d53aeba597880ef86fecf /java/com
parent31a1bf1ff7a7b2c216249a53fb5415f18dd94e46 (diff)
downloadturbine-49fc8eaf64a247dc8e93127e7bb9344a1c7d5c6d.tar.gz
Report diagnostics for unterminated expressions at the beginning of the expression instead of at the end of the file, which is probably farther from the problem.
MOE_MIGRATED_REVID=225615449
Diffstat (limited to 'java/com')
-rw-r--r--java/com/google/turbine/diag/TurbineError.java1
-rw-r--r--java/com/google/turbine/parse/Parser.java9
2 files changed, 9 insertions, 1 deletions
diff --git a/java/com/google/turbine/diag/TurbineError.java b/java/com/google/turbine/diag/TurbineError.java
index e13eb44..b8b2a54 100644
--- a/java/com/google/turbine/diag/TurbineError.java
+++ b/java/com/google/turbine/diag/TurbineError.java
@@ -30,6 +30,7 @@ public class TurbineError extends Error {
UNEXPECTED_EOF("unexpected end of input"),
UNTERMINATED_STRING("unterminated string literal"),
UNTERMINATED_CHARACTER_LITERAL("unterminated char literal"),
+ UNTERMINATED_EXPRESSION("unterminated expression, expected ';' not found"),
EMPTY_CHARACTER_LITERAL("empty char literal"),
EXPECTED_TOKEN("expected token %s"),
INVALID_LITERAL("invalid literal: %s"),
diff --git a/java/com/google/turbine/parse/Parser.java b/java/com/google/turbine/parse/Parser.java
index 245ced8..ff3cc3e 100644
--- a/java/com/google/turbine/parse/Parser.java
+++ b/java/com/google/turbine/parse/Parser.java
@@ -20,6 +20,7 @@ import static com.google.turbine.parse.Token.COMMA;
import static com.google.turbine.parse.Token.INTERFACE;
import static com.google.turbine.parse.Token.LPAREN;
import static com.google.turbine.parse.Token.RPAREN;
+import static com.google.turbine.parse.Token.SEMI;
import static com.google.turbine.tree.TurbineModifier.PROTECTED;
import static com.google.turbine.tree.TurbineModifier.PUBLIC;
@@ -812,6 +813,7 @@ public class Parser {
token = initializerParser.token;
boolean first = true;
+ int expressionStart = pos;
for (List<SavedToken> bit : bits) {
IteratorLexer lexer = new IteratorLexer(this.lexer.source(), bit.iterator());
Parser parser = new Parser(lexer);
@@ -823,12 +825,17 @@ public class Parser {
Type ty = baseTy;
ty = parser.extraDims(ty);
// TODO(cushon): skip more fields that are definitely non-const
- Expression init = new ConstExpressionParser(lexer, lexer.next()).expression();
+ ConstExpressionParser constExpressionParser = new ConstExpressionParser(lexer, lexer.next());
+ expressionStart = lexer.position();
+ Expression init = constExpressionParser.expression();
if (init != null && init.kind() == Tree.Kind.ARRAY_INIT) {
init = null;
}
result.add(new VarDecl(pos, access, annos, ty, name, Optional.ofNullable(init)));
}
+ if (token != SEMI) {
+ throw TurbineError.format(lexer.source(), expressionStart, ErrorKind.UNTERMINATED_EXPRESSION);
+ }
eat(Token.SEMI);
return result.build();
}