public static string[] tokenize(string expression) { String[] exps = new string[] { "\\$?(?:(?![0-9-])[\\w-]+:)?(?![0-9-])[\\w-]+", "\\d+\\.\\d+", "\\.\\d+", "\\d+", "\\/\\/", @"\/", "\\.\\.", "\\.", "\\s+", "::", ",", "@", "-", "=", "!=", "<=", "<", ">=", ">", "\\|", "\\+", "\\*", "\\(", "\\)", "\\[", "\\]", "\"[^\"]*\"", "'[^']*'" }; string ex = string.Join("|", exps); List <String> pString = new List <string>(); Match match = Regex.Match(expression, ex, RegexOptions.IgnoreCase); while (match.Success) { if (!XPathLexer.RegexTest(match.Value, @"^\s+$")) { pString.Add(match.Value); } match = match.NextMatch(); } if (pString.Count == 0) { throw new Exception("Invalid XPath expression"); } return(pString.ToArray()); }
public XPathAnalyzer(string expression) { this.lexer = new XPathLexer(expression); }
public XPathLexer(string expression) { this.tokens = XPathLexer.tokenize(expression); this.index = 0; }