//partition by sep, to the end of the current stack level //start is the opening token of the current stack level public virtual Partition partitionBalanced(int sep, int start, int leftPush, int rightPop) { Partition part = new Partition(this); System.Collections.ArrayList sepIdxs = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); int end = indexOfBalanced(start, rightPop, leftPush, rightPop); if (end == -1) { return(null); } int k = start; do { k = indexOfBalanced(k, sep, leftPush, rightPop); if (k != -1) { sepIdxs.Add((System.Int32)k); part.separators.Add((System.Int32)sep); } }while (k != -1); for (int i = 0; i <= sepIdxs.Count; i++) { int pieceStart = (i == 0?start + 1:Parser.vectInt(sepIdxs, i - 1) + 1); int pieceEnd = (i == sepIdxs.Count?end:Parser.vectInt(sepIdxs, i)); part.pieces.Add(extract(pieceStart, pieceEnd)); } return(part); }
//paritition the range [start,end), separating by any occurrence of separator public virtual Partition partition(int[] separators, int start, int end) { Partition part = new Partition(this); System.Collections.ArrayList sepIdxs = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int i = start; i < end; i++) { for (int j = 0; j < separators.Length; j++) { if (getTokenType(i) == separators[j]) { part.separators.Add((System.Int32)separators[j]); sepIdxs.Add((System.Int32)i); break; } } } for (int i = 0; i <= sepIdxs.Count; i++) { int pieceStart = (i == 0?start:Parser.vectInt(sepIdxs, i - 1) + 1); int pieceEnd = (i == sepIdxs.Count?end:Parser.vectInt(sepIdxs, i)); part.pieces.Add(extract(pieceStart, pieceEnd)); } return(part); }
public override XPathExpression build() { System.Collections.ArrayList steps = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); XPathExpression filtExpr = null; int offset = Absolute?1:0; for (int i = 0; i < clauses.Count + offset; i++) { if (offset == 0 || i > 0) { if (clauses[i - offset] is ASTNodePathStep) { steps.Add(((ASTNodePathStep)clauses[i - offset]).Step); } else { filtExpr = ((ASTNode)clauses[i - offset]).build(); } } if (i < separators.Count) { if (Parser.vectInt(separators, i) == Token.DBL_SLASH) { steps.Add(XPathStep.ABBR_DESCENDANTS()); } } } XPathStep[] stepArr = new XPathStep[steps.Count]; for (int i = 0; i < stepArr.Length; i++) { stepArr[i] = (XPathStep)steps[i]; } if (filtExpr == null) { return(new XPathPathExpr(Absolute?XPathPathExpr.INIT_CONTEXT_ROOT:XPathPathExpr.INIT_CONTEXT_RELATIVE, stepArr)); } else { if (filtExpr is XPathFilterExpr) { return(new XPathPathExpr((XPathFilterExpr)filtExpr, stepArr)); } else { return(new XPathPathExpr(new XPathFilterExpr(filtExpr, new XPathExpression[0]), stepArr)); } } }
public override XPathExpression build() { XPathExpression x; if (associativity == ASSOC_LEFT) { x = ((ASTNode)exprs[0]).build(); for (int i = 1; i < exprs.Count; i++) { x = getBinOpExpr(Parser.vectInt(ops, i - 1), x, ((ASTNode)exprs[i]).build()); } } else { x = ((ASTNode)exprs[exprs.Count - 1]).build(); for (int i = exprs.Count - 2; i >= 0; i--) { x = getBinOpExpr(Parser.vectInt(ops, i), ((ASTNode)exprs[i]).build(), x); } } return(x); }
public static XPathExpression parseXPath(System.String xpath) { return(Parser.parse(Lexer.lex(xpath))); }
public virtual void print(System.Object o) { indent += 1; if (o is ASTNodeAbstractExpr) { ASTNodeAbstractExpr x = (ASTNodeAbstractExpr)o; printStr("abstractexpr {"); for (int i = 0; i < x.content.Count; i++) { if (x.getType(i) == ASTNodeAbstractExpr.CHILD) { print(x.content[i]); } else { printStr(x.getToken(i).ToString()); } } printStr("}"); } else if (o is ASTNodePredicate) { ASTNodePredicate x = (ASTNodePredicate)o; printStr("predicate {"); print(x.expr); printStr("}"); } else if (o is ASTNodeFunctionCall) { ASTNodeFunctionCall x = (ASTNodeFunctionCall)o; if (x.args.Count == 0) { printStr("func {" + x.name.ToString() + ", args {none}}"); } else { printStr("func {" + x.name.ToString() + ", args {{"); for (int i = 0; i < x.args.Count; i++) { print(x.args[i]); if (i < x.args.Count - 1) { printStr(" } {"); } } printStr("}}}"); } } else if (o is ASTNodeBinaryOp) { ASTNodeBinaryOp x = (ASTNodeBinaryOp)o; printStr("opexpr {"); for (int i = 0; i < x.exprs.Count; i++) { print(x.exprs[i]); if (i < x.exprs.Count - 1) { switch (Parser.vectInt(x.ops, i)) { case Token.AND: printStr("and:"); break; case Token.OR: printStr("or:"); break; case Token.EQ: printStr("eq:"); break; case Token.NEQ: printStr("neq:"); break; case Token.LT: printStr("lt:"); break; case Token.LTE: printStr("lte:"); break; case Token.GT: printStr("gt:"); break; case Token.GTE: printStr("gte:"); break; case Token.PLUS: printStr("plus:"); break; case Token.MINUS: printStr("minus:"); break; case Token.DIV: printStr("div:"); break; case Token.MOD: printStr("mod:"); break; case Token.MULT: printStr("mult:"); break; case Token.UNION: printStr("union:"); break; } } } printStr("}"); } else if (o is ASTNodeUnaryOp) { ASTNodeUnaryOp x = (ASTNodeUnaryOp)o; printStr("opexpr {"); switch (x.op) { case Token.UMINUS: printStr("num-neg:"); break; } print(x.expr); printStr("}"); } else if (o is ASTNodeLocPath) { ASTNodeLocPath x = (ASTNodeLocPath)o; printStr("pathexpr {"); int offset = x.Absolute?1:0; for (int i = 0; i < x.clauses.Count + offset; i++) { if (offset == 0 || i > 0) { print(x.clauses[i - offset]); } if (i < x.separators.Count) { switch (Parser.vectInt(x.separators, i)) { case Token.DBL_SLASH: printStr("dbl-slash:"); break; case Token.SLASH: printStr("slash:"); break; } } } printStr("}"); } else if (o is ASTNodePathStep) { ASTNodePathStep x = (ASTNodePathStep)o; printStr("step {axis: " + x.axisType + " node test type: " + x.nodeTestType); if (x.axisType == ASTNodePathStep.AXIS_TYPE_EXPLICIT) { printStr(" axis type: " + x.axisVal); } if (x.nodeTestType == ASTNodePathStep.NODE_TEST_TYPE_QNAME) { printStr(" node test name: " + x.nodeTestQName.ToString()); } if (x.nodeTestType == ASTNodePathStep.NODE_TEST_TYPE_FUNC) { print(x.nodeTestFunc); } printStr("predicates..."); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" for (System.Collections.IEnumerator e = x.predicates.GetEnumerator(); e.MoveNext();) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" print(e.Current); } printStr("}"); } else if (o is ASTNodeFilterExpr) { ASTNodeFilterExpr x = (ASTNodeFilterExpr)o; printStr("filter expr {"); print(x.expr); printStr("predicates..."); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" for (System.Collections.IEnumerator e = x.predicates.GetEnumerator(); e.MoveNext();) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" print(e.Current); } printStr("}"); } indent -= 1; }