From bf726639e1bc70b30dc5e5ae2cf349a5bbdfb0ae Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 10 Apr 2016 20:10:36 -0400 Subject: Moved things around for rewrite of AST mechanisms --- .../bjc/dicelang/old/ast/DiceASTExpression.java | 46 ++++++++-------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTExpression.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTExpression.java b/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTExpression.java index 7651093..e6dca9e 100644 --- a/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTExpression.java +++ b/dice-lang/src/main/java/bjc/dicelang/old/ast/DiceASTExpression.java @@ -7,11 +7,11 @@ import java.util.function.Function; import bjc.dicelang.ComplexDice; import bjc.dicelang.IDiceExpression; -import bjc.dicelang.ast.nodes.DiceASTType; -import bjc.dicelang.ast.nodes.IDiceASTNode; -import bjc.dicelang.ast.nodes.LiteralDiceNode; -import bjc.dicelang.ast.nodes.OperatorDiceNode; -import bjc.dicelang.ast.nodes.VariableDiceNode; +import bjc.dicelang.old.ast.nodes.DiceASTType; +import bjc.dicelang.old.ast.nodes.IDiceASTNode; +import bjc.dicelang.old.ast.nodes.LiteralDiceNode; +import bjc.dicelang.old.ast.nodes.OperatorDiceNode; +import bjc.dicelang.old.ast.nodes.VariableDiceNode; import bjc.utils.data.GenHolder; import bjc.utils.data.Pair; import bjc.utils.funcdata.bst.ITreePart.TreeLinearizationMethod; @@ -79,8 +79,8 @@ public class DiceASTExpression implements IDiceExpression { * The enviroment to evaluate bindings and such against * @return The operations to use when collapsing the AST */ - private static Map - buildOperations(Map enviroment) { + private static Map buildOperations( + Map enviroment) { Map operatorCollapsers = new HashMap<>(); @@ -111,14 +111,13 @@ public class DiceASTExpression implements IDiceExpression { DiceASTExpression::parseGroup); operatorCollapsers.put(OperatorDiceNode.LET, (left, right) -> { - return doLet(enviroment, left, right); + return doLet(left, right); }); return operatorCollapsers; } private static Pair> doLet( - Map enviroment, Pair> left, Pair> right) { return left.merge((leftValue, leftAST) -> { @@ -127,21 +126,10 @@ public class DiceASTExpression implements IDiceExpression { .applyToHead(DiceASTExpression::isAssignNode)) { // Just ignore the left block then return new Pair<>(rightValue, rightAST); - } else { - // Left block has an assignment to handle - String varName = leftAST.applyToLeft((leftBranch) -> { - return getAssignmentVar(leftBranch); - }); - - return null; } - }); - }); - } - private static String getAssignmentVar(AST leftBranch) { - return leftBranch.applyToHead((node) -> { - return ((VariableDiceNode) node).getVariable(); + return null; + }); }); } @@ -268,8 +256,8 @@ public class DiceASTExpression implements IDiceExpression { * @return A pair consisting of the token's value and the AST it * represents */ - private Pair> - evaluateLeaf(IDiceASTNode leafNode) { + private Pair> evaluateLeaf( + IDiceASTNode leafNode) { if (leafNode.getType() == DiceASTType.VARIABLE) { VariableDiceNode node = (VariableDiceNode) leafNode; @@ -284,17 +272,17 @@ public class DiceASTExpression implements IDiceExpression { } } - private Pair> - parseVariable(VariableDiceNode leafNode) { + private Pair> parseVariable( + VariableDiceNode leafNode) { String varName = leafNode.getVariable(); if (env.containsKey(varName)) { return new Pair<>(env.get(varName).roll(), new AST<>(leafNode)); - } else { - // Handle special case for defining variables - return new Pair<>(0, new AST<>(leafNode)); } + + // Handle special case for defining variables + return new Pair<>(0, new AST<>(leafNode)); } /** -- cgit v1.2.3