From 8ce3f4d77ab442cc3d356e376f24e449b66ac974 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sat, 29 Oct 2011 04:20:13 +0200 Subject: [PATCH] Moved some code around in ParserProcessors.java --- .../expression/parser/ParserProcessors.java | 97 ++++++++++--------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java b/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java index 1bd20228e..ffa69cd63 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java @@ -14,54 +14,18 @@ import com.sk89q.worldedit.expression.runtime.Operators; import com.sk89q.worldedit.expression.runtime.Sequence; public final class ParserProcessors { - static Invokable processStatement(LinkedList input) throws ParserException { - LinkedList lhs = new LinkedList(); - LinkedList rhs = new LinkedList(); - boolean semicolonFound = false; - - for (Identifiable identifiable : input) { - if (semicolonFound) { - rhs.addLast(identifiable); - } - else { - if (identifiable.id() == ';') { - semicolonFound = true; - } - else { - lhs.addLast(identifiable); - } - } - } - - if (rhs.isEmpty()) { - if (lhs.isEmpty()) { - return new Sequence(semicolonFound ? input.get(0).getPosition() : -1); - } - - return processExpression(lhs); - } - else if (lhs.isEmpty()) { - return processStatement(rhs); - } - else { - assert(semicolonFound); - - Invokable lhsInvokable = processExpression(lhs); - Invokable rhsInvokable = processStatement(rhs); - - return new Sequence(lhsInvokable.getPosition(), lhsInvokable, rhsInvokable); - } - } - - static Invokable processExpression(LinkedList input) throws ParserException { - return processBinaryOpsRA(input, binaryOpMapsRA.length - 1); - } + private static final Map unaryOpMap = new HashMap(); private static final Map[] binaryOpMapsLA; private static final Map[] binaryOpMapsRA; - private static final Map unaryOpMap = new HashMap(); static { + unaryOpMap.put("-", "neg"); + unaryOpMap.put("!", "not"); + unaryOpMap.put("~", "inv"); + unaryOpMap.put("++", "inc"); + unaryOpMap.put("--", "dec"); + final Object[][][] binaryOpsLA = { { { "^", "pow" }, @@ -155,12 +119,49 @@ public final class ParserProcessors { } } } + } - unaryOpMap.put("-", "neg"); - unaryOpMap.put("!", "not"); - unaryOpMap.put("~", "inv"); - unaryOpMap.put("++", "inc"); - unaryOpMap.put("--", "dec"); + static Invokable processStatement(LinkedList input) throws ParserException { + LinkedList lhs = new LinkedList(); + LinkedList rhs = new LinkedList(); + boolean semicolonFound = false; + + for (Identifiable identifiable : input) { + if (semicolonFound) { + rhs.addLast(identifiable); + } + else { + if (identifiable.id() == ';') { + semicolonFound = true; + } + else { + lhs.addLast(identifiable); + } + } + } + + if (rhs.isEmpty()) { + if (lhs.isEmpty()) { + return new Sequence(semicolonFound ? input.get(0).getPosition() : -1); + } + + return processExpression(lhs); + } + else if (lhs.isEmpty()) { + return processStatement(rhs); + } + else { + assert(semicolonFound); + + Invokable lhsInvokable = processExpression(lhs); + Invokable rhsInvokable = processStatement(rhs); + + return new Sequence(lhsInvokable.getPosition(), lhsInvokable, rhsInvokable); + } + } + + static Invokable processExpression(LinkedList input) throws ParserException { + return processBinaryOpsRA(input, binaryOpMapsRA.length - 1); } private static Invokable processBinaryOpsLA(LinkedList input, int level) throws ParserException {