summaryrefslogtreecommitdiff
path: root/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-06-03 17:33:53 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-06-03 17:33:53 -0400
commit15a2b29e48f134bc93cfd0a3d8512001e9242f3d (patch)
treeb3f5c4c5f0e474479cd47ad0ac0f35770fc44881 /JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java
parent39ba97edf49270715ec61bedb7d4a62ada819ba0 (diff)
Rename package to new domainHEADtrunk
Rename the package to the new domain
Diffstat (limited to 'JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java')
-rw-r--r--JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java91
1 files changed, 0 insertions, 91 deletions
diff --git a/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java b/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java
deleted file mode 100644
index 446b80b..0000000
--- a/JPratt/src/main/java/bjc/pratt/blocks/GrammarParseBlock.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package bjc.pratt.blocks;
-
-import java.util.function.Function;
-
-import bjc.data.Tree;
-import bjc.pratt.ParserContext;
-import bjc.pratt.PrattParser;
-import bjc.pratt.commands.CommandResult;
-import bjc.pratt.tokens.Token;
-import bjc.pratt.tokens.TokenStream;
-import bjc.typeclasses.Isomorphism;
-import bjc.data.Tree;
-import bjc.functypes.*;
-import bjc.utils.parserutils.ParserException;
-
-/**
- * A {@link ParseBlock} that parses an expression from a 'inner' grammar.
- *
- * @author bjculkin
- *
- * @param <K> The key type of the outer tokens.
- *
- * @param <V> The value type of the outer tokens.
- *
- * @param <C> The state type of the outer parser.
- *
- * @param <K2> The key type of the inner tokens.
- *
- * @param <V2> The value type of the inner tokens.
- *
- * @param <C2> The state type of the outer parser.
- */
-public class GrammarParseBlock<K, V, C, K2, V2, C2> implements ParseBlock<K, V, C> {
- private final PrattParser<K2, V2, C2> innr;
-
- private final int prcedence;
- private final boolean isStatemnt;
-
- private final Function<TokenStream<K, V>, TokenStream<K2, V2>> tkenTransform;
- private final Isomorphism<C, C2> stteTransform;
- private final Function<Tree<Token<K2, V2>>, Tree<Token<K, V>>> xpressionTransform;
-
- /**
- * Create a new grammar parser block.
- *
- * @param inner The inner grammar to parse.
- * @param precedence The precedence of the expression to parse.
- * @param isStatement Is the expression being parsed in statement
- * context?
- * @param tokenTransform Function to transform to the new token type.
- * @param stateTransform Function to toggle between state types.
- * @param expressionTransform Function to transform back to the normal token
- * type.
- */
- public GrammarParseBlock(final PrattParser<K2, V2, C2> inner, final int precedence, final boolean isStatement,
- final Function<TokenStream<K, V>, TokenStream<K2, V2>> tokenTransform,
- final Isomorphism<C, C2> stateTransform,
- final Function<Tree<Token<K2, V2>>, Tree<Token<K, V>>> expressionTransform) {
- innr = inner;
- prcedence = precedence;
- isStatemnt = isStatement;
- tkenTransform = tokenTransform;
- stteTransform = stateTransform;
- xpressionTransform = expressionTransform;
- }
-
- @Override
- public CommandResult<K, V> parse(final ParserContext<K, V, C> ctx) throws ParserException {
- final C2 newState = stteTransform.to(ctx.state);
-
- final TokenStream<K2, V2> newTokens = tkenTransform.apply(ctx.tokens);
-
- final CommandResult<K2, V2> res = innr.parseExpression(prcedence, newTokens, newState, isStatemnt);
- switch (res.status) {
- case SUCCESS:
- break;
- case FAIL:
- return CommandResult.fail();
- case BACKTRACK:
- return CommandResult.backtrack();
- default:
- throw new IllegalStateException("Unhandled status " + res.status);
- }
-
- Tree<Token<K2, V2>> expression = res.success();
-
- ctx.state = stteTransform.from(newState);
-
- return CommandResult.success(xpressionTransform.apply(expression));
- }
-} \ No newline at end of file