internal IXQuerySelector GetNextSelector(XQueryParserContext context)
        {
            Match match = null;
            XQuerySelectorCreator xqsc = null;
            int matchLength            = 0;
            var str = context.Query.Substring(context.Index);

            XQuerySelectorCreator[] selectors;
            lock (_selectors)
                selectors = _selectors.ToArray();
            foreach (var qs in selectors)
            {
                var m = qs.MatchNext.Match(str);
                if (m.Success && m.Length > matchLength)
                {
                    matchLength = m.Length;
                    xqsc        = qs;
                    match       = m;
                }
            }
            if (xqsc == null)
            {
                return(null);
            }
            var sel = xqsc.Create(context, match);

            context.Index += match.Length;
            return(sel);
        }
		internal IXQuerySelector GetNextSelector(XQueryParserContext context)
		{
			Match match = null;
			XQuerySelectorCreator xqsc = null;
			int matchLength = 0;
			var str = context.Query.Substring(context.Index);
			XQuerySelectorCreator[] selectors;
			lock(_selectors)
				selectors = _selectors.ToArray();
			foreach(var qs in selectors)
			{
				var m = qs.MatchNext.Match(str);
				if(m.Success && m.Length > matchLength)
				{
					matchLength = m.Length;
					xqsc = qs;
					match = m;
				}
			}
			if(xqsc == null)
				return null;
			var sel = xqsc.Create(context, match);
			context.Index += match.Length;
			return sel;
		}
Exemple #3
0
		internal static IXQuerySelector[] Parse(XQueryParserContext context)
		{
			var list = new List<IXQuerySelector>();
			while(!context.EndOfQuery)
			{
				var selector = context.MatchNextSelector();
				if(selector == null)
					throw new XQueryException("Unexpected character at position " + context.Index + " in query: " + context.Query.Substring(context.Index), context.Query, context.Index, 1);
				list.Add(selector);
			}
			return list.ToArray();
		}
Exemple #4
0
		public static XElement[] Execute(string query, XDocument doc, params XElement[] baseElements)
		{
			var parserContext = new XQueryParserContext(new SelectorParserCatalog(), query);
			var selectors = Parse(parserContext);
			var resultsContext = new XQueryResultsContext(doc);
			if(baseElements.Length > 0)
				resultsContext.ResultSetInternal = baseElements;
			if(selectors.Length > 0)
				if(selectors.Last().IsTransposeSelector || selectors.First().IsTransposeSelector)
					throw new XQueryException("A query may not start or end with a transposal selector (e.g. >)", query, 0, query.Length);
			foreach(var selector in selectors)
				selector.Execute(resultsContext);
			return resultsContext.ResultSet;
		}
Exemple #5
0
        internal static IXQuerySelector[] Parse(XQueryParserContext context)
        {
            var list = new List <IXQuerySelector>();

            while (!context.EndOfQuery)
            {
                var selector = context.MatchNextSelector();
                if (selector == null)
                {
                    throw new XQueryException("Unexpected character at position " + context.Index + " in query: " + context.Query.Substring(context.Index), context.Query, context.Index, 1);
                }
                list.Add(selector);
            }
            return(list.ToArray());
        }
Exemple #6
0
        public static XElement[] Execute(string query, XDocument doc, params XElement[] baseElements)
        {
            var parserContext  = new XQueryParserContext(new SelectorParserCatalog(), query);
            var selectors      = Parse(parserContext);
            var resultsContext = new XQueryResultsContext(doc);

            if (baseElements.Length > 0)
            {
                resultsContext.ResultSetInternal = baseElements;
            }
            if (selectors.Length > 0)
            {
                if (selectors.Last().IsTransposeSelector || selectors.First().IsTransposeSelector)
                {
                    throw new XQueryException("A query may not start or end with a transposal selector (e.g. >)", query, 0, query.Length);
                }
            }
            foreach (var selector in selectors)
            {
                selector.Execute(resultsContext);
            }
            return(resultsContext.ResultSet);
        }
 public abstract IXQuerySelector Create(XQueryParserContext context, Match match);
 public abstract IXQuerySelector Create(XQueryParserContext context, Match match);