diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands')
7 files changed, 92 insertions, 75 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java index b263422..3c3a89b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/AbstractInitialCommand.java @@ -6,14 +6,27 @@ import bjc.utils.parserutils.pratt.InitialCommand; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * Abstract base for initial commands. + * + * @author bjculkin + * + * @param <K> + * The key type of the tokens. + * + * @param <V> + * The value type of the tokens. + * + * @param <C> + * The state type of the parser. + */ public abstract class AbstractInitialCommand<K, V, C> implements InitialCommand<K, V, C> { @Override - public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) - throws ParserException { + public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException { return intNullDenotation(operator, ctx); } - protected abstract ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, - ParserContext<K, V, C> ctx) throws ParserException; + protected abstract ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx) + throws ParserException; }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java index bf6786b..781309c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryCommand.java @@ -6,16 +6,36 @@ import bjc.utils.parserutils.ParserException; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * A binary operator. + * + * @author bjculkin + * + * @param <K> + * The key type of the tokens. + * + * @param <V> + * The value type of the tokens. + * + * @param <C> + * The state type of the parser. + */ public abstract class BinaryCommand<K, V, C> extends BinaryPostCommand<K, V, C> { - public BinaryCommand(int leftPower) { - super(leftPower); + /** + * Create a new binary operator with the specified precedence. + * + * @param precedence + * The precedence of the operator. + */ + public BinaryCommand(int precedence) { + super(precedence); } protected abstract int rightBinding(); @Override - public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, - ParserContext<K, V, C> ctx) throws ParserException { + public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx) + throws ParserException { ITree<Token<K, V>> opr = ctx.parse.parseExpression(rightBinding(), ctx.tokens, ctx.state, false); return new Tree<>(operator, operand, opr); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java index aa85f75..1324586 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ChainCommand.java @@ -8,21 +8,47 @@ import bjc.utils.parserutils.pratt.Token; import java.util.Set; +/** + * Create a new chained operator. + * + * @author bjculkin + * + * @param <K> + * The key type of the tokens. + * + * @param <V> + * The value type of the tokens. + * + * @param <C> + * The state type of the parser. + */ public class ChainCommand<K, V, C> extends BinaryPostCommand<K, V, C> { private Set<K> chainWith; private Token<K, V> chain; - public ChainCommand(int leftPower, Set<K> chainSet, Token<K, V> chainMarker) { - super(leftPower); + /** + * Create a new chained operator. + * + * @param precedence + * The precedence of this operator. + * + * @param chainSet + * The operators to chain with. + * + * @param chainMarker + * The token to use as the node in the AST. + */ + public ChainCommand(int precedence, Set<K> chainSet, Token<K, V> chainMarker) { + super(precedence); chainWith = chainSet; chain = chainMarker; } @Override - public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, - ParserContext<K, V, C> ctx) throws ParserException { + public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx) + throws ParserException { ITree<Token<K, V>> tree = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, false); ITree<Token<K, V>> res = new Tree<>(operator, operand, tree); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java index 2308cc7..10ff184 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/ConstantCommand.java @@ -6,16 +6,35 @@ import bjc.utils.parserutils.pratt.InitialCommand; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * A command that represents a specific tree. + * + * @author bjculkin + * + * @param <K> + * The key type of the tokens. + * + * @param <V> + * The value type of the tokens. + * + * @param <C> + * The state type of the parser. + */ public class ConstantCommand<K, V, C> implements InitialCommand<K, V, C> { private ITree<Token<K, V>> val; + /** + * Create a new constant. + * + * @param con + * The tree this constant represents. + */ public ConstantCommand(ITree<Token<K, V>> con) { val = con; } @Override - public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) - throws ParserException { + public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException { return val; } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java index 8c500a9..887dd25 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/DefaultNonInitialCommand.java @@ -20,7 +20,6 @@ import bjc.utils.parserutils.pratt.Token; * The state type of the parser. */ public class DefaultNonInitialCommand<K, V, C> extends NonInitialCommand<K, V, C> { - @Override public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx) { throw new UnsupportedOperationException("Default command has no left denotation"); @@ -30,5 +29,4 @@ public class DefaultNonInitialCommand<K, V, C> extends NonInitialCommand<K, V, C public int leftBinding() { return -1; } - } diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java deleted file mode 100644 index 554cf30..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InitialInterleaveCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -package bjc.utils.parserutils.pratt.commands; - -import bjc.utils.data.ITree; -import bjc.utils.parserutils.ParserException; -import bjc.utils.parserutils.pratt.ParserContext; -import bjc.utils.parserutils.pratt.Token; - -/** - * Represents a configurable initial command. - * - * @author EVE - * - * @param <K> - * The token key type. - * - * @param <V> - * The token value type. - * - * @param <C> - * The parser state type. - */ -public class InitialInterleaveCommand<K, V, C> extends AbstractInitialCommand<K, V, C> { - @Override - protected ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx) - throws ParserException { - return null; - } - -} diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java deleted file mode 100644 index fa2c592..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/InterleaveSpecifier.java +++ /dev/null @@ -1,30 +0,0 @@ -package bjc.utils.parserutils.pratt.commands; - -/** - * The specifier for what to do for each element of a command. - * - * @author EVE - * - */ -public class InterleaveSpecifier { - /** - * The type of this specifier. - * - * @author EVE - * - */ - public static enum Type { - /** - * Parse an expression with the given priority. - */ - EXPRESSION, - /** - * Parse a statement with the given priority. - */ - STATEMENT, - /** - * Expect a token of a certain type to be present. - */ - EXPECT, LITERAL; - } -}
\ No newline at end of file |
