private void processANDorOROp(Operator op, Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { if (expStack.isEmpty()) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } ExpressionNode top = expStack.pop(); if (top.isSingleNode()) { if (top == LeafExpressionNode.OPEN_PARAN_NODE) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } expStack.push(new NonLeafExpressionNode(op, top)); } else { NonLeafExpressionNode nlTop = (NonLeafExpressionNode) top; if (nlTop.getChildExps().size() != 2) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } expStack.push(new NonLeafExpressionNode(op, nlTop)); } }
private void processNOTOp(Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { // When ! comes, the stack can be empty or top ( or top can be some exp like // a& // !!.., a!, a&b!, !a! are invalid if (!expStack.isEmpty()) { ExpressionNode top = expStack.peek(); if (top.isSingleNode() && top != LeafExpressionNode.OPEN_PARAN_NODE) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } if (!top.isSingleNode() && ((NonLeafExpressionNode) top).getChildExps().size() != 1) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } } expStack.push(new NonLeafExpressionNode(Operator.NOT)); }
private void processOpenParan(Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { if (!expStack.isEmpty()) { ExpressionNode top = expStack.peek(); // Top can not be a Label Node. a(.. is not valid. but ((a.. is fine. if (top instanceof LeafExpressionNode && top != LeafExpressionNode.OPEN_PARAN_NODE) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } else if (top instanceof NonLeafExpressionNode) { // Top is non leaf. // It can be ! node but with out any child nodes. !a(.. is invalid // Other NonLeafExpressionNode , then there should be exactly 1 child. // a&b( is not valid. // a&( is valid though. Also !( is valid NonLeafExpressionNode nlTop = (NonLeafExpressionNode) top; if ((nlTop.getOperator() == Operator.NOT && nlTop.getChildExps().size() != 0) || (nlTop.getOperator() != Operator.NOT && nlTop.getChildExps().size() != 1)) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } } } expStack.push(LeafExpressionNode.OPEN_PARAN_NODE); }
private void processLabelExpNode(LeafExpressionNode node, Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { if (expStack.isEmpty()) { expStack.push(node); } else { ExpressionNode top = expStack.peek(); if (top == LeafExpressionNode.OPEN_PARAN_NODE) { expStack.push(node); } else if (top instanceof NonLeafExpressionNode) { NonLeafExpressionNode nlTop = (NonLeafExpressionNode) expStack.pop(); nlTop.addChildExp(node); if (nlTop.getOperator() == Operator.NOT && !expStack.isEmpty()) { ExpressionNode secondTop = expStack.peek(); if (secondTop == LeafExpressionNode.OPEN_PARAN_NODE) { expStack.push(nlTop); } else if (secondTop instanceof NonLeafExpressionNode) { ((NonLeafExpressionNode) secondTop).addChildExp(nlTop); } } else { expStack.push(nlTop); } } else { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } } }
throw new ParseException(); } else { ExpressionNode top = expStack.pop(); throw new ParseException("Error parsing expression " + expS + " at column : " + index); if ((nlTop.getOperator() == Operator.NOT && nlTop.getChildExps().size() != 1) || (nlTop.getOperator() != Operator.NOT && nlTop.getChildExps().size() != 2)) { throw new ParseException("Error parsing expression " + expS + " at column : " + index);
index++; if (exp[index] != '\\' && exp[index] != '"') throw new ParseException("invalid escaping with quotes " + expS + " at column : " + index); throw new ParseException("No terminating quotes " + expS + " at column : " + index); String leafExp = Bytes.toString(array).trim(); if (leafExp.isEmpty()) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); do { if (!VisibilityLabelsValidator.isValidAuthChar(exp[index])) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); new String(exp, labelOffset, index - labelOffset, StandardCharsets.UTF_8).trim(); if (leafExp.isEmpty()) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); throw new ParseException("Error parsing expression " + expS); throw new ParseException("Error parsing expression " + expS); if (nlTop.getOperator() == Operator.NOT) { if (nlTop.getChildExps().size() != 1) { throw new ParseException("Error parsing expression " + expS); throw new ParseException("Error parsing expression " + expS);
private void processANDorOROp(Operator op, Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { if (expStack.isEmpty()) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } ExpressionNode top = expStack.pop(); if (top.isSingleNode()) { if (top == LeafExpressionNode.OPEN_PARAN_NODE) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } expStack.push(new NonLeafExpressionNode(op, top)); } else { NonLeafExpressionNode nlTop = (NonLeafExpressionNode) top; if (nlTop.getChildExps().size() != 2) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } expStack.push(new NonLeafExpressionNode(op, nlTop)); } }
private void processNOTOp(Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { // When ! comes, the stack can be empty or top ( or top can be some exp like // a& // !!.., a!, a&b!, !a! are invalid if (!expStack.isEmpty()) { ExpressionNode top = expStack.peek(); if (top.isSingleNode() && top != LeafExpressionNode.OPEN_PARAN_NODE) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } if (!top.isSingleNode() && ((NonLeafExpressionNode) top).getChildExps().size() != 1) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } } expStack.push(new NonLeafExpressionNode(Operator.NOT)); }
private void processLabelExpNode(LeafExpressionNode node, Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { if (expStack.isEmpty()) { expStack.push(node); } else { ExpressionNode top = expStack.peek(); if (top == LeafExpressionNode.OPEN_PARAN_NODE) { expStack.push(node); } else if (top instanceof NonLeafExpressionNode) { NonLeafExpressionNode nlTop = (NonLeafExpressionNode) expStack.pop(); nlTop.addChildExp(node); if (nlTop.getOperator() == Operator.NOT && !expStack.isEmpty()) { ExpressionNode secondTop = expStack.peek(); if (secondTop == LeafExpressionNode.OPEN_PARAN_NODE) { expStack.push(nlTop); } else if (secondTop instanceof NonLeafExpressionNode) { ((NonLeafExpressionNode) secondTop).addChildExp(nlTop); } } else { expStack.push(nlTop); } } else { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } } }
private void processOpenParan(Stack<ExpressionNode> expStack, String expS, int index) throws ParseException { if (!expStack.isEmpty()) { ExpressionNode top = expStack.peek(); // Top can not be a Label Node. a(.. is not valid. but ((a.. is fine. if (top instanceof LeafExpressionNode && top != LeafExpressionNode.OPEN_PARAN_NODE) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } else if (top instanceof NonLeafExpressionNode) { // Top is non leaf. // It can be ! node but with out any child nodes. !a(.. is invalid // Other NonLeafExpressionNode , then there should be exactly 1 child. // a&b( is not valid. // a&( is valid though. Also !( is valid NonLeafExpressionNode nlTop = (NonLeafExpressionNode) top; if ((nlTop.getOperator() == Operator.NOT && nlTop.getChildExps().size() != 0) || (nlTop.getOperator() != Operator.NOT && nlTop.getChildExps().size() != 1)) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); } } } expStack.push(LeafExpressionNode.OPEN_PARAN_NODE); }
throw new ParseException(); } else { ExpressionNode top = expStack.pop(); throw new ParseException("Error parsing expression " + expS + " at column : " + index); if ((nlTop.getOperator() == Operator.NOT && nlTop.getChildExps().size() != 1) || (nlTop.getOperator() != Operator.NOT && nlTop.getChildExps().size() != 2)) { throw new ParseException("Error parsing expression " + expS + " at column : " + index);
index++; if (exp[index] != '\\' && exp[index] != '"') throw new ParseException("invalid escaping with quotes " + expS + " at column : " + index); throw new ParseException("No terminating quotes " + expS + " at column : " + index); String leafExp = Bytes.toString(array).trim(); if (leafExp.isEmpty()) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); do { if (!VisibilityLabelsValidator.isValidAuthChar(exp[index])) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); leafExp = new String(exp, labelOffset, index - labelOffset).trim(); if (leafExp.isEmpty()) { throw new ParseException("Error parsing expression " + expS + " at column : " + index); throw new ParseException("Error parsing expression " + expS); throw new ParseException("Error parsing expression " + expS); if (nlTop.getOperator() == Operator.NOT) { if (nlTop.getChildExps().size() != 1) { throw new ParseException("Error parsing expression " + expS); throw new ParseException("Error parsing expression " + expS);