public static object parse(Expr rootParser, XPathLexer lexer) { Dictionary <string, object> funCall = new Dictionary <string, object>(); funCall.Add("type", XPathAnalyzer.ExprType.FUNCTION_CALL); funCall.Add("name", lexer.next()); lexer.next(); if (lexer.peak().Equals(")")) { lexer.next(); } else { funCall.Add("args", new List <object>()); while (!lexer.peak().Equals(")")) { ((List <object>)funCall["args"]).Add(rootParser.parse(lexer)); if (lexer.peak().Equals(",")) { lexer.next(); } } lexer.next(); } return(funCall); }
public static object parse(Expr rootParser, XPathLexer lexer) { string token = lexer.peak(); char ch = token[0]; if (ch == '(') { lexer.next(); var expr = rootParser.parse(lexer); if (!lexer.next().Equals(")")) { throw new Exception("Error: Unclosed parentheses"); } return expr; } if (ch == '"' || ch == '\'') { lexer.next(); Dictionary<string, object> r = new Dictionary<string, object>(); r.Add("type", XPathAnalyzer.ExprType.LITERAL); r.Add("string", token.Substring(1, (token.Length - 1) - 1));//token.slice(1, -1) return r; } if (ch == '$') { throw new Exception("Error: Variable reference are not implemented"); } if (XPathLexer.RegexTest(token, @"^\d+$") || XPathLexer.RegexTest(token, @"^(\d+)?\.\d+$")) { lexer.next(); Dictionary<string, object> r = new Dictionary<string, object>(); r.Add("type", XPathAnalyzer.ExprType.NUMBER); r.Add("number", float.Parse(token, CultureInfo.InvariantCulture));//token.slice(1, -1) return r; } if (lexer.peak(1) == "(" && !NodeTypeValidator.isValid(lexer.peak())) { return FunctionCall.parse(rootParser, lexer); } return null; //throw new Exception("Error: Unhandle Expresion!"); }
public static object parse(Expr rootParser, XPathLexer lexer) { string token = lexer.peak(); char ch = token[0]; if (ch == '(') { lexer.next(); var expr = rootParser.parse(lexer); if (!lexer.next().Equals(")")) { throw new Exception("Error: Unclosed parentheses"); } return(expr); } if (ch == '"' || ch == '\'') { lexer.next(); Dictionary <string, object> r = new Dictionary <string, object>(); r.Add("type", XPathAnalyzer.ExprType.LITERAL); r.Add("string", token.Substring(1, (token.Length - 1) - 1));//token.slice(1, -1) return(r); } if (ch == '$') { throw new Exception("Error: Variable reference are not implemented"); } if (XPathLexer.RegexTest(token, @"^\d+$") || XPathLexer.RegexTest(token, @"^(\d+)?\.\d+$")) { lexer.next(); Dictionary <string, object> r = new Dictionary <string, object>(); r.Add("type", XPathAnalyzer.ExprType.NUMBER); r.Add("number", float.Parse(token, CultureInfo.InvariantCulture));//token.slice(1, -1) return(r); } if (lexer.peak(1) == "(" && !NodeTypeValidator.isValid(lexer.peak())) { return(FunctionCall.parse(rootParser, lexer)); } return(null); //throw new Exception("Error: Unhandle Expresion!"); }
public static object parse(Expr rootParser, XPathLexer lexer) { lexer.next(); var predicate = rootParser.parse(lexer); if (!lexer.next().Equals("]")) { throw new Exception("Error: Unclosed brackets"); } return(predicate); }
public static object parse(Expr rootParser, XPathLexer lexer) { lexer.next(); var predicate = rootParser.parse(lexer); if (!lexer.next().Equals("]")) { throw new Exception("Error: Unclosed brackets"); } return predicate; }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = UnaryExpr.parse(rootParser, lexer); Dictionary <string, string> multiplicativeTypes = new Dictionary <string, string>(); multiplicativeTypes.Add("*", XPathAnalyzer.ExprType.MULTIPLICATIVE); multiplicativeTypes.Add("div", XPathAnalyzer.ExprType.DIVISIONAL); multiplicativeTypes.Add("mod", XPathAnalyzer.ExprType.MODULUS); if (!string.IsNullOrEmpty(lexer.peak()) && multiplicativeTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary <string, object> list = new Dictionary <string, object>(); list.Add("type", multiplicativeTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return(list); } else { return(lhs); } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = MultiplicativeExpr.parse(rootParser, lexer); Dictionary <string, string> additiveTypes = new Dictionary <string, string>(); additiveTypes.Add("+", XPathAnalyzer.ExprType.ADDITIVE); additiveTypes.Add("-", XPathAnalyzer.ExprType.SUBTRACTIVE); if (!string.IsNullOrEmpty(lexer.peak()) && additiveTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary <string, object> list = new Dictionary <string, object>(); list.Add("type", additiveTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return(list); } else { return(lhs); } }
public static object parse(Expr rootParser, XPathLexer lexer) { Dictionary <string, object> relativeLocation = new Dictionary <string, object>(); relativeLocation.Add("type", XPathAnalyzer.ExprType.RELATIVE_LOCATION_PATH); relativeLocation.Add("steps", new List <Dictionary <string, object> >()); ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(Step.parse(rootParser, lexer)); while (!lexer.empty() && (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak()[0] == '/')) { if (lexer.next().Equals("/")) { ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(Step.parse(rootParser, lexer)); } else { Dictionary <string, object> itm = new Dictionary <string, object>(); itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF); Dictionary <string, object> test = new Dictionary <string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); itm.Add("test", test); ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(itm); ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(Step.parse(rootParser, lexer)); } } return(relativeLocation); }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = RelationalExpr.parse(rootParser, lexer); Dictionary<string, string> equalityTypes = new Dictionary<string, string>(); equalityTypes.Add("=", XPathAnalyzer.ExprType.EQUALITY); equalityTypes.Add("!=", XPathAnalyzer.ExprType.INEQUALITY); if (!string.IsNullOrEmpty(lexer.peak()) && equalityTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary<string, object> list = new Dictionary<string, object>(); list.Add("type", equalityTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return list; } else { return lhs; } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = AdditiveExpr.parse(rootParser, lexer); Dictionary<string, string> relationalTypes = new Dictionary<string, string>(); relationalTypes.Add("<", XPathAnalyzer.ExprType.LESS_THAN); relationalTypes.Add(">", XPathAnalyzer.ExprType.GREATER_THAN); relationalTypes.Add("<=", XPathAnalyzer.ExprType.LESS_THAN_OR_EQUAL); relationalTypes.Add(">=", XPathAnalyzer.ExprType.GREATER_THAN_OR_EQUAL); if (!string.IsNullOrEmpty(lexer.peak()) && relationalTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary<string, object> list = new Dictionary<string, object>(); list.Add("type", relationalTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return list; } else { return lhs; } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = RelationalExpr.parse(rootParser, lexer); Dictionary <string, string> equalityTypes = new Dictionary <string, string>(); equalityTypes.Add("=", XPathAnalyzer.ExprType.EQUALITY); equalityTypes.Add("!=", XPathAnalyzer.ExprType.INEQUALITY); if (!string.IsNullOrEmpty(lexer.peak()) && equalityTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary <string, object> list = new Dictionary <string, object>(); list.Add("type", equalityTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return(list); } else { return(lhs); } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = AdditiveExpr.parse(rootParser, lexer); Dictionary <string, string> relationalTypes = new Dictionary <string, string>(); relationalTypes.Add("<", XPathAnalyzer.ExprType.LESS_THAN); relationalTypes.Add(">", XPathAnalyzer.ExprType.GREATER_THAN); relationalTypes.Add("<=", XPathAnalyzer.ExprType.LESS_THAN_OR_EQUAL); relationalTypes.Add(">=", XPathAnalyzer.ExprType.GREATER_THAN_OR_EQUAL); if (!string.IsNullOrEmpty(lexer.peak()) && relationalTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary <string, object> list = new Dictionary <string, object>(); list.Add("type", relationalTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return(list); } else { return(lhs); } }
public static object parse(Expr rootParser, XPathLexer lexer) { Dictionary<string, object> absoluteLocation = new Dictionary<string, object>(); absoluteLocation.Add("type", XPathAnalyzer.ExprType.ABSOLUTE_LOCATION_PATH); while (!lexer.empty() && (lexer.peak()[0] == '/')) { if(!absoluteLocation.ContainsKey("steps")) absoluteLocation.Add("steps", new List<Dictionary<string, object>>()); if (lexer.next().Equals("/")) { var next = lexer.peak(); if (!lexer.empty() && (next.Equals(".") || next.Equals("..") || next.Equals("@") || next.Equals("*") || XPathLexer.RegexTest(next, @"(?![0 - 9])[\w]"))) { ((List<Dictionary<string, object>>)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer)); } }else { Dictionary<string, object> itm = new Dictionary<string, object>(); itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF); Dictionary<string, object> test = new Dictionary<string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); itm.Add("test", test); ((List<Dictionary<string, object>>)absoluteLocation["steps"]).Add(itm); ((List<Dictionary<string, object>>)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer)); } } return absoluteLocation; }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = UnaryExpr.parse(rootParser, lexer); Dictionary<string, string> multiplicativeTypes = new Dictionary<string, string>(); multiplicativeTypes.Add("*", XPathAnalyzer.ExprType.MULTIPLICATIVE); multiplicativeTypes.Add("div", XPathAnalyzer.ExprType.DIVISIONAL); multiplicativeTypes.Add("mod", XPathAnalyzer.ExprType.MODULUS); if (!string.IsNullOrEmpty(lexer.peak()) && multiplicativeTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary<string, object> list = new Dictionary<string, object>(); list.Add("type", multiplicativeTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return list; } else { return lhs; } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = MultiplicativeExpr.parse(rootParser, lexer); Dictionary<string, string> additiveTypes = new Dictionary<string, string>(); additiveTypes.Add("+", XPathAnalyzer.ExprType.ADDITIVE); additiveTypes.Add("-", XPathAnalyzer.ExprType.SUBTRACTIVE); if (!string.IsNullOrEmpty(lexer.peak()) && additiveTypes.ContainsKey(lexer.peak())) { string op = lexer.next(); object rhs = parse(rootParser, lexer); Dictionary<string, object> list = new Dictionary<string, object>(); list.Add("type", additiveTypes[op]); list.Add("lhs", lhs); list.Add("rhs", rhs); return list; } else { return lhs; } }
public static object parse(Expr rootParser, XPathLexer lexer) { if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("-")) { lexer.next(); Dictionary <string, object> list = new Dictionary <string, object>(); list.Add("type", XPathAnalyzer.ExprType.NEGATION); list.Add("lhs", parse(rootParser, lexer)); return(list); } else { return(UnionExpr.parse(rootParser, lexer)); } }
public static object parse(Expr rootParser, XPathLexer lexer) { if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("-")) { lexer.next(); Dictionary<string, object> list = new Dictionary<string, object>(); list.Add("type", XPathAnalyzer.ExprType.NEGATION); list.Add("lhs", parse(rootParser, lexer)); return list; } else { return UnionExpr.parse(rootParser, lexer); } }
public static object parse(Expr rootParser, XPathLexer lexer) { if (FilterExpr.isValidOp(lexer)) { object filter = FilterExpr.parse(rootParser, lexer); if (!lexer.empty() && (lexer.peak()[0] == '/')) { Dictionary <string, object> path = new Dictionary <string, object>(); path.Add("type", XPathAnalyzer.ExprType.PATH); path.Add("filter", filter); path.Add("steps", new List <Dictionary <string, object> >()); while (!lexer.empty() && (lexer.peak()[0] == '/')) { if (lexer.next().Equals("//")) { Dictionary <string, object> itm = new Dictionary <string, object>(); itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF); Dictionary <string, string> test = new Dictionary <string, string>(); test.Add("type", XPathAnalyzer.NodeType.NODE); itm.Add("test", test); ((List <Dictionary <string, object> >)path["steps"]).Add(itm); } ((List <Dictionary <string, object> >)path["steps"]).Add(Step.parse(rootParser, lexer)); } return(path); } else { return(filter); } } else { return(LocationPath.parse(rootParser, lexer)); } }
public static object parse(Expr rootParser, XPathLexer lexer) { if (FilterExpr.isValidOp(lexer)) { object filter = FilterExpr.parse(rootParser, lexer); if (!lexer.empty() && (lexer.peak()[0] == '/')) { Dictionary<string, object> path = new Dictionary<string, object>(); path.Add("type", XPathAnalyzer.ExprType.PATH); path.Add("filter", filter); path.Add("steps", new List<Dictionary<string, object>>()); while (!lexer.empty() && (lexer.peak()[0] == '/')) { if (lexer.next().Equals("//")) { Dictionary<string, object> itm = new Dictionary<string, object>(); itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF); Dictionary<string, string> test = new Dictionary<string, string>(); test.Add("type", XPathAnalyzer.NodeType.NODE); itm.Add("test", test); ((List<Dictionary<string, object>>)path["steps"]).Add(itm); } ((List<Dictionary<string, object>>)path["steps"]).Add(Step.parse(rootParser, lexer)); } return path; } else { return filter; } } else { return LocationPath.parse(rootParser, lexer); } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = AndExpr.parse(rootParser, lexer); if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("or")) { lexer.next(); object rhs = parse(rootParser, lexer); Dictionary<string, object> list = new Dictionary<string, object>(); list.Add("type", XPathAnalyzer.ExprType.OR); list.Add("lhs", lhs); list.Add("rhs", rhs); return list; }else { return lhs; } }
public static object parse(Expr rootParser, XPathLexer lexer) { object lhs = AndExpr.parse(rootParser, lexer); if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("or")) { lexer.next(); object rhs = parse(rootParser, lexer); Dictionary <string, object> list = new Dictionary <string, object>(); list.Add("type", XPathAnalyzer.ExprType.OR); list.Add("lhs", lhs); list.Add("rhs", rhs); return(list); } else { return(lhs); } }
public static object parse(Expr rootParser, XPathLexer lexer) { Dictionary<string, object> ret = new Dictionary<string, object>(); if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("*")) { lexer.next(); ret.Add("name", "*"); return ret; } if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("(")) { if (NodeTypeValidator.isValid(lexer.peak())) { ret.Add("type", lexer.next()); lexer.next(); if (lexer.peak().Equals(")")) { lexer.next(); } else { ret.Add("name", lexer.next()); lexer.next(); } return ret; } else { throw new Exception("Error: Unexpected token " + lexer.peak()); } } ret = new Dictionary<string, object>(); ret.Add("name", lexer.next()); return ret; }
public static object parse(Expr rootParser, XPathLexer lexer) { Dictionary <string, object> ret = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("*")) { lexer.next(); ret.Add("name", "*"); return(ret); } if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("(")) { if (NodeTypeValidator.isValid(lexer.peak())) { ret.Add("type", lexer.next()); lexer.next(); if (lexer.peak().Equals(")")) { lexer.next(); } else { ret.Add("name", lexer.next()); lexer.next(); } return(ret); } else { throw new Exception("Error: Unexpected token " + lexer.peak()); } } ret = new Dictionary <string, object>(); ret.Add("name", lexer.next()); return(ret); }
public static object parse(Expr rootParser, XPathLexer lexer) { Dictionary <string, object> absoluteLocation = new Dictionary <string, object>(); absoluteLocation.Add("type", XPathAnalyzer.ExprType.ABSOLUTE_LOCATION_PATH); while (!lexer.empty() && (lexer.peak()[0] == '/')) { if (!absoluteLocation.ContainsKey("steps")) { absoluteLocation.Add("steps", new List <Dictionary <string, object> >()); } if (lexer.next().Equals("/")) { var next = lexer.peak(); if (!lexer.empty() && (next.Equals(".") || next.Equals("..") || next.Equals("@") || next.Equals("*") || XPathLexer.RegexTest(next, @"(?![0 - 9])[\w]"))) { ((List <Dictionary <string, object> >)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer)); } } else { Dictionary <string, object> itm = new Dictionary <string, object>(); itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF); Dictionary <string, object> test = new Dictionary <string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); itm.Add("test", test); ((List <Dictionary <string, object> >)absoluteLocation["steps"]).Add(itm); ((List <Dictionary <string, object> >)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer)); } } return(absoluteLocation); }
public static Dictionary <string, object> parse(Expr rootParser, XPathLexer lexer) { Dictionary <string, object> step = new Dictionary <string, object>(); step.Add("axis", ""); step.Add("test", new object()); if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("::")) { var axisSpecifier = lexer.next(); lexer.next(); if (AxisSpecifierValidator.isValid(axisSpecifier)) { step["axis"] = axisSpecifier; } else { throw new Exception("Error: Unexpected token " + axisSpecifier); } } else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("@")) { lexer.next(); step["axis"] = XPathAnalyzer.AxisSpecifier.ATTRIBUTE; } else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("..")) { lexer.next(); Dictionary <string, object> test = new Dictionary <string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); step["axis"] = XPathAnalyzer.AxisSpecifier.PARENT; step["test"] = test; return(step); } else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals(".")) { lexer.next(); Dictionary <string, object> test = new Dictionary <string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); step["axis"] = XPathAnalyzer.AxisSpecifier.SELF; step["test"] = test; return(step); } else { step["axis"] = XPathAnalyzer.AxisSpecifier.CHILD; } step["test"] = NodeTest.parse(rootParser, lexer); while (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("[")) { if (!step.ContainsKey("predicates")) { step.Add("predicates", new List <object>()); } ((List <object>)step["predicates"]).Add(Predicate.parse(rootParser, lexer)); } return(step); }
public static Dictionary<string, object> parse(Expr rootParser, XPathLexer lexer) { Dictionary<string, object> step = new Dictionary<string, object>(); step.Add("axis", ""); step.Add("test", new object()); if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("::")) { var axisSpecifier = lexer.next(); lexer.next(); if (AxisSpecifierValidator.isValid(axisSpecifier)) { step["axis"] = axisSpecifier; } else { throw new Exception("Error: Unexpected token " + axisSpecifier); } } else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("@")) { lexer.next(); step["axis"] = XPathAnalyzer.AxisSpecifier.ATTRIBUTE; }else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("..")) { lexer.next(); Dictionary<string, object> test = new Dictionary<string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); step["axis"] = XPathAnalyzer.AxisSpecifier.PARENT; step["test"] = test; return step; } else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals(".")) { lexer.next(); Dictionary<string, object> test = new Dictionary<string, object>(); test.Add("type", XPathAnalyzer.NodeType.NODE); step["axis"] = XPathAnalyzer.AxisSpecifier.SELF; step["test"] = test; return step; } else { step["axis"] = XPathAnalyzer.AxisSpecifier.CHILD; } step["test"] = NodeTest.parse(rootParser, lexer); while (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("[")) { if(!step.ContainsKey("predicates")) { step.Add("predicates", new List<object>()); } ((List<object>)step["predicates"]).Add(Predicate.parse(rootParser, lexer)); } return step; }