diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-03-25 19:13:42 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-03-25 19:13:42 -0400 |
| commit | 42990231fee502552b769b9af4c04ac0dcaeb195 (patch) | |
| tree | 4dbe0ba0bc54fffafacc9ab12349efd76c52041c /BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java | |
| parent | 674d9769821775484fe6913b93c650189fbedfed (diff) | |
Update Pratt parser
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java index ba5099e..90fca00 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/PostCircumfixCommand.java @@ -3,29 +3,57 @@ package bjc.utils.parserutils.pratt.commands; import bjc.utils.data.ITree; import bjc.utils.data.Tree; import bjc.utils.parserutils.ParserException; +import bjc.utils.parserutils.pratt.ParseBlock; import bjc.utils.parserutils.pratt.ParserContext; import bjc.utils.parserutils.pratt.Token; +/** + * A post-circumfix operator, like array indexing. + * + * @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 PostCircumfixCommand<K, V, C> extends BinaryPostCommand<K, V, C> { - private int insidePrec; - private K term; - private Token<K, V> mark; + private ParseBlock<K, V, C> innerBlock; - public PostCircumfixCommand(int leftPower, int insidePower, K terminator, Token<K, V> marker) { - super(leftPower); + private Token<K, V> mark; + + /** + * Create a new post-circumfix operator. + * + * @param precedence + * The precedence of the operator. + * + * @param inner + * The block inside the expression. + * + * @param marker + * The token to use as the node for the AST. + */ + public PostCircumfixCommand(int precedence, ParseBlock<K, V, C> inner, Token<K, V> marker) { + super(precedence); + + if (inner == null) { + throw new NullPointerException("Inner block must not be null"); + } + + innerBlock = inner; - insidePrec = insidePower; - term = terminator; mark = marker; } - @SuppressWarnings("unchecked") @Override - 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>> inside = ctx.parse.parseExpression(insidePrec, ctx.tokens, ctx.state, false); - - ctx.tokens.expect(term); + 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>> inside = innerBlock.parse(ctx); return new Tree<>(mark, operand, inside); } |
