diff options
| author | Ben Culkin <scorpress@gmail.com> | 2022-09-27 19:18:09 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2022-09-27 19:18:09 -0400 |
| commit | 02af075e89fbdeb22575f235a3acb2607e0b4edf (patch) | |
| tree | bf31e1157732b1c421522301cf4d2a8ee7f4e3fb | |
| parent | cea3e47938322b97c318dea38dc0d649e196dc1b (diff) | |
Minor changes
17 files changed, 235 insertions, 15 deletions
diff --git a/JPratt/.settings/org.eclipse.jdt.core.prefs b/JPratt/.settings/org.eclipse.jdt.core.prefs index cf2cd45..40089f4 100644 --- a/JPratt/.settings/org.eclipse.jdt.core.prefs +++ b/JPratt/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,110 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled +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=info +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=disabled +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=info +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +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=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +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=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=info +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=info 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=ignore +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=info +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=ignore +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/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java index 9d05ca2..ac5aa12 100644 --- a/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java +++ b/JPratt/src/examples/java/bjc/pratt/examples/lang/PrattParserTest.java @@ -33,7 +33,6 @@ import bjc.pratt.commands.NonInitialCommand; import bjc.pratt.tokens.StringToken; import bjc.pratt.tokens.StringTokenStream; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.data.TransformIterator; import bjc.funcdata.ListEx; import bjc.utils.parserutils.ParserException; diff --git a/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java b/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java index 3f79665..b0a3844 100644 --- a/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java +++ b/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java @@ -5,7 +5,6 @@ import java.util.function.Function; import bjc.pratt.ParserContext; import bjc.pratt.PrattParser; import bjc.pratt.commands.CommandResult; -import bjc.pratt.commands.CommandResult.Status; import bjc.pratt.tokens.Token; import bjc.pratt.tokens.TokenStream; import bjc.data.Tree; diff --git a/JPratt/src/main/java/bjc/pratt/blocks/ParseBlock.java b/JPratt/src/main/java/bjc/pratt/blocks/ParseBlock.java index fede096..aa2fa2e 100644 --- a/JPratt/src/main/java/bjc/pratt/blocks/ParseBlock.java +++ b/JPratt/src/main/java/bjc/pratt/blocks/ParseBlock.java @@ -2,8 +2,6 @@ package bjc.pratt.blocks; import bjc.pratt.ParserContext; import bjc.pratt.commands.CommandResult; -import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java b/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java index df17595..d404eea 100644 --- a/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java +++ b/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java @@ -5,8 +5,6 @@ import java.util.function.UnaryOperator; import bjc.pratt.ParserContext; import bjc.pratt.commands.CommandResult; import bjc.pratt.commands.CommandResult.Status; -import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java index 48f9ba7..3e4f3a9 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java @@ -2,7 +2,6 @@ package bjc.pratt.commands; import bjc.pratt.ParserContext; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java index ba544b4..0cfa290 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java @@ -2,7 +2,6 @@ package bjc.pratt.commands; import bjc.pratt.ParserContext; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java index 1d54996..07d9a76 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java @@ -5,7 +5,6 @@ import bjc.pratt.blocks.ParseBlock; import bjc.pratt.commands.AbstractInitialCommand; import bjc.pratt.commands.CommandResult; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/DefaultInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/DefaultInitialCommand.java index 2dfc576..8d28b57 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/DefaultInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/impls/DefaultInitialCommand.java @@ -4,7 +4,6 @@ import bjc.pratt.ParserContext; import bjc.pratt.commands.CommandResult; import bjc.pratt.commands.InitialCommand; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/DenestingCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/DenestingCommand.java index 4935c81..de39e0b 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/DenestingCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/impls/DenestingCommand.java @@ -6,7 +6,6 @@ import bjc.pratt.commands.CommandResult; import bjc.pratt.commands.CommandResult.Status; import bjc.pratt.commands.InitialCommand; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.utils.parserutils.ParserException; /** diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java b/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java index 9801788..bfc4e4f 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java +++ b/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java @@ -9,8 +9,6 @@ import java.util.function.UnaryOperator; import bjc.pratt.blocks.ParseBlock; import bjc.pratt.commands.InitialCommand; import bjc.pratt.tokens.Token; -import bjc.utils.parserutils.ParserException; -import bjc.data.SimpleTree; import bjc.data.Tree; /** @@ -211,6 +209,6 @@ public class InitialCommands { * @return A command that implements a panfix operator */ public static <K, V, C> InitialCommand<K, V, C> panfix(final int precedence, final K term, final Token<K, V> marker) { - return new PanfixCommand<K, V, C>(marker, term, precedence); + return new PanfixCommand<>(marker, term, precedence); } }
\ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java index c702323..20fb3d4 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java @@ -4,7 +4,6 @@ import bjc.pratt.ParserContext; import bjc.pratt.commands.CommandResult; import bjc.pratt.commands.InitialCommand; import bjc.pratt.tokens.Token; -import bjc.data.Tree; import bjc.data.SimpleTree; import bjc.utils.parserutils.ParserException; diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/PanfixCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/PanfixCommand.java index 06e69c1..04ad370 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/PanfixCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/impls/PanfixCommand.java @@ -9,11 +9,26 @@ import bjc.pratt.commands.CommandResult.Status; import bjc.pratt.tokens.Token; import bjc.utils.parserutils.ParserException; +/** + * Represents a 'panfix' command, one where the operator is repeated prefix, infix and postfix. + * @author bjcul + * + * @param <K> The key type of the token + * @param <V> The value type of the token + * @param <C> The context type of the parser + */ public final class PanfixCommand<K, V, C> implements InitialCommand<K, V, C> { private final Token<K, V> marker; private final K term; private final int precedence; + /** + * Create a new panfix command. + * + * @param marker The marker token. + * @param term The value to use as the root of the result-tree + * @param precedence The precedence for this command + */ public PanfixCommand(Token<K, V> marker, K term, int precedence) { this.marker = marker; this.term = term; diff --git a/JPratt/src/main/java/bjc/pratt/tokens/StringTokenStream.java b/JPratt/src/main/java/bjc/pratt/tokens/StringTokenStream.java index 8c7fcec..70876f2 100644 --- a/JPratt/src/main/java/bjc/pratt/tokens/StringTokenStream.java +++ b/JPratt/src/main/java/bjc/pratt/tokens/StringTokenStream.java @@ -33,6 +33,9 @@ public class StringTokenStream extends TokenStream<String, String> { @Override public Token<String, String> current() { + // Prime stream if necessary + if (curr == null) + return next(); return curr; } @@ -70,6 +73,8 @@ public class StringTokenStream extends TokenStream<String, String> { @Override public void rollback() { iter.rollback(); + + curr = iter.current(); } @Override diff --git a/JPratt/src/test/java/bjc/test/pratt/PrattParserTest.java b/JPratt/src/test/java/bjc/test/pratt/PrattParserTest.java new file mode 100644 index 0000000..608a137 --- /dev/null +++ b/JPratt/src/test/java/bjc/test/pratt/PrattParserTest.java @@ -0,0 +1,58 @@ +package bjc.test.pratt; + +import static org.junit.Assert.*; +import static bjc.test.pratt.TestUtils.*; + +import java.util.Iterator; + +import org.junit.Test; + +import bjc.data.ArrayIterator; +import bjc.data.SimpleTree; +import bjc.data.Tree; +import bjc.pratt.PrattParser; +import bjc.pratt.commands.CommandResult; +import bjc.pratt.commands.impls.InitialCommands; +import bjc.pratt.commands.impls.NonInitialCommands; +import bjc.pratt.tokens.StringTokenStream; +import bjc.pratt.tokens.Token; +import bjc.utils.parserutils.ParserException; + +@SuppressWarnings("javadoc") +public class PrattParserTest { + + @Test + public void test() { + Iterator<Token<String, String>> iter = new ArrayIterator<>(token("(int)", "1"), token("+"), + token("(int)", "2")); + StringTokenStream tokens = new StringTokenStream(iter); + + PrattParser<String, String, TestState> parser = new PrattParser<>(); + + parser.addInitialCommand("(int)", InitialCommands.leaf()); + parser.addNonInitialCommand("+", NonInitialCommands.infixLeft(1)); + + try { + TestState state = new TestState(); + + tokens.mark(); + CommandResult<String, String> result = parser.parseExpression(0, tokens, state, false); + tokens.rollback(); + + assertEquals(CommandResult.Status.SUCCESS, result.status); + Tree<Token<String, String>> actualTree = result.success(); + + Tree<Token<String, String>> expectedTree = new SimpleTree<>(token("+"), + new SimpleTree<>(token("(int)", "1")), new SimpleTree<>(token("(int)", "2"))); + + assertEquals(expectedTree, actualTree); + } catch (ParserException e) { + e.printStackTrace(); + } + } + +} + +class TestState { + +} diff --git a/JPratt/src/test/java/bjc/test/pratt/TestUtils.java b/JPratt/src/test/java/bjc/test/pratt/TestUtils.java new file mode 100644 index 0000000..a32349f --- /dev/null +++ b/JPratt/src/test/java/bjc/test/pratt/TestUtils.java @@ -0,0 +1,15 @@ +package bjc.test.pratt; + +import bjc.pratt.tokens.StringToken; +import bjc.pratt.tokens.Token; + +public class TestUtils { + + public static Token<String, String> token(String val) { + return token(val, val); + } + + public static Token<String, String> token(String key, String val) { + return new StringToken(key, val); + } +} diff --git a/JPratt/src/test/java/bjc/test/pratt/tokens/StringTokenStreamTest.java b/JPratt/src/test/java/bjc/test/pratt/tokens/StringTokenStreamTest.java new file mode 100644 index 0000000..5bacac7 --- /dev/null +++ b/JPratt/src/test/java/bjc/test/pratt/tokens/StringTokenStreamTest.java @@ -0,0 +1,39 @@ +package bjc.test.pratt.tokens; + +import static org.junit.Assert.*; +import static bjc.test.pratt.TestUtils.*; + +import java.util.Iterator; + +import org.junit.Test; + +import bjc.data.ArrayIterator; +import bjc.pratt.tokens.StringTokenStream; +import bjc.pratt.tokens.Token; + +@SuppressWarnings("javadoc") +public class StringTokenStreamTest { + + @Test + public void test() { + Token<String, String> tokenA = token("a"); + Token<String, String> tokenB = token("b"); + Token<String, String> tokenC = token("c"); + Token<String, String> tokenD = token("d"); + + Iterator<Token<String, String>> itr = new ArrayIterator<>(tokenA, tokenB, tokenC, tokenD); + StringTokenStream strm = new StringTokenStream(itr); + + assertNull(strm.current()); + assertEquals(tokenA, strm.next()); + assertEquals(tokenB, strm.next()); + strm.mark(); + assertEquals(tokenC, strm.next()); + assertEquals(tokenD, strm.next()); + strm.rollback(); + assertEquals(tokenC, strm.next()); + assertEquals(tokenD, strm.next()); + assertEquals(token("(end)"), strm.next()); + } + +} |
