@Override public Object get(Context<Object> context) { return context.getValueStack().pop(); }
@Override public final boolean run(Context<Object> context) { B builder = builder(); context.getValueStack().push(builder); return true; }
@Override public final T get(Context<Object> context) { @SuppressWarnings("unchecked") B builder = (B) context.getValueStack().pop(); return build(builder); }
@Override public final boolean run(Context<Object> context) { Object value = get(context); context.getValueStack().push(value); return true; } }
private static void printContext(Object caller, Context<Object> context) { String message = ErrorUtils.printErrorMessage("%s:%s:%s", "", context.getCurrentIndex(), context.getCurrentIndex() + 1, context.getInputBuffer()); System.err.println("*** " + caller + message + "\n\t" + Joiner.on("\n\t - ").join(context.getValueStack())); } }
@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; }
Node parseListBlock(StringBuilderVar block) { Context<Object> context = getContext(); Node innerRoot = parseInternal(block); setContext(context); // we need to save and restore the context since we might be recursing block.clearContents(); //debugMsg("parsed list block " + innerRoot.toString() + " adjusting indices by " + getContext().getValueStack().peek(), block.getString()); return withIndicesShifted(innerRoot, (Integer) context.getValueStack().pop()); }
/** * Pushes the given value onto the value stack. Equivalent to push(0, value). * * @param value the value to push * @return true */ public boolean push(V value) { check(); context.getValueStack().push(value); return true; }
/** * Removes the value at the top of the value stack. * * @return true * @throws IllegalArgumentException if the stack is empty */ public boolean drop() { check(); context.getValueStack().pop(); return true; }
/** * Duplicates the top value of the value stack. Equivalent to push(peek()). * * @return true * @throws IllegalArgumentException if the stack is empty */ public boolean dup() { check(); context.getValueStack().dup(); return true; }
/** * 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); }
/** * Replaces the current top value of the value stack with the given value. Equivalent to poke(0, value). * * @param value the value * @return true * @throws IllegalArgumentException if the stack is empty */ public boolean poke(V value) { check(); context.getValueStack().poke(value); return true; }
/** * Reverses the order of the top 4 value stack elements. * * @return true * @throws org.parboiled.errors.GrammarException * if the stack does not contain at least 4 elements */ public boolean swap4() { check(); context.getValueStack().swap4(); return true; }
/** * Reverses the order of the top 6 value stack elements. * * @return true * @throws org.parboiled.errors.GrammarException * if the stack does not contain at least 6 elements */ public boolean swap6() { check(); context.getValueStack().swap6(); return true; }
@Override public final T get(Context<Object> context) { @SuppressWarnings("unchecked") B builder = (B) context.getValueStack().pop(); return build(builder); }
@Override public final boolean run(Context<Object> context) { B builder = builder(); context.getValueStack().push(builder); return true; }
private static void printContext(Object caller, Context<Object> context) { String message = ErrorUtils.printErrorMessage("%s:%s:%s", "", context.getCurrentIndex(), context.getCurrentIndex() + 1, context.getInputBuffer()); System.err.println("*** " + caller + message + "\n\t" + Joiner.on("\n\t - ").join(context.getValueStack())); } }
@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; }
<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; }