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; }