diff options
Diffstat (limited to 'clformat')
5 files changed, 58 insertions, 113 deletions
diff --git a/clformat/.settings/org.eclipse.jdt.core.prefs b/clformat/.settings/org.eclipse.jdt.core.prefs index 74568b3..aeacc3c 100644 --- a/clformat/.settings/org.eclipse.jdt.core.prefs +++ b/clformat/.settings/org.eclipse.jdt.core.prefs @@ -1,109 +1,7 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= -org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullable.secondary= -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.compliance=17 -org.eclipse.jdt.core.compiler.problem.APILeak=warning -org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=info -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore -org.eclipse.jdt.core.compiler.problem.localVariableHiding=info -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=info -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=info -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning -org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning -org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=info -org.eclipse.jdt.core.compiler.problem.potentialNullReference=info -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=info -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=info -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=info -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info -org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=info -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning -org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled -org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=info -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=info -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=info -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=17 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 7ed76d2..9fd56f5 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java @@ -128,6 +128,8 @@ public class CLTokenizer implements Iterator<SimpleDecree> { dir = new SimpleDecree(directiveName, isUser, CLParameters.fromDirective(directiveParameterString), CLModifiers.fromString(directiveModifierString)); + + dir.setPosition(mat.start(), mat.end()); } if (tmp.equals("")) { @@ -138,7 +140,7 @@ public class CLTokenizer implements Iterator<SimpleDecree> { return dcr; } - return new SimpleDecree(sb.toString()); + return new SimpleDecree(sb.toString(), mat.start(), mat.end()); } mat.appendTail(sb); @@ -182,7 +184,10 @@ public class CLTokenizer implements Iterator<SimpleDecree> { GroupDecree newGroup = new GroupDecree(); newGroup.opening = openedWith; - if (!hasNext()) throw new NoSuchElementException("No decrees available"); + if (!hasNext()) { + String fmt = "No decrees available for group starting with %s at %#s"; + throw new NoSuchElementException(String.format(fmt, openedWith.name, openedWith.position)); + } ClauseDecree curClause = new ClauseDecree(); @@ -233,8 +238,8 @@ public class CLTokenizer implements Iterator<SimpleDecree> { if (newGroup.closing == null) { String msg = String.format( - "Did not find closing directive for group (wanted \"%s\", last decree was \"%s\")", - desiredClosing, curDecree.name); + "Did not find closing directive for group (wanted \"%s\", last decree was \"%s\" at %#s)", + desiredClosing, curDecree.name, curDecree.position); throw new NoSuchElementException(msg); } diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java index a7db42f..35d4355 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java @@ -1,5 +1,8 @@ package bjc.utils.ioutils.format; +import bjc.data.Pair; +import bjc.data.SimplePair; + /** * A decree is the building blocks of what we need to pick and call a directive. * @@ -35,6 +38,11 @@ public class SimpleDecree implements Decree { public CLModifiers modifiers; /** + * The position in the input this decree had + */ + public Pair<Integer, Integer> position; + + /** * Create a new blank decree. */ public SimpleDecree() { @@ -54,6 +62,20 @@ public class SimpleDecree implements Decree { } /** + * Create a new literal text directive. + * + * @param txt + * The text of the directive. + * @param start The starting position of this directive + * @param end The ending position of this directive + */ + public SimpleDecree(String txt, int start, int end) { + this(txt); + + this.setPosition(start, end); + } + + /** * Create a new directive. * * @param name @@ -120,6 +142,16 @@ public class SimpleDecree implements Decree { else return name.equals(nam); } + /** + * Set the position of this decree. + * + * @param start The starting position of this decree + * @param end The ending position of this decree + */ + public void setPosition(int start, int end) { + position = new SimplePair<>(start, end); + } + @Override public String toString() { return String.format( diff --git a/clformat/src/main/java/module-info.java b/clformat/src/main/java/module-info.java index d32a9a7..51396bf 100644 --- a/clformat/src/main/java/module-info.java +++ b/clformat/src/main/java/module-info.java @@ -1,10 +1,21 @@ +/** + * Represents an implementation of string formatting which is inspired by Common + * Lisps FORMAT. + * + * I say inspired because there are a number of extensions to it, as well as a + * few things that either aren't implemented, or are implemented in a different + * way. + * + * @author bjculkin + * + */ module clformat { exports bjc.utils.ioutils.format.directives; exports bjc.utils.ioutils.format; exports bjc.utils.ioutils.format.exceptions; - requires bjc.utils; - requires esodata; + requires transitive bjc.utils; + requires transitive esodata; requires inflexion; requires junit; }
\ No newline at end of file diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java index 629e802..250e52c 100644 --- a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java +++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java @@ -101,13 +101,12 @@ public class CLFormatterTest { assertEquals("XIV xiv", format("~@R ~(~@R~)", 14, 14)); } - // @Test +// @Test public void testListPrinting() { // Test printing a list - // String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#[~; and~] - // ~A~^,~}~]."; - String fmtStr - = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#*[ ~A,~; and ~A~; ~A~]~}~]."; + String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#[~; and~]~A~^,~}~]."; +// String fmtStr +// = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#*[ ~A,~; and ~A~; ~A~]~}~]."; fmt.DEBUG = true; assertEquals("Items: none.", format(fmtStr)); |
