Esempio n. 1
0
        ParseSearchTerms(
            string searchTermsExpression
            )
        {
            try {
                OslcSearchTermsParser parser  = new OslcSearchTermsParser(searchTermsExpression);
                CommonTree            rawTree = (CommonTree)parser.Result;
                CommonTree            child   = (CommonTree)rawTree.GetChild(0);

                if (child is CommonErrorNode)
                {
                    throw ((CommonErrorNode)child).trappedException;
                }

                IList <ITree> rawList    = rawTree.Children;
                StringList    stringList = new StringList(rawList.Count);

                foreach (CommonTree str in rawList)
                {
                    string rawString = str.Text;

                    stringList.Add(rawString.Substring(1, rawString.Length - 2));
                }

                return(stringList);
            } catch (RecognitionException e) {
                throw new ParseException(e);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Parse a oslc.searchTerms expression
        ///
        /// <p><b>Note</b>: {@link Object#toString()} of result has been overridden to
        /// return input expression.
        /// </summary>
        /// <param name="searchTermsExpression">contents of an oslc.searchTerms HTTP query
        /// parameter</param>
        /// <returns>the parsed search terms clause</returns>
        public static SearchTermsClause ParseSearchTerms(string searchTermsExpression)
        {
            try
            {
                var parser  = new OslcSearchTermsParser(searchTermsExpression);
                var rawTree = (CommonTree)parser.Result;
                var child   = (CommonTree)rawTree.GetChild(0);

                if (child is CommonErrorNode node)
                {
                    return(new StringList(isError: true, errorReason: node.trappedException.ToString()));
                }

                var rawList    = rawTree.Children;
                var stringList = new StringList(rawList.Count);

                foreach (var iTree in rawList)
                {
                    var str       = (CommonTree)iTree;
                    var rawString = str.Text;

                    stringList.Add(rawString.Substring(1, rawString.Length - 2));
                }

                return(stringList);
            }
            catch (RecognitionException e)
            {
                return(new StringList(isError: true, errorReason: e.ToString()));
            }
        }