From f3814a84f8471684cd483347db4fb7b107c2e635 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 3 Dec 2020 19:28:15 -0500 Subject: Rename interfaces to match Java style Rename several interfaces that were in the style IWhatever, which Java doesn't use --- .../bjc/utils/components/ComponentDescription.java | 6 +- .../bjc/utils/components/ComponentRepository.java | 49 ++++++++ .../bjc/utils/components/DescribedComponent.java | 64 ++++++++++ .../utils/components/FileComponentRepository.java | 4 +- .../bjc/utils/components/IComponentRepository.java | 49 -------- .../bjc/utils/components/IDescribedComponent.java | 64 ---------- .../components/MemoryComponentRepository.java | 4 +- .../src/main/java/bjc/utils/funcutils/Builder.java | 34 ++++++ .../main/java/bjc/utils/funcutils/IBuilder.java | 34 ------ .../java/bjc/utils/parserutils/IPrecedent.java | 28 ----- .../main/java/bjc/utils/parserutils/Precedent.java | 28 +++++ .../java/bjc/utils/parserutils/ShuntingYard.java | 8 +- .../utils/patterns/FunctionalPatternMatcher.java | 2 +- .../java/bjc/utils/patterns/IPatternMatcher.java | 85 ------------- .../bjc/utils/patterns/MutablePatternMatcher.java | 2 +- .../java/bjc/utils/patterns/PatternMatcher.java | 96 +++++++++++---- .../bjc/utils/patterns/SimplePatternMatcher.java | 41 +++++++ .../java/bjc/utils/ioutils/format/CLFormatter.java | 6 +- .../java/bjc/utils/ioutils/format/CLTokenizer.java | 36 +++--- .../bjc/utils/ioutils/format/ClauseDecree.java | 16 +-- .../main/java/bjc/utils/ioutils/format/Decree.java | 131 ++------------------- .../java/bjc/utils/ioutils/format/GroupDecree.java | 10 +- .../java/bjc/utils/ioutils/format/IDecree.java | 14 --- .../bjc/utils/ioutils/format/SimpleDecree.java | 129 ++++++++++++++++++++ .../ioutils/format/directives/CompileContext.java | 4 +- .../format/directives/FormatParameters.java | 4 +- .../format/directives/InflectDirective.java | 8 +- .../format/directives/IterationDirective.java | 8 +- .../bjc/utils/test/ioutils/CLTokenizerTest.java | 2 +- 29 files changed, 483 insertions(+), 483 deletions(-) create mode 100644 base/src/main/java/bjc/utils/components/ComponentRepository.java create mode 100644 base/src/main/java/bjc/utils/components/DescribedComponent.java delete mode 100644 base/src/main/java/bjc/utils/components/IComponentRepository.java delete mode 100644 base/src/main/java/bjc/utils/components/IDescribedComponent.java create mode 100644 base/src/main/java/bjc/utils/funcutils/Builder.java delete mode 100644 base/src/main/java/bjc/utils/funcutils/IBuilder.java delete mode 100644 base/src/main/java/bjc/utils/parserutils/IPrecedent.java create mode 100644 base/src/main/java/bjc/utils/parserutils/Precedent.java delete mode 100644 base/src/main/java/bjc/utils/patterns/IPatternMatcher.java create mode 100644 base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java delete mode 100644 clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java create mode 100644 clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java diff --git a/base/src/main/java/bjc/utils/components/ComponentDescription.java b/base/src/main/java/bjc/utils/components/ComponentDescription.java index 189ef90..2feed8d 100644 --- a/base/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/base/src/main/java/bjc/utils/components/ComponentDescription.java @@ -5,7 +5,7 @@ package bjc.utils.components; * * @author ben */ -public class ComponentDescription implements IDescribedComponent { +public class ComponentDescription implements DescribedComponent { /* Check arguments are good. */ @SuppressWarnings("unused") private static void sanityCheckArgs(final String name, final String author, @@ -58,7 +58,7 @@ public class ComponentDescription implements IDescribedComponent { @Override public String getAuthor() { if (author == null) { - return IDescribedComponent.super.getAuthor(); + return DescribedComponent.super.getAuthor(); } return author; @@ -67,7 +67,7 @@ public class ComponentDescription implements IDescribedComponent { @Override public String getDescription() { if (description == null) { - return IDescribedComponent.super.getDescription(); + return DescribedComponent.super.getDescription(); } return description; diff --git a/base/src/main/java/bjc/utils/components/ComponentRepository.java b/base/src/main/java/bjc/utils/components/ComponentRepository.java new file mode 100644 index 0000000..120edc8 --- /dev/null +++ b/base/src/main/java/bjc/utils/components/ComponentRepository.java @@ -0,0 +1,49 @@ +package bjc.utils.components; + +import bjc.funcdata.ListEx; +import bjc.funcdata.MapEx; + +/** + * A collection of implementations of a particular type of + * {@link DescribedComponent}. + * + * @author ben + * + * @param + * The type of components contained in this repository. + */ +public interface ComponentRepository { + /** + * Get all of the components this repository knows about. + * + * @return A map from component name to component, containing all of the + * components in the repositories. + */ + public MapEx getAll(); + + /** + * Get a component with a specific name. + * + * @param name + * The name of the component to retrieve. + * + * @return The named component, or null if no component with that name exists. + */ + public ComponentType getByName(String name); + + /** + * Get a list of all the registered components. + * + * @return A list of all the registered components. + */ + public default ListEx getList() { + return getAll().valueList(); + } + + /** + * Get the source from which these components came. + * + * @return The source from which these components came. + */ + public String getSource(); +} diff --git a/base/src/main/java/bjc/utils/components/DescribedComponent.java b/base/src/main/java/bjc/utils/components/DescribedComponent.java new file mode 100644 index 0000000..dcbaf59 --- /dev/null +++ b/base/src/main/java/bjc/utils/components/DescribedComponent.java @@ -0,0 +1,64 @@ +package bjc.utils.components; + +/** + * Represents a optional component that has status information associated with + * it. + * + * @author ben + * + */ +public interface DescribedComponent extends Comparable { + /** + * Get the author of this component. + * + * Providing this is optional, with "Anonymous" as the default author. + * + * @return The author of the component. + */ + default String getAuthor() { + return "Anonymous"; + } + + /** + * Get the description of this component. + * + * Providing this is optional, with the default being a note that no description + * was provided. + * + * @return The description of the component + */ + default String getDescription() { + return "No description provided."; + } + + /** + * Get the name of this component. + * + * This is the only thing required of all components. + * + * @return The name of the component. + */ + String getName(); + + /** + * Get the version of this component. + * + * Providing this is optional, with "1" as the default version. + * + * @return The version of this component. + */ + default int getVersion() { + return 1; + } + + @Override + default int compareTo(final DescribedComponent o) { + int res = getName().compareTo(o.getName()); + + if (res == 0) { + res = getVersion() - o.getVersion(); + } + + return res; + } +} diff --git a/base/src/main/java/bjc/utils/components/FileComponentRepository.java b/base/src/main/java/bjc/utils/components/FileComponentRepository.java index fa98d03..e0e929f 100644 --- a/base/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/base/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -24,8 +24,8 @@ import bjc.utils.funcutils.FileUtils; * @param * The type of component being read in. */ -public class FileComponentRepository - implements IComponentRepository { +public class FileComponentRepository + implements ComponentRepository { /* The logger to use for storing data about this class. */ private static final Logger CLASS_LOGGER = Logger.getLogger("FileComponentRepository"); diff --git a/base/src/main/java/bjc/utils/components/IComponentRepository.java b/base/src/main/java/bjc/utils/components/IComponentRepository.java deleted file mode 100644 index 7a40541..0000000 --- a/base/src/main/java/bjc/utils/components/IComponentRepository.java +++ /dev/null @@ -1,49 +0,0 @@ -package bjc.utils.components; - -import bjc.funcdata.ListEx; -import bjc.funcdata.MapEx; - -/** - * A collection of implementations of a particular type of - * {@link IDescribedComponent}. - * - * @author ben - * - * @param - * The type of components contained in this repository. - */ -public interface IComponentRepository { - /** - * Get all of the components this repository knows about. - * - * @return A map from component name to component, containing all of the - * components in the repositories. - */ - public MapEx getAll(); - - /** - * Get a component with a specific name. - * - * @param name - * The name of the component to retrieve. - * - * @return The named component, or null if no component with that name exists. - */ - public ComponentType getByName(String name); - - /** - * Get a list of all the registered components. - * - * @return A list of all the registered components. - */ - public default ListEx getList() { - return getAll().valueList(); - } - - /** - * Get the source from which these components came. - * - * @return The source from which these components came. - */ - public String getSource(); -} diff --git a/base/src/main/java/bjc/utils/components/IDescribedComponent.java b/base/src/main/java/bjc/utils/components/IDescribedComponent.java deleted file mode 100644 index ae3e06c..0000000 --- a/base/src/main/java/bjc/utils/components/IDescribedComponent.java +++ /dev/null @@ -1,64 +0,0 @@ -package bjc.utils.components; - -/** - * Represents a optional component that has status information associated with - * it. - * - * @author ben - * - */ -public interface IDescribedComponent extends Comparable { - /** - * Get the author of this component. - * - * Providing this is optional, with "Anonymous" as the default author. - * - * @return The author of the component. - */ - default String getAuthor() { - return "Anonymous"; - } - - /** - * Get the description of this component. - * - * Providing this is optional, with the default being a note that no description - * was provided. - * - * @return The description of the component - */ - default String getDescription() { - return "No description provided."; - } - - /** - * Get the name of this component. - * - * This is the only thing required of all components. - * - * @return The name of the component. - */ - String getName(); - - /** - * Get the version of this component. - * - * Providing this is optional, with "1" as the default version. - * - * @return The version of this component. - */ - default int getVersion() { - return 1; - } - - @Override - default int compareTo(final IDescribedComponent o) { - int res = getName().compareTo(o.getName()); - - if (res == 0) { - res = getVersion() - o.getVersion(); - } - - return res; - } -} diff --git a/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java b/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java index 2e11616..f83c293 100644 --- a/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java +++ b/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java @@ -10,8 +10,8 @@ import bjc.funcdata.MapEx; * @param * The type of component stored in the repository. */ -public class MemoryComponentRepository - implements IComponentRepository { +public class MemoryComponentRepository + implements ComponentRepository { private final MapEx repo; private final String source; diff --git a/base/src/main/java/bjc/utils/funcutils/Builder.java b/base/src/main/java/bjc/utils/funcutils/Builder.java new file mode 100644 index 0000000..72c045d --- /dev/null +++ b/base/src/main/java/bjc/utils/funcutils/Builder.java @@ -0,0 +1,34 @@ +package bjc.utils.funcutils; + +/** + * Generic interface for objects that implement the builder pattern. + * + * @author ben + * + * @param + * The type of object being built. + */ +public interface Builder { + /** + * Build the object this builder is building. + * + * @return The built object. + * + * @throws IllegalStateException + * If the data in the builder cannot be built into + * its corresponding object at this point in time. + */ + public E build(); + + /** + * Reset the state of this builder to its initial state. + * + * @throws UnsupportedOperationException + * If the builder doesn't support + * resetting its state. + */ + public default void reset() { + throw new UnsupportedOperationException( + "Builder doesn't support state resetting"); + } +} diff --git a/base/src/main/java/bjc/utils/funcutils/IBuilder.java b/base/src/main/java/bjc/utils/funcutils/IBuilder.java deleted file mode 100644 index b1a2020..0000000 --- a/base/src/main/java/bjc/utils/funcutils/IBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -package bjc.utils.funcutils; - -/** - * Generic interface for objects that implement the builder pattern. - * - * @author ben - * - * @param - * The type of object being built. - */ -public interface IBuilder { - /** - * Build the object this builder is building. - * - * @return The built object. - * - * @throws IllegalStateException - * If the data in the builder cannot be built into - * its corresponding object at this point in time. - */ - public E build(); - - /** - * Reset the state of this builder to its initial state. - * - * @throws UnsupportedOperationException - * If the builder doesn't support - * resetting its state. - */ - public default void reset() { - throw new UnsupportedOperationException( - "Builder doesn't support state resetting"); - } -} diff --git a/base/src/main/java/bjc/utils/parserutils/IPrecedent.java b/base/src/main/java/bjc/utils/parserutils/IPrecedent.java deleted file mode 100644 index eb164b3..0000000 --- a/base/src/main/java/bjc/utils/parserutils/IPrecedent.java +++ /dev/null @@ -1,28 +0,0 @@ -package bjc.utils.parserutils; - -/** - * Represents something that has a set precedence - * - * @author ben - * - */ -@FunctionalInterface -public interface IPrecedent { - /** - * Create a new object with set precedence - * - * @param precedence - * The precedence of the object to handle - * @return A new object with set precedence - */ - public static IPrecedent newSimplePrecedent(final int precedence) { - return () -> precedence; - } - - /** - * Get the precedence of the attached object - * - * @return The precedence of the attached object - */ - public int getPrecedence(); -} diff --git a/base/src/main/java/bjc/utils/parserutils/Precedent.java b/base/src/main/java/bjc/utils/parserutils/Precedent.java new file mode 100644 index 0000000..33b032c --- /dev/null +++ b/base/src/main/java/bjc/utils/parserutils/Precedent.java @@ -0,0 +1,28 @@ +package bjc.utils.parserutils; + +/** + * Represents something that has a set precedence + * + * @author ben + * + */ +@FunctionalInterface +public interface Precedent { + /** + * Create a new object with set precedence + * + * @param precedence + * The precedence of the object to handle + * @return A new object with set precedence + */ + public static Precedent newSimplePrecedent(final int precedence) { + return () -> precedence; + } + + /** + * Get the precedence of the attached object + * + * @return The precedence of the attached object + */ + public int getPrecedence(); +} diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java index f73c315..f0475ff 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -25,7 +25,7 @@ public class ShuntingYard { * @author ben * */ - public static enum Operator implements IPrecedent { + public static enum Operator implements Precedent { /** * Represents addition. */ @@ -59,7 +59,7 @@ public class ShuntingYard { /* * Holds all the shuntable operations. */ - private MapEx operators; + private MapEx operators; /** * Create a new shunting yard with a default set of operators. @@ -95,7 +95,7 @@ public class ShuntingYard { /* * Create the precedence marker */ - final IPrecedent prec = IPrecedent.newSimplePrecedent(precedence); + final Precedent prec = Precedent.newSimplePrecedent(precedence); this.addOp(operator, prec); } @@ -109,7 +109,7 @@ public class ShuntingYard { * @param precedence * The precedence of the operator. */ - public void addOp(final String operator, final IPrecedent precedence) { + public void addOp(final String operator, final Precedent precedence) { /* * Complain about trying to add an incorrect operator */ diff --git a/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java b/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java index 5a214d3..e370fa0 100644 --- a/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java +++ b/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java @@ -11,7 +11,7 @@ import bjc.functypes.*; * @param The type to match against. */ public class FunctionalPatternMatcher - implements IPatternMatcher { + implements PatternMatcher { private final ThrowFunction matcher; diff --git a/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java b/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java deleted file mode 100644 index b688a47..0000000 --- a/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java +++ /dev/null @@ -1,85 +0,0 @@ -package bjc.utils.patterns; - -import java.util.function.*; - -import bjc.functypes.*; - -/** - * Represents a pattern matcher against a series of patterns. - * - * @author Ben Culkin - * - * @param The type returned from matching the patterns. - * @param The type to match against. - */ -@FunctionalInterface -public interface IPatternMatcher { - /** - * Match an input object against a set of patterns. - * - * @param input The object to match against. - * - * @return The result of matching against the object. - * - * @throws NonExhaustiveMatch If none of the patterns in this set match - */ - ReturnType matchFor(InputType input) throws NonExhaustiveMatch; - - /** - * Create a pattern matcher against a static set of patterns. - * - * @param The type returned from matching the patterns. - * @param The type to match against. - * - * @param patterns The set of patterns to match on. - * - * @return A pattern matcher which matches on the given patterns. - */ - @SafeVarargs - static IPatternMatcher matchingOn( - ComplexPattern... patterns) { - return new PatternMatcher<>(patterns); - } - - /** - * Create a pattern matcher from a handler function. - * - * @param The type returned by the matcher. - * @param The type to match against. - * - * @param handler The handler function. - * - * @return A pattern matcher defined by the given handler. - */ - static IPatternMatcher from( - ThrowFunction handler) { - return new FunctionalPatternMatcher<>(handler); - } - - /** - * Create a pattern matcher which applies a transform to its input. - * - * @param The new input type to use. - * @param transformer The function to convert from the new input to the old input. - * - * @return A pattern matcher which takes values of the new type instead. - */ - default IPatternMatcher transformInput( - Function transformer) { - return from(inp -> matchFor(transformer.apply(inp))); - } - - /** - * Create a pattern matcher which applies a transform to its output. - * - * @param The new output type to use. - * - * @param transformer The function to convert from the new output to the old output. - * - * @return A pattern matcher which takes values of the new type instead. - */ - default IPatternMatcher transformOutput( - Function transformer) { - return from(inp -> transformer.apply(matchFor(inp))); - } -} \ No newline at end of file diff --git a/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java b/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java index 17de37a..28e9cd7 100644 --- a/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java +++ b/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java @@ -16,7 +16,7 @@ import bjc.data.*; * @param The type of the input to match against. */ public class MutablePatternMatcher - implements IPatternMatcher { + implements PatternMatcher { private final List> patterns; /** diff --git a/base/src/main/java/bjc/utils/patterns/PatternMatcher.java b/base/src/main/java/bjc/utils/patterns/PatternMatcher.java index f144d36..40bf42b 100644 --- a/base/src/main/java/bjc/utils/patterns/PatternMatcher.java +++ b/base/src/main/java/bjc/utils/patterns/PatternMatcher.java @@ -1,41 +1,85 @@ package bjc.utils.patterns; -import bjc.data.*; +import java.util.function.*; + +import bjc.functypes.*; /** - * Implements pattern-matching (of a sort) against a collection of patterns. + * Represents a pattern matcher against a series of patterns. * * @author Ben Culkin - * - * @param The type returned by the pattern. + * + * @param The type returned from matching the patterns. + * @param The type to match against. */ -public class PatternMatcher - implements IPatternMatcher { - private final ComplexPattern[] patterns; +@FunctionalInterface +public interface PatternMatcher { + /** + * Match an input object against a set of patterns. + * + * @param input The object to match against. + * + * @return The result of matching against the object. + * + * @throws NonExhaustiveMatch If none of the patterns in this set match + */ + ReturnType matchFor(InputType input) throws NonExhaustiveMatch; /** - * Create a new pattern matcher. + * Create a pattern matcher against a static set of patterns. * - * @param patterns The set of patterns to match against. + * @param The type returned from matching the patterns. + * @param The type to match against. + * + * @param patterns The set of patterns to match on. + * + * @return A pattern matcher which matches on the given patterns. */ - @SuppressWarnings("unchecked") @SafeVarargs - public PatternMatcher(ComplexPattern...patterns) { - // Note: this may seem a somewhat questionable cast, but because we never - // actually do anything with the value who has a type matching the second - // parameter, this should be safe - this.patterns = (ComplexPattern[]) patterns; + static PatternMatcher matchingOn( + ComplexPattern... patterns) { + return new SimplePatternMatcher<>(patterns); + } + + /** + * Create a pattern matcher from a handler function. + * + * @param The type returned by the matcher. + * @param The type to match against. + * + * @param handler The handler function. + * + * @return A pattern matcher defined by the given handler. + */ + static PatternMatcher from( + ThrowFunction handler) { + return new FunctionalPatternMatcher<>(handler); + } + + /** + * Create a pattern matcher which applies a transform to its input. + * + * @param The new input type to use. + * @param transformer The function to convert from the new input to the old input. + * + * @return A pattern matcher which takes values of the new type instead. + */ + default PatternMatcher transformInput( + Function transformer) { + return from(inp -> matchFor(transformer.apply(inp))); } - @Override - public ReturnType matchFor(InputType input) throws NonExhaustiveMatch { - for (ComplexPattern pattern : patterns) { - Pair matches = pattern.matches(input); - if (matches.getLeft()) { - pattern.apply(input, matches.getRight()); - } - } - - throw new NonExhaustiveMatch("Non-exhaustive match against " + input); + /** + * Create a pattern matcher which applies a transform to its output. + * + * @param The new output type to use. + * + * @param transformer The function to convert from the new output to the old output. + * + * @return A pattern matcher which takes values of the new type instead. + */ + default PatternMatcher transformOutput( + Function transformer) { + return from(inp -> transformer.apply(matchFor(inp))); } -} +} \ No newline at end of file diff --git a/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java b/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java new file mode 100644 index 0000000..fea947a --- /dev/null +++ b/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java @@ -0,0 +1,41 @@ +package bjc.utils.patterns; + +import bjc.data.*; + +/** + * Implements pattern-matching (of a sort) against a collection of patterns. + * + * @author Ben Culkin + * + * @param The type returned by the pattern. + */ +public class SimplePatternMatcher + implements PatternMatcher { + private final ComplexPattern[] patterns; + + /** + * Create a new pattern matcher. + * + * @param patterns The set of patterns to match against. + */ + @SuppressWarnings("unchecked") + @SafeVarargs + public SimplePatternMatcher(ComplexPattern...patterns) { + // Note: this may seem a somewhat questionable cast, but because we never + // actually do anything with the value who has a type matching the second + // parameter, this should be safe + this.patterns = (ComplexPattern[]) patterns; + } + + @Override + public ReturnType matchFor(InputType input) throws NonExhaustiveMatch { + for (ComplexPattern pattern : patterns) { + Pair matches = pattern.matches(input); + if (matches.getLeft()) { + pattern.apply(input, matches.getRight()); + } + } + + throw new NonExhaustiveMatch("Non-exhaustive match against " + input); + } +} diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java index 6908773..c55fda4 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java @@ -299,7 +299,7 @@ public class CLFormatter { boolean isToplevel) throws IOException { try { while (cltok.hasNext()) { - Decree decr = cltok.next(); + SimpleDecree decr = cltok.next(); if (decr.isLiteral) { rw.write(decr.name); @@ -411,7 +411,7 @@ public class CLFormatter { * * @return A set of edicts compiled from the decrees. */ - public List compile(Iterable decrees) { + public List compile(Iterable decrees) { // If we have no decrees, there are no edicts. if (decrees == null) return new ArrayList<>(); @@ -444,7 +444,7 @@ public class CLFormatter { List result = new ArrayList<>(); while (cltok.hasNext()) { - Decree decr = cltok.next(); + SimpleDecree decr = cltok.next(); String nam = decr.name; CompileContext compCTX = new CompileContext(cltok, this, decr); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java index 94437ee..7ed76d2 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java @@ -9,7 +9,7 @@ import java.util.regex.*; * @author bjculkin * */ -public class CLTokenizer implements Iterator { +public class CLTokenizer implements Iterator { /** * Whether or not the tokenizer is in debug mode or not. */ @@ -19,13 +19,13 @@ public class CLTokenizer implements Iterator { * Internal class for a tokenizer that returns a specific set of tokens. */ private static class SetCLTokenizer extends CLTokenizer { - private Iterator body; + private Iterator body; - public SetCLTokenizer(Iterator bod) { + public SetCLTokenizer(Iterator bod) { body = bod; } - public SetCLTokenizer(Iterable bod) { + public SetCLTokenizer(Iterable bod) { body = bod.iterator(); } @@ -35,14 +35,14 @@ public class CLTokenizer implements Iterator { } @Override - public Decree next() { + public SimpleDecree next() { return body.next(); } } private Matcher mat; - private Decree dir; + private SimpleDecree dir; /** * Empty constructor that should only be invoked if you are a subclass who @@ -70,7 +70,7 @@ public class CLTokenizer implements Iterator { * * @return A tokenizer yielding the given set of decrees. */ - public static CLTokenizer fromTokens(Iterator bod) { + public static CLTokenizer fromTokens(Iterator bod) { return new SetCLTokenizer(bod); } @@ -82,7 +82,7 @@ public class CLTokenizer implements Iterator { * * @return A tokenizer yielding the given set of decrees. */ - public static CLTokenizer fromTokens(Iterable bod) { + public static CLTokenizer fromTokens(Iterable bod) { return new SetCLTokenizer(bod); } @@ -92,15 +92,15 @@ public class CLTokenizer implements Iterator { } @Override - public Decree next() { + public SimpleDecree next() { return getNext(); } - private Decree getNext() { + private SimpleDecree getNext() { if (!hasNext()) throw new NoSuchElementException("No possible decrees remaining"); if (dir != null) { - Decree tmp = dir; + SimpleDecree tmp = dir; dir = null; @@ -125,25 +125,25 @@ public class CLTokenizer implements Iterator { boolean isUser = directiveName == null && directiveFunction != null; - dir = new Decree(directiveName, isUser, + dir = new SimpleDecree(directiveName, isUser, CLParameters.fromDirective(directiveParameterString), CLModifiers.fromString(directiveModifierString)); } if (tmp.equals("")) { - Decree dcr = dir; + SimpleDecree dcr = dir; dir = null; return dcr; } - return new Decree(sb.toString()); + return new SimpleDecree(sb.toString()); } mat.appendTail(sb); - return new Decree(sb.toString()); + return new SimpleDecree(sb.toString()); } /** @@ -157,7 +157,7 @@ public class CLTokenizer implements Iterator { * * @return A group decree with the given properties. */ - public GroupDecree nextGroup(Decree openedWith, String desiredClosing) { + public GroupDecree nextGroup(SimpleDecree openedWith, String desiredClosing) { return nextGroup(openedWith, desiredClosing, null); } @@ -177,7 +177,7 @@ public class CLTokenizer implements Iterator { * * @return A group decree with the given properties. */ - public GroupDecree nextGroup(Decree openedWith, String desiredClosing, + public GroupDecree nextGroup(SimpleDecree openedWith, String desiredClosing, String clauseSep) { GroupDecree newGroup = new GroupDecree(); newGroup.opening = openedWith; @@ -188,7 +188,7 @@ public class CLTokenizer implements Iterator { int nestingLevel = 1; - Decree curDecree; + SimpleDecree curDecree; do { curDecree = next(); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java index 9db248c..db38eca 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/ClauseDecree.java @@ -13,16 +13,16 @@ import bjc.utils.ioutils.ReportWriter; * * @author Ben Culkin */ -public class ClauseDecree implements IDecree { +public class ClauseDecree implements Decree { /** * The decrees that make up the body of this clause. */ - public List body; + public List body; /** * The decree that terminated this clause. */ - public Decree terminator; + public SimpleDecree terminator; /** * Create a new blank clause decree. @@ -38,10 +38,10 @@ public class ClauseDecree implements IDecree { * @param children * The decrees to form the body of the clause. */ - public ClauseDecree(Decree... children) { + public ClauseDecree(SimpleDecree... children) { this(); - for (Decree child : children) body.add(child); + for (SimpleDecree child : children) body.add(child); } /** @@ -53,7 +53,7 @@ public class ClauseDecree implements IDecree { * @param children * The decrees that form the body of the clause. */ - public ClauseDecree(Decree term, Decree... children) { + public ClauseDecree(SimpleDecree term, SimpleDecree... children) { this(children); this.terminator = term; @@ -65,7 +65,7 @@ public class ClauseDecree implements IDecree { * @param child * The decree to add to this clause. */ - public void addChild(Decree child) { + public void addChild(SimpleDecree child) { body.add(child); } @@ -96,7 +96,7 @@ public class ClauseDecree implements IDecree { writer.write("\n"); int idx = 0; - for (Decree kid : body) + for (SimpleDecree kid : body) writer.writef("Child %d: %s\n", idx, kid.toString()); writer.dedent(); diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java b/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java index 115ef0d..e06caf0 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/Decree.java @@ -1,129 +1,14 @@ package bjc.utils.ioutils.format; /** - * A decree is the building blocks of what we need to pick and call a directive. + * Interface for all decrees. + * + * At the moment, this is just a marker interface, but there may be things added + * here. + * + * @author Ben Culkin * - * Namely, it is the name of the directive, any modifiers attached to the - * directive, and any prefix parameters that are also attached to the directive. - * - * @author Ben Culkin. */ -public class Decree implements IDecree { - /** - * The name of the directive. - */ - public String name; - - /** - * Is this directive an actual directive, or just a literal string? - */ - public boolean isLiteral; - - /** - * Is this directive a user function call? - */ - public boolean isUserCall; - - /** - * The prefix parameters for this directive. - */ - public CLParameters parameters; - - /** - * The modifiers for this directive. - */ - public CLModifiers modifiers; - - /** - * Create a new blank decree. - */ - public Decree() { - - } - - /** - * Create a new literal text directive. - * - * @param txt - * The text of the directive. - */ - public Decree(String txt) { - this.name = txt; - - this.isLiteral = true; - } - - /** - * Create a new directive. - * - * @param name - * The name of the directive. Whether or not it is an actual - * directive will be auto-determined (if it starts with a ~, it's - * a directive.) - * - * @param params - * The prefix parameters to the directive. - * - * @param mods - * The modifiers to the directive. - */ - public Decree(String name, CLParameters params, CLModifiers mods) { - this.name = name; - - this.parameters = params; - - this.modifiers = mods; - - this.isLiteral = false; - } - - /** - * Create a new directive that may be a user function. - * - * @param name - * The name of the directive. Whether or not it is an actual - * directive will be auto-determined (if it starts with a ~ and is - * not a user function, it's a directive.) - * - * @param isUser - * Is this directive a user function? - * - * @param params - * The prefix parameters to the directive. - * - * @param mods - * The modifiers to the directive. - */ - public Decree(String name, boolean isUser, CLParameters params, CLModifiers mods) { - this.name = name; - - this.parameters = params; - - this.modifiers = mods; - - this.isUserCall = isUser; - - this.isLiteral = isUser; - } - - /** - * Check if this decree is a non-literal, with a particular name. - * - * @param nam - * The name to see if we have. - * - * @return Whether or not the provided name equals our name. - */ - public boolean isNamed(String nam) { - // Literals don't have a meaningful name - if (isLiteral) return false; - else return name.equals(nam); - } - - @Override - public String toString() { - return String.format( - "Decree [name='%s', isLiteral=%s, isUserCall=%s, parameters=%s, modifiers='%s']", - name, isLiteral, isUserCall, parameters, modifiers); - } +public interface Decree { + // Marker interface, for now } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java index 7095aa5..c1c5c7b 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/GroupDecree.java @@ -13,16 +13,16 @@ import bjc.utils.ioutils.ReportWriter; * * @author Ben Culkin */ -public class GroupDecree implements Iterable, IDecree { +public class GroupDecree implements Iterable, Decree { /** * The decree that opened this group. */ - public Decree opening; + public SimpleDecree opening; /** * The decree that closed this group. */ - public Decree closing; + public SimpleDecree closing; /** * The clauses that make up the body of this group. @@ -60,7 +60,7 @@ public class GroupDecree implements Iterable, IDecree { * @param children * The decree making up the body of the group. */ - public GroupDecree(Decree opening, Decree closing, ClauseDecree... children) { + public GroupDecree(SimpleDecree opening, SimpleDecree closing, ClauseDecree... children) { this(children); this.opening = opening; @@ -103,7 +103,7 @@ public class GroupDecree implements Iterable, IDecree { * * @return The decrees that make up the body of the first clause. */ - public List unwrap() { + public List unwrap() { return body.get(0).body; } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java deleted file mode 100644 index 17b9ecf..0000000 --- a/clformat/src/main/java/bjc/utils/ioutils/format/IDecree.java +++ /dev/null @@ -1,14 +0,0 @@ -package bjc.utils.ioutils.format; - -/** - * Interface for all decrees. - * - * At the moment, this is just a marker interface, but there may be things added - * here. - * - * @author Ben Culkin - * - */ -public interface IDecree { - // Marker interface, for now -} diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java new file mode 100644 index 0000000..a7db42f --- /dev/null +++ b/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java @@ -0,0 +1,129 @@ +package bjc.utils.ioutils.format; + +/** + * A decree is the building blocks of what we need to pick and call a directive. + * + * Namely, it is the name of the directive, any modifiers attached to the + * directive, and any prefix parameters that are also attached to the directive. + * + * @author Ben Culkin. + */ +public class SimpleDecree implements Decree { + /** + * The name of the directive. + */ + public String name; + + /** + * Is this directive an actual directive, or just a literal string? + */ + public boolean isLiteral; + + /** + * Is this directive a user function call? + */ + public boolean isUserCall; + + /** + * The prefix parameters for this directive. + */ + public CLParameters parameters; + + /** + * The modifiers for this directive. + */ + public CLModifiers modifiers; + + /** + * Create a new blank decree. + */ + public SimpleDecree() { + + } + + /** + * Create a new literal text directive. + * + * @param txt + * The text of the directive. + */ + public SimpleDecree(String txt) { + this.name = txt; + + this.isLiteral = true; + } + + /** + * Create a new directive. + * + * @param name + * The name of the directive. Whether or not it is an actual + * directive will be auto-determined (if it starts with a ~, it's + * a directive.) + * + * @param params + * The prefix parameters to the directive. + * + * @param mods + * The modifiers to the directive. + */ + public SimpleDecree(String name, CLParameters params, CLModifiers mods) { + this.name = name; + + this.parameters = params; + + this.modifiers = mods; + + this.isLiteral = false; + } + + /** + * Create a new directive that may be a user function. + * + * @param name + * The name of the directive. Whether or not it is an actual + * directive will be auto-determined (if it starts with a ~ and is + * not a user function, it's a directive.) + * + * @param isUser + * Is this directive a user function? + * + * @param params + * The prefix parameters to the directive. + * + * @param mods + * The modifiers to the directive. + */ + public SimpleDecree(String name, boolean isUser, CLParameters params, CLModifiers mods) { + this.name = name; + + this.parameters = params; + + this.modifiers = mods; + + this.isUserCall = isUser; + + this.isLiteral = isUser; + } + + /** + * Check if this decree is a non-literal, with a particular name. + * + * @param nam + * The name to see if we have. + * + * @return Whether or not the provided name equals our name. + */ + public boolean isNamed(String nam) { + // Literals don't have a meaningful name + if (isLiteral) return false; + else return name.equals(nam); + } + + @Override + public String toString() { + return String.format( + "Decree [name='%s', isLiteral=%s, isUserCall=%s, parameters=%s, modifiers='%s']", + name, isLiteral, isUserCall, parameters, modifiers); + } +} diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java index 3c5f692..77c8402 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/CompileContext.java @@ -21,7 +21,7 @@ public class CompileContext { /** * The decree that is currently being parsed. */ - public Decree decr; + public SimpleDecree decr; /** * Create a new compilation context. @@ -35,7 +35,7 @@ public class CompileContext { * @param dcr * The decree currently being compiled. */ - public CompileContext(CLTokenizer dirs, CLFormatter fmt, Decree dcr) { + public CompileContext(CLTokenizer dirs, CLFormatter fmt, SimpleDecree dcr) { directives = dirs; formatter = fmt; diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java index d206d17..e2884d3 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/FormatParameters.java @@ -28,7 +28,7 @@ public class FormatParameters { /** * The current decree. */ - public Decree decr; + public SimpleDecree decr; /** * The current format parameters. @@ -66,7 +66,7 @@ public class FormatParameters { * @param formatter * The formatter we are using */ - public FormatParameters(ReportWriter writer, Object item, Decree decr, + public FormatParameters(ReportWriter writer, Object item, SimpleDecree decr, Tape tParams, CLTokenizer dirIter, CLFormatter formatter) { this.writer = writer; diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java index c4b2edb..937bd9d 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/InflectDirective.java @@ -15,13 +15,13 @@ import bjc.utils.ioutils.format.*; public class InflectDirective implements Directive { @Override public Edict compile(CompileContext compCTX) { - List body = new ArrayList<>(); + List body = new ArrayList<>(); int nestLevel = 1; - Iterator dirIter = compCTX.directives; + Iterator dirIter = compCTX.directives; while (dirIter.hasNext()) { - Decree decr = dirIter.next(); + SimpleDecree decr = dirIter.next(); if (decr.isLiteral) { body.add(decr); @@ -62,7 +62,7 @@ public class InflectDirective implements Directive { class InflectEdict implements Edict { private CLString body; - public InflectEdict(List body, CLFormatter fmt) { + public InflectEdict(List body, CLFormatter fmt) { this.body = new CLString(fmt.compile(body)); } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java index 4b3b193..34f815d 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IterationDirective.java @@ -16,12 +16,12 @@ public class IterationDirective implements Directive { public Edict compile(CompileContext compCTX) { IterationEdict.Mode mode; - List body = new ArrayList<>(); + List body = new ArrayList<>(); - Iterator dirIter = compCTX.directives; + Iterator dirIter = compCTX.directives; // :GroupDecree while (dirIter.hasNext()) { - Decree decr = dirIter.next(); + SimpleDecree decr = dirIter.next(); if (decr.isLiteral) { body.add(decr); } else { @@ -73,7 +73,7 @@ class IterationEdict implements Edict { private CLValue maxItrVal; - public IterationEdict(Mode mode, List body, CLFormatter fmt, CLValue maxItr) { + public IterationEdict(Mode mode, List body, CLFormatter fmt, CLValue maxItr) { this.mode = mode; this.body = new CLString(fmt.compile(body)); diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java index 429c089..20d64b0 100644 --- a/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java +++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLTokenizerTest.java @@ -18,7 +18,7 @@ public class CLTokenizerTest { CLTokenizer tokenzer = new CLTokenizer(""); assertTrue("Empty tokenizer has a decree", tokenzer.hasNext()); - Decree dec = tokenzer.next(); + SimpleDecree dec = tokenzer.next(); assertFalse("Empty tokenizer has only one decree", tokenzer.hasNext()); assertTrue("Decree from empty tokenizer is a literal", dec.isLiteral); -- cgit v1.2.3