diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-10-27 21:40:28 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-10-27 21:40:28 -0400 |
| commit | e13a6981bd278c2cfc3b5ecb2517367b117f7a52 (patch) | |
| tree | c6a07aef91b5412a2f345316ccaa2fa8d0972e19 /dice-lang/src/main | |
| parent | bb27392419549bb40cbc4f194e38f471d2b9f63d (diff) | |
Work on documentation
Continued work on documenting how exactly the language works
Diffstat (limited to 'dice-lang/src/main')
| -rw-r--r-- | dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java | 13 |
1 files changed, 12 insertions, 1 deletions
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<IDiceASTNode> inlineNode(IDiceASTNode node, IMap<String, ITree<IDiceASTNode>> enviroment, boolean specificInline, IList<String> 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<IDiceASTNode> ast, IMap<String, ITree<IDiceASTNode>> enviroment, String... variables) { + // If we're selectively inlining, do so if (variables != null && variables.length > 0) { IList<String> 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); }); |
