From e13a6981bd278c2cfc3b5ecb2517367b117f7a52 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 27 Oct 2016 21:40:28 -0400 Subject: Work on documentation Continued work on documenting how exactly the language works --- .../src/main/java/bjc/dicelang/ast/DiceASTInliner.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dice-lang/src/main/java/bjc') diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java index 7f5f2d7..305c9af 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java @@ -36,33 +36,41 @@ public class DiceASTInliner { private static ITree inlineNode(IDiceASTNode node, IMap> enviroment, boolean specificInline, IList variableNames) { + // Only variables get inlined if (node.getType() != DiceASTType.VARIABLE) { return new Tree<>(node); } + // Get the name of what we're inlining String variableName = ((VariableDiceNode) node).getVariable(); + // If we're inlining only certain variables, do so if (specificInline) { + // Only inline the variable if we're supposed to if (variableNames.contains(variableName)) { + // You can't inline non-existent variables if (!enviroment.containsKey(variableName)) { throw new UnsupportedOperationException( "Attempted to inline non-existant variable " + variableName); } + // Return the tree for the variable return enviroment.get(variableName); } } else { + // You can't inline non-existent variables if (!enviroment.containsKey(variableName)) { throw new UnsupportedOperationException( "Attempted to inline non-existant variable " + variableName); } + // Return the tree for the variable return enviroment.get(variableName); } - return new Tree<>(node); + // return new Tree<>(node); } /** @@ -99,14 +107,17 @@ public class DiceASTInliner { ITree ast, IMap> enviroment, String... variables) { + // If we're selectively inlining, do so if (variables != null && variables.length > 0) { IList variableNames = new FunctionalList<>(variables); + // Selectively inline each tree node return ast.flatMapTree((node) -> { return inlineNode(node, enviroment, true, variableNames); }); } + // Inline everything in each node return ast.flatMapTree((node) -> { return inlineNode(node, enviroment, false, null); }); -- cgit v1.2.3