From e6e31d0b93441cde53470f7b34e273de7e92bad4 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 22 Nov 2011 16:28:27 +0100 Subject: [PATCH] Moved some code around --- .../worldedit/expression/parser/Parser.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java b/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java index 51c0d9c90..0f9ee2fb4 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java @@ -101,7 +101,11 @@ public class Parser { break; case '{': - statements.add(parseBlock()); + consumeCharacter('{'); + + statements.add(parseStatements(false)); + + consumeCharacter('}'); if (singleStatement) { break loop; @@ -178,7 +182,7 @@ public class Parser { default: statements.add(parseExpression()); - + if (peek().id() == ';') { ++position; if (singleStatement) { @@ -194,13 +198,17 @@ public class Parser { switch (statements.size()) { case 0: - throw new ParserException(-1, "No statement found."); + if (singleStatement) { + throw new ParserException(peek().getPosition(), "Statement expected."); + } else { + return new Sequence(peek().getPosition()); + } case 1: return statements.get(0); default: - return new Sequence(position, statements.toArray(new RValue[statements.size()])); + return new Sequence(peek().getPosition(), statements.toArray(new RValue[statements.size()])); } } @@ -327,20 +335,6 @@ public class Parser { return ret; } - private final RValue parseBlock() throws ParserException { - consumeCharacter('{'); - - if (peek().id() == '}') { - return new Sequence(peek().getPosition()); - } - - final RValue ret = parseStatements(false); - - consumeCharacter('}'); - - return ret; - } - private boolean hasKeyword(String keyword) { final Token next = peek(); if (!(next instanceof KeywordToken)) {