Example #1
0
        /// <summary>
        /// Parse a oslc.where expression
        /// </summary>
        /// <param name="whereExpression"contents of an oslc.where HTTP query
        /// parameter></param>
        /// <param name="prefixMap">map between XML namespace prefixes and
        /// associated URLs</param>
        /// <returns>the parsed where clause</returns>
        public static WhereClause ParseWhere(string whereExpression, IReadOnlyDictionary <string, string> prefixMap)
        {
            try
            {
                var parser  = new OslcWhereParser(whereExpression);
                var rawTree = (CommonTree)parser.Result;
                var child   = rawTree.GetChild(0);

                if (child is CommonTree commonTree)
                {
                    var errorNode = commonTree.Children
                                    ?.SelectMany(item => (item as CommonTree)?.Children ?? new List <ITree>())
                                    .Where(item => item is CommonErrorNode);
                    if (errorNode != null && errorNode.Any())
                    {
                        return(new WhereClauseImpl(isError: true, errorReason: errorNode.ToString()));
                    }
                }

                if (child is CommonErrorNode)
                {
                    return(new WhereClauseImpl(isError: true, errorReason: child?.ToString()));
                }

                return(new WhereClauseImpl(rawTree, prefixMap));
            }
            catch (RecognitionException e)
            {
                return(new WhereClauseImpl(isError: true, errorReason: e.ToString()));
            }
        }
Example #2
0
        ParseWhere(
            string whereExpression,
            IDictionary <string, string> prefixMap
            )
        {
            try
            {
                OslcWhereParser parser  = new OslcWhereParser(whereExpression);
                CommonTree      rawTree = (CommonTree)parser.Result;
                ITree           child   = rawTree.GetChild(0);

                if (child is CommonErrorNode)
                {
                    throw new ParseException(child.ToString());
                }

                return((WhereClause) new WhereClauseImpl(rawTree, prefixMap));
            } catch (RecognitionException e) {
                throw new ParseException(e);
            }
        }