@Override public final boolean run(Context<Object> context) { V value = extractor.get(context); @SuppressWarnings("unchecked") B builder = (B) context.getValueStack().peek(); specify(builder, value); return true; }
boolean setListItemIndices() { SuperNode listItem = (SuperNode) getContext().getValueStack().peek(); List<Node> children = listItem.getChildren(); listItem.setStartIndex(children.get(0).getStartIndex()); listItem.setEndIndex(children.get(children.size() - 1).getEndIndex()); return true; }
/** * Returns the value at the top of the value stack without removing it. * * @return the current top value * @throws IllegalArgumentException if the stack is empty */ public V peek() { check(); return context.getValueStack().peek(); }
/** * Returns the value the given number of elements below the top of the value stack without removing it. * * @param down the number of elements to skip (0 being equivalent to peek()) * @return the value * @throws IllegalArgumentException if the stack does not contain enough elements to perform this operation */ public V peek(int down) { check(); return context.getValueStack().peek(down); }
<T> List<T> popAll(Class... classes) { ValueStack<Object> valueStack = getContext().getValueStack(); List<T> result = new ArrayList<T>(); while (!valueStack.isEmpty() && isInstance(classes, valueStack.peek())) { result.add((T) valueStack.pop()); } if (!valueStack.isEmpty() && valueStack.peek() == MARKER) { valueStack.pop(); } Collections.reverse(result); return result; }
@Override public final boolean run(Context<Object> context) { V value = extractor.get(context); @SuppressWarnings("unchecked") B builder = (B) context.getValueStack().peek(); specify(builder, value); return true; }
@Override public final boolean run(Context<Object> context) { V value = extractor.get(context); @SuppressWarnings("unchecked") B builder = (B) context.getValueStack().peek(); specify(builder, value); return true; }
@SuppressWarnings({"ConstantConditions"}) public void createNode() { if (!nodeSuppressed) { node = new NodeImpl<V>(matcher, getSubNodes(), startIndex, currentIndex, valueStack.isEmpty() ? null : valueStack.peek(), hasError); if (parent != null) { parent.subNodes = parent.subNodes.prepend(node); } } }
/** * Creates a new ParsingResult. * * @param matched true if the rule matched the input * @param parseTreeRoot the parse tree root node * @param valueStack the value stack of the parsing run * @param parseErrors the list of parse errors * @param inputBuffer the input buffer */ public ParsingResult(boolean matched, Node<V> parseTreeRoot, ValueStack<V> valueStack, List<ParseError> parseErrors, InputBuffer inputBuffer) { this.matched = matched; this.parseTreeRoot = parseTreeRoot; this.valueStack = checkArgNotNull(valueStack, "valueStack"); this.resultValue = valueStack.isEmpty() ? null : valueStack.peek(); this.parseErrors = checkArgNotNull(parseErrors, "parseErrors"); this.inputBuffer = checkArgNotNull(inputBuffer, "inputBuffer"); }