/** * walk the current operator and its descendants. * * @param nd * current operator in the graph * @throws SemanticException */ @Override protected void walk(Node nd) throws SemanticException { if (opStack.empty() || nd != opStack.peek()) { opStack.push(nd); } if (allParentsDispatched(nd)) { // all children are done or no need to walk the children if (!getDispatchedList().contains(nd)) { toWalk.addAll(nd.getChildren()); dispatch(nd, opStack); } opStack.pop(); return; } // add children, self to the front of the queue in that order toWalk.add(0, nd); addAllParents(nd); } }
private void shuntOperators(List<Token> outputQueue, Stack<Token> stack, LazyOperator o1) { Expression.Token nextToken = stack.isEmpty() ? null : stack.peek(); while (nextToken != null && (nextToken.type == Expression.TokenType.OPERATOR || nextToken.type == Expression.TokenType.UNARY_OPERATOR) && ((o1.isLeftAssoc() && o1.getPrecedence() <= operators.get(nextToken.surface).getPrecedence()) || (o1 .getPrecedence() < operators.get(nextToken.surface).getPrecedence()))) { outputQueue.add(stack.pop()); nextToken = stack.isEmpty() ? null : stack.peek(); } }
arity = arity.min(Math.max(1, arity.min)); // if key=value, minimum arity is at least 1 if (arity.min > 0 && !empty(cluster)) { if (tracer.isDebug()) {tracer.debug("Trying to process '%s' as option parameter%n", cluster);} if (!empty(cluster)) { args.push(cluster); // interpret remainder as option parameter (CAUTION: may be empty string!) parseResult.nowProcessing.add(argSpec); first = false; } else { int consumed = applyOption(argSpec, lookBehind, arity, args, initialized, argDescription); if (empty(cluster) || args.isEmpty() || args.size() < argCount) { return; cluster = args.pop(); } else { // cluster is empty || cluster.charAt(0) is not a short option key if (cluster.length() == 0) { // we finished parsing a group of short options like -rxv args.push(paramAttachedToOption ? prefix + cluster : cluster); if (args.peek().equals(arg)) { // #149 be consistent between unmatched short and long options if (tracer.isDebug()) {tracer.debug("Could not match any short options in %s, deciding whether to treat as unmatched option or positional parameter...%n", arg);} if (commandSpec.resemblesOption(arg, tracer)) { handleUnmatchedArgument(args); return; } // #149
private void validateRootExists(CaseInsensitiveString root, PipelineDependencyState pipelineDependencyState, Stack<CaseInsensitiveString> visiting) throws Exception { if (!pipelineDependencyState.hasPipeline(root)) { StringBuffer sb = new StringBuffer("Pipeline \""); sb.append(root); sb.append("\" does not exist."); visiting.pop(); if (!visiting.empty()) { CaseInsensitiveString parent = visiting.peek(); sb.append(" It is used from pipeline \""); sb.append(parent); sb.append("\"."); } throw new Exception(sb.toString()); } }
@Override public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { String tagName = localName.toUpperCase(Locale.ENGLISH); // make sure that this tag occurs in the proper context if(!elements.peek().isAllowed(tagName)) throw new SAXException(tagName+" is not allowed inside "+tagNames.peek()); Checker next = CHECKERS.get(tagName); if(next==null) next = ALL_ALLOWED; elements.push(next); tagNames.push(tagName); super.startElement(uri, localName, qName, atts); }
private Phrase getNext() { while (!iteratorStack.isEmpty()) { Iterator<Object> iter = iteratorStack.peek(); if (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof Phrase) { return (Phrase) obj; } else if (obj instanceof Map) { iteratorStack.push(((Map) obj).values().iterator()); } else if (obj instanceof List) { iteratorStack.push(((List) obj).iterator()); } else { throw new RuntimeException("Unexpected class in phrase table " + obj.getClass()); } } else { iteratorStack.pop(); } } return null; }
/** * walk the current operator and its descendants. * * @param nd * current operator in the graph * @throws SemanticException */ @Override protected void walk(Node nd) throws SemanticException { if (opStack.empty() || nd != opStack.peek()) { opStack.push(nd); } if (allParentsDispatched(nd)) { // all children are done or no need to walk the children if (!getDispatchedList().contains(nd)) { toWalk.addAll(nd.getChildren()); dispatch(nd, opStack); } opStack.pop(); return; } // add children, self to the front of the queue in that order toWalk.add(0, nd); addAllParents(nd); } }
private static void close(Stack<XNode> stack, String text) { U.must(!stack.isEmpty(), "Empty stack!"); XNode x = stack.pop(); U.must(x.op != XNode.OP.OP_ROOT, "Cannot close a tag that wasn't open: %s", text); if (!U.eq(x.text, text)) { throw U.rte("Expected block: %s, but found: %s", x.text, text); } stack.peek().children.add(x); }