From c990d4c50a35f41faa6485a536811f8c5f11c03c Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 23 Sep 2017 23:43:08 -0700 Subject: [PATCH] More around files into more applicable packages. --- .../java/org/nwapw/abacus/lexing/Lexer.java | 5 ++--- .../abacus/lexing/{pattern => }/Match.java | 2 +- .../nwapw/abacus/lexing/pattern/Pattern.java | 22 ++++++++++--------- .../abacus/lexing/pattern/PatternChain.java | 6 +++-- .../lexing/pattern/{ => nodes}/AnyNode.java | 2 +- .../lexing/pattern/{ => nodes}/EndNode.java | 2 +- .../lexing/pattern/{ => nodes}/LinkNode.java | 2 +- .../pattern/{ => nodes}/PatternNode.java | 9 +++++++- .../lexing/pattern/{ => nodes}/RangeNode.java | 2 +- .../lexing/pattern/{ => nodes}/ValueNode.java | 2 +- .../number/{ => standard}/NaiveNumber.java | 4 +++- .../number/{ => standard}/PreciseNumber.java | 4 +++- .../{ => standard}/LexerTokenizer.java | 6 ++--- .../{ => standard}/ShuntingYardParser.java | 9 ++++---- .../{tree => parsing/standard}/TokenType.java | 2 +- .../java/org/nwapw/abacus/plugin/Plugin.java | 4 ++++ .../nwapw/abacus/plugin/PluginManager.java | 4 ++++ .../plugin/standard/StandardPlugin.java | 7 ++++-- .../main/kotlin/org/nwapw/abacus/Abacus.kt | 11 +++++----- .../abacus/{tree => }/EvaluationResult.kt | 2 +- .../nwapw/abacus/context/EvaluationContext.kt | 2 +- .../context/MutableEvaluationContext.kt | 2 +- .../function/{applicable => }/Applicable.kt | 2 +- .../{ => interfaces}/NumberFunction.kt | 4 ++-- .../{ => interfaces}/NumberOperator.kt | 7 ++++-- .../{ => interfaces}/TreeValueFunction.kt | 6 ++--- .../{ => interfaces}/TreeValueOperator.kt | 9 +++++--- .../nwapw/abacus/number/NumberInterface.kt | 1 + .../number/{ => promotion}/NumberUtils.kt | 4 +++- .../{ => promotion}/PromotionManager.kt | 5 +++-- .../number/{ => promotion}/PromotionResult.kt | 3 ++- .../abacus/number/{ => range}/NumberRange.kt | 3 ++- .../number/{ => range}/NumberRangeBuilder.kt | 3 ++- .../kotlin/org/nwapw/abacus/parsing/Parser.kt | 2 +- .../org/nwapw/abacus/parsing/TreeBuilder.kt | 2 +- .../plugin/standard/operator/OperatorAdd.kt | 2 +- .../plugin/standard/operator/OperatorCaret.kt | 2 +- .../standard/operator/OperatorDefine.kt | 6 ++--- .../standard/operator/OperatorDivide.kt | 2 +- .../standard/operator/OperatorFactorial.kt | 2 +- .../standard/operator/OperatorMultiply.kt | 2 +- .../plugin/standard/operator/OperatorNcr.kt | 2 +- .../standard/operator/OperatorNegate.kt | 2 +- .../plugin/standard/operator/OperatorNpr.kt | 2 +- .../plugin/standard/operator/OperatorSet.kt | 6 ++--- .../standard/operator/OperatorSubtract.kt | 2 +- .../kotlin/org/nwapw/abacus/tree/Reducer.kt | 2 ++ .../abacus/tree/{ => nodes}/BinaryNode.kt | 2 +- .../nwapw/abacus/tree/{ => nodes}/CallNode.kt | 2 +- .../tree/{ => nodes}/NumberBinaryNode.kt | 4 +++- .../NumberFunctionNode.kt} | 6 +++-- .../abacus/tree/{ => nodes}/NumberNode.kt | 4 +++- .../tree/{ => nodes}/NumberUnaryNode.kt | 4 +++- .../nwapw/abacus/tree/{ => nodes}/TreeNode.kt | 4 +++- .../tree/{ => nodes}/TreeValueBinaryNode.kt | 4 +++- .../tree/{ => nodes}/TreeValueFunctionNode.kt | 4 +++- .../tree/{ => nodes}/TreeValueUnaryNode.kt | 4 +++- .../abacus/tree/{ => nodes}/UnaryNode.kt | 2 +- .../abacus/tree/{ => nodes}/VariableNode.kt | 4 +++- .../tree/{ => standard}/NumberReducer.kt | 6 +++-- .../nwapw/abacus/tests/CalculationTests.java | 2 +- .../org/nwapw/abacus/tests/LexerTests.java | 2 +- .../org/nwapw/abacus/tests/RangeTests.java | 6 ++--- .../nwapw/abacus/tests/TokenizerTests.java | 8 ++++--- .../org/nwapw/abacus/fx/AbacusController.java | 4 ++-- 65 files changed, 164 insertions(+), 102 deletions(-) rename core/src/main/java/org/nwapw/abacus/lexing/{pattern => }/Match.java (95%) rename core/src/main/java/org/nwapw/abacus/lexing/pattern/{ => nodes}/AnyNode.java (85%) rename core/src/main/java/org/nwapw/abacus/lexing/pattern/{ => nodes}/EndNode.java (92%) rename core/src/main/java/org/nwapw/abacus/lexing/pattern/{ => nodes}/LinkNode.java (90%) rename core/src/main/java/org/nwapw/abacus/lexing/pattern/{ => nodes}/PatternNode.java (88%) rename core/src/main/java/org/nwapw/abacus/lexing/pattern/{ => nodes}/RangeNode.java (94%) rename core/src/main/java/org/nwapw/abacus/lexing/pattern/{ => nodes}/ValueNode.java (93%) rename core/src/main/java/org/nwapw/abacus/number/{ => standard}/NaiveNumber.java (97%) rename core/src/main/java/org/nwapw/abacus/number/{ => standard}/PreciseNumber.java (94%) rename core/src/main/java/org/nwapw/abacus/parsing/{ => standard}/LexerTokenizer.java (95%) rename core/src/main/java/org/nwapw/abacus/parsing/{ => standard}/ShuntingYardParser.java (97%) rename core/src/main/java/org/nwapw/abacus/{tree => parsing/standard}/TokenType.java (93%) rename core/src/main/kotlin/org/nwapw/abacus/{tree => }/EvaluationResult.kt (71%) rename core/src/main/kotlin/org/nwapw/abacus/function/{applicable => }/Applicable.kt (97%) rename core/src/main/kotlin/org/nwapw/abacus/function/{ => interfaces}/NumberFunction.kt (73%) rename core/src/main/kotlin/org/nwapw/abacus/function/{ => interfaces}/NumberOperator.kt (65%) rename core/src/main/kotlin/org/nwapw/abacus/function/{ => interfaces}/TreeValueFunction.kt (70%) rename core/src/main/kotlin/org/nwapw/abacus/function/{ => interfaces}/TreeValueOperator.kt (62%) rename core/src/main/kotlin/org/nwapw/abacus/number/{ => promotion}/NumberUtils.kt (85%) rename core/src/main/kotlin/org/nwapw/abacus/number/{ => promotion}/PromotionManager.kt (95%) rename core/src/main/kotlin/org/nwapw/abacus/number/{ => promotion}/PromotionResult.kt (72%) rename core/src/main/kotlin/org/nwapw/abacus/number/{ => range}/NumberRange.kt (92%) rename core/src/main/kotlin/org/nwapw/abacus/number/{ => range}/NumberRangeBuilder.kt (91%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/BinaryNode.kt (95%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/CallNode.kt (95%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/NumberBinaryNode.kt (89%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{FunctionNode.kt => nodes/NumberFunctionNode.kt} (71%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/NumberNode.kt (86%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/NumberUnaryNode.kt (87%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/TreeNode.kt (59%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/TreeValueBinaryNode.kt (88%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/TreeValueFunctionNode.kt (86%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/TreeValueUnaryNode.kt (87%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/UnaryNode.kt (93%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => nodes}/VariableNode.kt (87%) rename core/src/main/kotlin/org/nwapw/abacus/tree/{ => standard}/NumberReducer.kt (95%) diff --git a/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java b/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java index 1b7553b..292c1b9 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/Lexer.java @@ -1,9 +1,8 @@ package org.nwapw.abacus.lexing; -import org.nwapw.abacus.lexing.pattern.EndNode; -import org.nwapw.abacus.lexing.pattern.Match; +import org.nwapw.abacus.lexing.pattern.nodes.EndNode; import org.nwapw.abacus.lexing.pattern.Pattern; -import org.nwapw.abacus.lexing.pattern.PatternNode; +import org.nwapw.abacus.lexing.pattern.nodes.PatternNode; import java.util.*; diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Match.java b/core/src/main/java/org/nwapw/abacus/lexing/Match.java similarity index 95% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/Match.java rename to core/src/main/java/org/nwapw/abacus/lexing/Match.java index 90edc82..3202fff 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Match.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/Match.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing; /** * A match that has been generated by the lexer. diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java index 06d0d09..b578d01 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java @@ -1,5 +1,7 @@ package org.nwapw.abacus.lexing.pattern; +import org.nwapw.abacus.lexing.pattern.nodes.*; + import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -88,7 +90,7 @@ public class Pattern { * @return the modified chain. */ private PatternChain transformPlus(PatternChain chain) { - chain.tail.outputStates.add(chain.head); + chain.tail.getOutputStates().add(chain.head); return chain; } @@ -102,10 +104,10 @@ public class Pattern { private PatternChain transformStar(PatternChain chain) { LinkNode newTail = new LinkNode<>(); LinkNode newHead = new LinkNode<>(); - newHead.outputStates.add(chain.head); - newHead.outputStates.add(newTail); - chain.tail.outputStates.add(newTail); - newTail.outputStates.add(newHead); + newHead.getOutputStates().add(chain.head); + newHead.getOutputStates().add(newTail); + chain.tail.getOutputStates().add(newTail); + newTail.getOutputStates().add(newHead); chain.head = newHead; chain.tail = newTail; return chain; @@ -121,9 +123,9 @@ public class Pattern { private PatternChain transformQuestion(PatternChain chain) { LinkNode newTail = new LinkNode<>(); LinkNode newHead = new LinkNode<>(); - newHead.outputStates.add(chain.head); - newHead.outputStates.add(newTail); - chain.tail.outputStates.add(newTail); + newHead.getOutputStates().add(chain.head); + newHead.getOutputStates().add(newTail); + chain.tail.getOutputStates().add(newTail); chain.head = newHead; chain.tail = newTail; return chain; @@ -140,8 +142,8 @@ public class Pattern { LinkNode tail = new LinkNode<>(); PatternChain newChain = new PatternChain<>(head, tail); for (PatternChain chain : collection) { - head.outputStates.add(chain.head); - chain.tail.outputStates.add(tail); + head.getOutputStates().add(chain.head); + chain.tail.getOutputStates().add(tail); } return newChain; } diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternChain.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternChain.java index 1ce9661..294c8bf 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternChain.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternChain.java @@ -1,5 +1,7 @@ package org.nwapw.abacus.lexing.pattern; +import org.nwapw.abacus.lexing.pattern.nodes.PatternNode; + /** * A chain of nodes that can be treated as a single unit. * Used during pattern compilation. @@ -56,7 +58,7 @@ public class PatternChain { this.head = other.head; this.tail = other.tail; } else { - tail.outputStates.add(other.head); + tail.getOutputStates().add(other.head); tail = other.tail; } } @@ -72,7 +74,7 @@ public class PatternChain { if (tail == null) { head = tail = node; } else { - tail.outputStates.add(node); + tail.getOutputStates().add(node); tail = node; } } diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/AnyNode.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/AnyNode.java similarity index 85% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/AnyNode.java rename to core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/AnyNode.java index 3db1bbb..fa0fb25 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/AnyNode.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/AnyNode.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing.pattern.nodes; /** * A pattern node that matches any character. diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/EndNode.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/EndNode.java similarity index 92% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/EndNode.java rename to core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/EndNode.java index 7bb6301..5d5d4ab 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/EndNode.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/EndNode.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing.pattern.nodes; /** * A node that represents a successful match. diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/LinkNode.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/LinkNode.java similarity index 90% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/LinkNode.java rename to core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/LinkNode.java index 8ba45bd..353ddf5 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/LinkNode.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/LinkNode.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing.pattern.nodes; import java.util.Collection; diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternNode.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/PatternNode.java similarity index 88% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternNode.java rename to core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/PatternNode.java index 005f49f..d8c9544 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/PatternNode.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/PatternNode.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing.pattern.nodes; import java.util.Collection; import java.util.HashSet; @@ -65,4 +65,11 @@ public class PatternNode { outputStates.forEach(e -> e.addInto(into)); } + /** + * Gets the output states of this node. + * @return the output states. + */ + public Set> getOutputStates() { + return outputStates; + } } diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/RangeNode.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/RangeNode.java similarity index 94% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/RangeNode.java rename to core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/RangeNode.java index 2956022..686e83c 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/RangeNode.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/RangeNode.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing.pattern.nodes; /** * A node that matches a range of characters. diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/ValueNode.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/ValueNode.java similarity index 93% rename from core/src/main/java/org/nwapw/abacus/lexing/pattern/ValueNode.java rename to core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/ValueNode.java index 2daa7c9..12d4939 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/ValueNode.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/nodes/ValueNode.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.lexing.pattern; +package org.nwapw.abacus.lexing.pattern.nodes; /** * A node that matches a single value. diff --git a/core/src/main/java/org/nwapw/abacus/number/NaiveNumber.java b/core/src/main/java/org/nwapw/abacus/number/standard/NaiveNumber.java similarity index 97% rename from core/src/main/java/org/nwapw/abacus/number/NaiveNumber.java rename to core/src/main/java/org/nwapw/abacus/number/standard/NaiveNumber.java index 4f03243..ad4474a 100755 --- a/core/src/main/java/org/nwapw/abacus/number/NaiveNumber.java +++ b/core/src/main/java/org/nwapw/abacus/number/standard/NaiveNumber.java @@ -1,4 +1,6 @@ -package org.nwapw.abacus.number; +package org.nwapw.abacus.number.standard; + +import org.nwapw.abacus.number.NumberInterface; /** * An implementation of NumberInterface using a double. diff --git a/core/src/main/java/org/nwapw/abacus/number/PreciseNumber.java b/core/src/main/java/org/nwapw/abacus/number/standard/PreciseNumber.java similarity index 94% rename from core/src/main/java/org/nwapw/abacus/number/PreciseNumber.java rename to core/src/main/java/org/nwapw/abacus/number/standard/PreciseNumber.java index 41e9080..0da7005 100755 --- a/core/src/main/java/org/nwapw/abacus/number/PreciseNumber.java +++ b/core/src/main/java/org/nwapw/abacus/number/standard/PreciseNumber.java @@ -1,4 +1,6 @@ -package org.nwapw.abacus.number; +package org.nwapw.abacus.number.standard; + +import org.nwapw.abacus.number.NumberInterface; import java.math.BigDecimal; import java.math.MathContext; diff --git a/core/src/main/java/org/nwapw/abacus/parsing/LexerTokenizer.java b/core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java similarity index 95% rename from core/src/main/java/org/nwapw/abacus/parsing/LexerTokenizer.java rename to core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java index 1096abb..028089a 100644 --- a/core/src/main/java/org/nwapw/abacus/parsing/LexerTokenizer.java +++ b/core/src/main/java/org/nwapw/abacus/parsing/standard/LexerTokenizer.java @@ -1,12 +1,12 @@ -package org.nwapw.abacus.parsing; +package org.nwapw.abacus.parsing.standard; import org.nwapw.abacus.exception.TokenizeException; import org.nwapw.abacus.lexing.Lexer; -import org.nwapw.abacus.lexing.pattern.Match; +import org.nwapw.abacus.lexing.Match; import org.nwapw.abacus.lexing.pattern.Pattern; +import org.nwapw.abacus.parsing.Tokenizer; import org.nwapw.abacus.plugin.PluginListener; import org.nwapw.abacus.plugin.PluginManager; -import org.nwapw.abacus.tree.TokenType; import java.util.Comparator; import java.util.List; diff --git a/core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java b/core/src/main/java/org/nwapw/abacus/parsing/standard/ShuntingYardParser.java similarity index 97% rename from core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java rename to core/src/main/java/org/nwapw/abacus/parsing/standard/ShuntingYardParser.java index 67bc1f6..6c75f03 100644 --- a/core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java +++ b/core/src/main/java/org/nwapw/abacus/parsing/standard/ShuntingYardParser.java @@ -1,13 +1,14 @@ -package org.nwapw.abacus.parsing; +package org.nwapw.abacus.parsing.standard; import org.nwapw.abacus.exception.ParseException; import org.nwapw.abacus.function.Operator; import org.nwapw.abacus.function.OperatorAssociativity; import org.nwapw.abacus.function.OperatorType; -import org.nwapw.abacus.lexing.pattern.Match; +import org.nwapw.abacus.lexing.Match; +import org.nwapw.abacus.parsing.Parser; import org.nwapw.abacus.plugin.PluginListener; import org.nwapw.abacus.plugin.PluginManager; -import org.nwapw.abacus.tree.*; +import org.nwapw.abacus.tree.nodes.*; import java.util.*; @@ -162,7 +163,7 @@ public class ShuntingYardParser implements Parser>, PluginListe matches.remove(0); CallNode node; if (matchType == TokenType.FUNCTION) { - node = new FunctionNode(functionName, children); + node = new NumberFunctionNode(functionName, children); } else { node = new TreeValueFunctionNode(functionName, children); } diff --git a/core/src/main/java/org/nwapw/abacus/tree/TokenType.java b/core/src/main/java/org/nwapw/abacus/parsing/standard/TokenType.java similarity index 93% rename from core/src/main/java/org/nwapw/abacus/tree/TokenType.java rename to core/src/main/java/org/nwapw/abacus/parsing/standard/TokenType.java index 7df9a94..cf6ebd1 100644 --- a/core/src/main/java/org/nwapw/abacus/tree/TokenType.java +++ b/core/src/main/java/org/nwapw/abacus/parsing/standard/TokenType.java @@ -1,4 +1,4 @@ -package org.nwapw.abacus.tree; +package org.nwapw.abacus.parsing.standard; /** * Enum to represent the type of the token that has been matched diff --git a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java index 223d7aa..4064762 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/Plugin.java @@ -1,6 +1,10 @@ package org.nwapw.abacus.plugin; import org.nwapw.abacus.function.*; +import org.nwapw.abacus.function.interfaces.NumberFunction; +import org.nwapw.abacus.function.interfaces.NumberOperator; +import org.nwapw.abacus.function.interfaces.TreeValueFunction; +import org.nwapw.abacus.function.interfaces.TreeValueOperator; import org.nwapw.abacus.number.NumberInterface; /** diff --git a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 27404d4..4abd731 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -2,6 +2,10 @@ package org.nwapw.abacus.plugin; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.function.*; +import org.nwapw.abacus.function.interfaces.NumberFunction; +import org.nwapw.abacus.function.interfaces.NumberOperator; +import org.nwapw.abacus.function.interfaces.TreeValueFunction; +import org.nwapw.abacus.function.interfaces.TreeValueOperator; import org.nwapw.abacus.number.NumberInterface; import java.lang.reflect.InvocationTargetException; diff --git a/core/src/main/java/org/nwapw/abacus/plugin/standard/StandardPlugin.java b/core/src/main/java/org/nwapw/abacus/plugin/standard/StandardPlugin.java index 7fb94ff..3d8a68c 100755 --- a/core/src/main/java/org/nwapw/abacus/plugin/standard/StandardPlugin.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/standard/StandardPlugin.java @@ -2,9 +2,12 @@ package org.nwapw.abacus.plugin.standard; import org.nwapw.abacus.context.MutableEvaluationContext; import org.nwapw.abacus.function.*; -import org.nwapw.abacus.number.NaiveNumber; +import org.nwapw.abacus.function.interfaces.NumberFunction; +import org.nwapw.abacus.function.interfaces.NumberOperator; +import org.nwapw.abacus.function.interfaces.TreeValueOperator; +import org.nwapw.abacus.number.standard.NaiveNumber; import org.nwapw.abacus.number.NumberInterface; -import org.nwapw.abacus.number.PreciseNumber; +import org.nwapw.abacus.number.standard.PreciseNumber; import org.nwapw.abacus.plugin.NumberImplementation; import org.nwapw.abacus.plugin.Plugin; import org.nwapw.abacus.plugin.PluginManager; diff --git a/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt b/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt index f84f25a..0946ade 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt @@ -3,15 +3,14 @@ package org.nwapw.abacus import org.nwapw.abacus.config.Configuration import org.nwapw.abacus.context.MutableEvaluationContext import org.nwapw.abacus.context.EvaluationContext -import org.nwapw.abacus.number.PromotionManager -import org.nwapw.abacus.parsing.LexerTokenizer -import org.nwapw.abacus.parsing.ShuntingYardParser +import org.nwapw.abacus.number.promotion.PromotionManager +import org.nwapw.abacus.parsing.standard.LexerTokenizer +import org.nwapw.abacus.parsing.standard.ShuntingYardParser import org.nwapw.abacus.parsing.TreeBuilder import org.nwapw.abacus.plugin.PluginManager import org.nwapw.abacus.plugin.standard.StandardPlugin -import org.nwapw.abacus.tree.EvaluationResult -import org.nwapw.abacus.tree.NumberReducer -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.standard.NumberReducer +import org.nwapw.abacus.tree.nodes.TreeNode /** * Core class to handle all mathematics. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/EvaluationResult.kt b/core/src/main/kotlin/org/nwapw/abacus/EvaluationResult.kt similarity index 71% rename from core/src/main/kotlin/org/nwapw/abacus/tree/EvaluationResult.kt rename to core/src/main/kotlin/org/nwapw/abacus/EvaluationResult.kt index a499877..268a183 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/EvaluationResult.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/EvaluationResult.kt @@ -1,4 +1,4 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus import org.nwapw.abacus.context.MutableEvaluationContext import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/context/EvaluationContext.kt b/core/src/main/kotlin/org/nwapw/abacus/context/EvaluationContext.kt index 293a5ff..5745516 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/context/EvaluationContext.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/context/EvaluationContext.kt @@ -3,7 +3,7 @@ package org.nwapw.abacus.context import org.nwapw.abacus.number.NumberInterface import org.nwapw.abacus.plugin.NumberImplementation import org.nwapw.abacus.tree.Reducer -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.nodes.TreeNode /** * A context for the reduction of a [org.nwapw.abacus.tree.TreeNode] into a number. diff --git a/core/src/main/kotlin/org/nwapw/abacus/context/MutableEvaluationContext.kt b/core/src/main/kotlin/org/nwapw/abacus/context/MutableEvaluationContext.kt index 684b69c..4fc2891 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/context/MutableEvaluationContext.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/context/MutableEvaluationContext.kt @@ -3,7 +3,7 @@ package org.nwapw.abacus.context import org.nwapw.abacus.number.NumberInterface import org.nwapw.abacus.plugin.NumberImplementation import org.nwapw.abacus.tree.Reducer -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.nodes.TreeNode /** * A reduction context that is mutable. diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt b/core/src/main/kotlin/org/nwapw/abacus/function/Applicable.kt similarity index 97% rename from core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt rename to core/src/main/kotlin/org/nwapw/abacus/function/Applicable.kt index 0d64ba6..efb78f6 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/Applicable.kt @@ -1,4 +1,4 @@ -package org.nwapw.abacus.function.applicable +package org.nwapw.abacus.function import org.nwapw.abacus.context.MutableEvaluationContext import org.nwapw.abacus.exception.DomainException diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/NumberFunction.kt similarity index 73% rename from core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt rename to core/src/main/kotlin/org/nwapw/abacus/function/interfaces/NumberFunction.kt index f76f147..051c09e 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/NumberFunction.kt @@ -1,6 +1,6 @@ -package org.nwapw.abacus.function +package org.nwapw.abacus.function.interfaces -import org.nwapw.abacus.function.applicable.Applicable +import org.nwapw.abacus.function.Applicable import org.nwapw.abacus.number.NumberInterface /** diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/NumberOperator.kt similarity index 65% rename from core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt rename to core/src/main/kotlin/org/nwapw/abacus/function/interfaces/NumberOperator.kt index 81349c3..b97546c 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/NumberOperator.kt @@ -1,6 +1,9 @@ -package org.nwapw.abacus.function +package org.nwapw.abacus.function.interfaces -import org.nwapw.abacus.function.applicable.Applicable +import org.nwapw.abacus.function.Applicable +import org.nwapw.abacus.function.Operator +import org.nwapw.abacus.function.OperatorAssociativity +import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface /** diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/TreeValueFunction.kt similarity index 70% rename from core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt rename to core/src/main/kotlin/org/nwapw/abacus/function/interfaces/TreeValueFunction.kt index 198b271..b21932b 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/TreeValueFunction.kt @@ -1,8 +1,8 @@ -package org.nwapw.abacus.function +package org.nwapw.abacus.function.interfaces -import org.nwapw.abacus.function.applicable.Applicable +import org.nwapw.abacus.function.Applicable import org.nwapw.abacus.number.NumberInterface -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.nodes.TreeNode /** * A function that operates on trees. diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/TreeValueOperator.kt similarity index 62% rename from core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt rename to core/src/main/kotlin/org/nwapw/abacus/function/interfaces/TreeValueOperator.kt index 92b208f..c2cbf3f 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/interfaces/TreeValueOperator.kt @@ -1,8 +1,11 @@ -package org.nwapw.abacus.function +package org.nwapw.abacus.function.interfaces -import org.nwapw.abacus.function.applicable.Applicable +import org.nwapw.abacus.function.Applicable +import org.nwapw.abacus.function.Operator +import org.nwapw.abacus.function.OperatorAssociativity +import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.nodes.TreeNode /** * An operator that operates on trees. diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt b/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt index 337969c..3279af6 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt @@ -1,6 +1,7 @@ package org.nwapw.abacus.number import org.nwapw.abacus.exception.ComputationInterruptedException +import org.nwapw.abacus.number.range.NumberRangeBuilder abstract class NumberInterface: Comparable { diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/NumberUtils.kt b/core/src/main/kotlin/org/nwapw/abacus/number/promotion/NumberUtils.kt similarity index 85% rename from core/src/main/kotlin/org/nwapw/abacus/number/NumberUtils.kt rename to core/src/main/kotlin/org/nwapw/abacus/number/promotion/NumberUtils.kt index 03c46fd..4d765c5 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/NumberUtils.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/promotion/NumberUtils.kt @@ -1,5 +1,7 @@ @file:JvmName("NumberUtils") -package org.nwapw.abacus.number +package org.nwapw.abacus.number.promotion + +import org.nwapw.abacus.number.NumberInterface typealias PromotionFunction = java.util.function.Function typealias PromotionPath = List diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/PromotionManager.kt b/core/src/main/kotlin/org/nwapw/abacus/number/promotion/PromotionManager.kt similarity index 95% rename from core/src/main/kotlin/org/nwapw/abacus/number/PromotionManager.kt rename to core/src/main/kotlin/org/nwapw/abacus/number/promotion/PromotionManager.kt index 548bee6..fd7004b 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/PromotionManager.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/promotion/PromotionManager.kt @@ -1,7 +1,8 @@ -package org.nwapw.abacus.number +package org.nwapw.abacus.number.promotion import org.nwapw.abacus.Abacus import org.nwapw.abacus.exception.PromotionException +import org.nwapw.abacus.number.NumberInterface import org.nwapw.abacus.plugin.NumberImplementation import org.nwapw.abacus.plugin.PluginListener import org.nwapw.abacus.plugin.PluginManager @@ -51,7 +52,7 @@ class PromotionManager(val abacus: Abacus) : PluginListener { val implementations = numbers.map { pluginManager.interfaceImplementationFor(it.javaClass) } val highestPriority = implementations.sortedBy { it.priority }.last() return PromotionResult(items = numbers.map { - if(it.javaClass == highestPriority.implementation) it + if (it.javaClass == highestPriority.implementation) it else computePaths[pluginManager.interfaceImplementationFor(it.javaClass) to highestPriority] ?.promote(it) ?: throw PromotionException() }.toTypedArray(), promotedTo = highestPriority) diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/PromotionResult.kt b/core/src/main/kotlin/org/nwapw/abacus/number/promotion/PromotionResult.kt similarity index 72% rename from core/src/main/kotlin/org/nwapw/abacus/number/PromotionResult.kt rename to core/src/main/kotlin/org/nwapw/abacus/number/promotion/PromotionResult.kt index 51623fb..6fb492f 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/PromotionResult.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/promotion/PromotionResult.kt @@ -1,5 +1,6 @@ -package org.nwapw.abacus.number +package org.nwapw.abacus.number.promotion +import org.nwapw.abacus.number.NumberInterface import org.nwapw.abacus.plugin.NumberImplementation /** diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/NumberRange.kt b/core/src/main/kotlin/org/nwapw/abacus/number/range/NumberRange.kt similarity index 92% rename from core/src/main/kotlin/org/nwapw/abacus/number/NumberRange.kt rename to core/src/main/kotlin/org/nwapw/abacus/number/range/NumberRange.kt index 6adfc65..0bf9b5e 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/NumberRange.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/range/NumberRange.kt @@ -1,6 +1,7 @@ -package org.nwapw.abacus.number +package org.nwapw.abacus.number.range import org.nwapw.abacus.Abacus +import org.nwapw.abacus.number.NumberInterface /** * A closed range designed specifically for [NumberInterface] diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/NumberRangeBuilder.kt b/core/src/main/kotlin/org/nwapw/abacus/number/range/NumberRangeBuilder.kt similarity index 91% rename from core/src/main/kotlin/org/nwapw/abacus/number/NumberRangeBuilder.kt rename to core/src/main/kotlin/org/nwapw/abacus/number/range/NumberRangeBuilder.kt index c0ed09c..8e747ff 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/NumberRangeBuilder.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/range/NumberRangeBuilder.kt @@ -1,6 +1,7 @@ -package org.nwapw.abacus.number +package org.nwapw.abacus.number.range import org.nwapw.abacus.Abacus +import org.nwapw.abacus.number.NumberInterface /** * A utility class for creating [NumberRange] instances. diff --git a/core/src/main/kotlin/org/nwapw/abacus/parsing/Parser.kt b/core/src/main/kotlin/org/nwapw/abacus/parsing/Parser.kt index be2dde3..22bc080 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/parsing/Parser.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/parsing/Parser.kt @@ -1,6 +1,6 @@ package org.nwapw.abacus.parsing -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.nodes.TreeNode /** * Converter from tokens into a parse tree. diff --git a/core/src/main/kotlin/org/nwapw/abacus/parsing/TreeBuilder.kt b/core/src/main/kotlin/org/nwapw/abacus/parsing/TreeBuilder.kt index cdcd24b..07efda1 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/parsing/TreeBuilder.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/parsing/TreeBuilder.kt @@ -1,6 +1,6 @@ package org.nwapw.abacus.parsing -import org.nwapw.abacus.tree.TreeNode +import org.nwapw.abacus.tree.nodes.TreeNode /** * Class to combine a [Tokenizer] and a [Parser] diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorAdd.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorAdd.kt index 17db073..959d3da 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorAdd.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorAdd.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt index b673851..7dfc804 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDefine.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDefine.kt index 8eff979..de92837 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDefine.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDefine.kt @@ -3,10 +3,10 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType -import org.nwapw.abacus.function.TreeValueOperator +import org.nwapw.abacus.function.interfaces.TreeValueOperator import org.nwapw.abacus.number.NumberInterface -import org.nwapw.abacus.tree.TreeNode -import org.nwapw.abacus.tree.VariableNode +import org.nwapw.abacus.tree.nodes.TreeNode +import org.nwapw.abacus.tree.nodes.VariableNode /** * The definition operator. diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDivide.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDivide.kt index 94ad35a..8643e64 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDivide.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorDivide.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt index 64071a8..df62e0c 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorMultiply.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorMultiply.kt index a92e8ba..f670e4b 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorMultiply.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorMultiply.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt index 15cada8..b51ceca 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNegate.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNegate.kt index a53b069..f02faca 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNegate.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNegate.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt index b053458..a316663 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSet.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSet.kt index 89019dd..cef0c58 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSet.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSet.kt @@ -3,10 +3,10 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType -import org.nwapw.abacus.function.TreeValueOperator +import org.nwapw.abacus.function.interfaces.TreeValueOperator import org.nwapw.abacus.number.NumberInterface -import org.nwapw.abacus.tree.TreeNode -import org.nwapw.abacus.tree.VariableNode +import org.nwapw.abacus.tree.nodes.TreeNode +import org.nwapw.abacus.tree.nodes.VariableNode /** * The set operator. diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSubtract.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSubtract.kt index bd0e37f..22ac8ea 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSubtract.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorSubtract.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.plugin.standard.operator import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.NumberOperator +import org.nwapw.abacus.function.interfaces.NumberOperator import org.nwapw.abacus.function.OperatorAssociativity import org.nwapw.abacus.function.OperatorType import org.nwapw.abacus.number.NumberInterface diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt index 45cb4dc..1c07f57 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/Reducer.kt @@ -1,5 +1,7 @@ package org.nwapw.abacus.tree +import org.nwapw.abacus.tree.nodes.TreeNode + /** * Reducer interface that takes a tree and returns a single value. * diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/BinaryNode.kt similarity index 95% rename from core/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/BinaryNode.kt index aa04571..b99ed24 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/BinaryNode.kt @@ -1,4 +1,4 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes /** * A tree node that holds a binary operation. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/CallNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/CallNode.kt similarity index 95% rename from core/src/main/kotlin/org/nwapw/abacus/tree/CallNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/CallNode.kt index 38595dd..c9c0656 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/CallNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/CallNode.kt @@ -1,4 +1,4 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes /** * Represents a more generic function call. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberBinaryNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberBinaryNode.kt similarity index 89% rename from core/src/main/kotlin/org/nwapw/abacus/tree/NumberBinaryNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberBinaryNode.kt index 3742477..fd59bef 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberBinaryNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberBinaryNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A binary operator node that reduces its children. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberFunctionNode.kt similarity index 71% rename from core/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberFunctionNode.kt index e4d2acb..ecc8a89 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberFunctionNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node that holds a function call. @@ -8,7 +10,7 @@ package org.nwapw.abacus.tree * * @param function the function string. */ -class FunctionNode(function: String, children: List) : CallNode(function, children) { +class NumberFunctionNode(function: String, children: List) : CallNode(function, children) { override fun reduce(reducer: Reducer): T { val children = Array(children.size, { children[it].reduce(reducer) }) diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberNode.kt similarity index 86% rename from core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberNode.kt index 9278301..cfb012c 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node that holds a single number value. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberUnaryNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberUnaryNode.kt similarity index 87% rename from core/src/main/kotlin/org/nwapw/abacus/tree/NumberUnaryNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberUnaryNode.kt index 01a494f..7ee5077 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberUnaryNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/NumberUnaryNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A unary operator node that reduces its children. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeNode.kt similarity index 59% rename from core/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeNode.kt index a17b191..7a12458 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueBinaryNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueBinaryNode.kt similarity index 88% rename from core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueBinaryNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueBinaryNode.kt index 97cd0cf..e89de19 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueBinaryNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueBinaryNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node that represents a binary tree value operator. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueFunctionNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueFunctionNode.kt similarity index 86% rename from core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueFunctionNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueFunctionNode.kt index 18301d8..9bc23af 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueFunctionNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueFunctionNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node that represents a tree value function call. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueUnaryNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueUnaryNode.kt similarity index 87% rename from core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueUnaryNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueUnaryNode.kt index dab3f52..2a5bd46 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/TreeValueUnaryNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/TreeValueUnaryNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node that represents a unary tree value operator. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/UnaryNode.kt similarity index 93% rename from core/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/UnaryNode.kt index ea518e2..27953c8 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/UnaryNode.kt @@ -1,4 +1,4 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes /** * A tree node that holds a unary operation. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/VariableNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/VariableNode.kt similarity index 87% rename from core/src/main/kotlin/org/nwapw/abacus/tree/VariableNode.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/nodes/VariableNode.kt index 0fdf887..fe9a7dd 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/VariableNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/nodes/VariableNode.kt @@ -1,4 +1,6 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.nodes + +import org.nwapw.abacus.tree.Reducer /** * A tree node that holds a placeholder variable. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/standard/NumberReducer.kt similarity index 95% rename from core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt rename to core/src/main/kotlin/org/nwapw/abacus/tree/standard/NumberReducer.kt index 1d9885a..6daec11 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/standard/NumberReducer.kt @@ -1,10 +1,12 @@ -package org.nwapw.abacus.tree +package org.nwapw.abacus.tree.standard import org.nwapw.abacus.Abacus import org.nwapw.abacus.context.EvaluationContext import org.nwapw.abacus.exception.NumberReducerException import org.nwapw.abacus.exception.ReductionException import org.nwapw.abacus.number.NumberInterface +import org.nwapw.abacus.tree.Reducer +import org.nwapw.abacus.tree.nodes.* class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer { @@ -40,7 +42,7 @@ class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer { + is NumberFunctionNode -> { val promotionResult = promotionManager .promote(*children.map { it as NumberInterface }.toTypedArray()) context.numberImplementation = promotionResult.promotedTo diff --git a/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java b/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java index f4d5597..2d636de 100755 --- a/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java @@ -8,7 +8,7 @@ import org.nwapw.abacus.config.Configuration; import org.nwapw.abacus.exception.DomainException; import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.plugin.standard.StandardPlugin; -import org.nwapw.abacus.tree.TreeNode; +import org.nwapw.abacus.tree.nodes.TreeNode; public class CalculationTests { diff --git a/core/src/test/java/org/nwapw/abacus/tests/LexerTests.java b/core/src/test/java/org/nwapw/abacus/tests/LexerTests.java index 80a8dfb..05f7947 100644 --- a/core/src/test/java/org/nwapw/abacus/tests/LexerTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/LexerTests.java @@ -3,7 +3,7 @@ package org.nwapw.abacus.tests; import org.junit.Assert; import org.junit.Test; import org.nwapw.abacus.lexing.Lexer; -import org.nwapw.abacus.lexing.pattern.Match; +import org.nwapw.abacus.lexing.Match; import java.util.List; diff --git a/core/src/test/java/org/nwapw/abacus/tests/RangeTests.java b/core/src/test/java/org/nwapw/abacus/tests/RangeTests.java index a9c0cf1..9b87ef3 100644 --- a/core/src/test/java/org/nwapw/abacus/tests/RangeTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/RangeTests.java @@ -5,10 +5,10 @@ import org.junit.BeforeClass; import org.junit.Test; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; -import org.nwapw.abacus.number.NaiveNumber; +import org.nwapw.abacus.number.standard.NaiveNumber; import org.nwapw.abacus.number.NumberInterface; -import org.nwapw.abacus.number.NumberRange; -import org.nwapw.abacus.number.PreciseNumber; +import org.nwapw.abacus.number.range.NumberRange; +import org.nwapw.abacus.number.standard.PreciseNumber; import org.nwapw.abacus.plugin.standard.StandardPlugin; import java.util.function.Function; diff --git a/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java b/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java index 8293bd4..148f121 100644 --- a/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/TokenizerTests.java @@ -7,11 +7,13 @@ import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; import org.nwapw.abacus.context.MutableEvaluationContext; import org.nwapw.abacus.function.*; -import org.nwapw.abacus.lexing.pattern.Match; +import org.nwapw.abacus.function.interfaces.NumberFunction; +import org.nwapw.abacus.function.interfaces.NumberOperator; +import org.nwapw.abacus.lexing.Match; import org.nwapw.abacus.number.NumberInterface; -import org.nwapw.abacus.parsing.LexerTokenizer; +import org.nwapw.abacus.parsing.standard.LexerTokenizer; import org.nwapw.abacus.plugin.Plugin; -import org.nwapw.abacus.tree.TokenType; +import org.nwapw.abacus.parsing.standard.TokenType; import java.util.List; diff --git a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java index fc9d6cb..fa6883e 100644 --- a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -20,8 +20,8 @@ import org.nwapw.abacus.plugin.ClassFinder; import org.nwapw.abacus.plugin.PluginListener; import org.nwapw.abacus.plugin.PluginManager; import org.nwapw.abacus.plugin.standard.StandardPlugin; -import org.nwapw.abacus.tree.EvaluationResult; -import org.nwapw.abacus.tree.TreeNode; +import org.nwapw.abacus.EvaluationResult; +import org.nwapw.abacus.tree.nodes.TreeNode; import java.io.File; import java.io.IOException;