/// <summary> /// Attempts to parse a filter string from the command line to a RootFilter /// </summary> /// <remarks> /// Filter string is of the format: /// [DependencyOperator][Filter] /// /// where [DependencyOperator] is implicitly all dependencies or "+" for all dependencies and dependents /// where [Filter] is a filter of form [filter type]='[filter value]' or [negation]([Filter]) or [negation]([Filter][operator][Filter]) /// where [negation] is either "~" or empty /// where [operator] is "and" or "or" /// </remarks> /// <param name="rootFilter">Filter that was parsed</param> /// <param name="error">Error from parsing filter string</param> /// <returns>true if parsing was successful</returns> public bool TryParse(out RootFilter rootFilter, out FilterParserError error) { Contract.Ensures(Contract.Result <bool>() ^ Contract.ValueAtReturn <RootFilter>(out rootFilter) == null); Contract.Ensures(Contract.Result <bool>() ^ Contract.ValueAtReturn <FilterParserError>(out error) != null); rootFilter = null; if (string.IsNullOrEmpty(m_expression)) { error = new FilterParserError(0, ErrorMessages.NullEmptyFilter); return(false); } SkipWhitespace(); try { rootFilter = ParseRootFilter(); // Ensure parsing the filter consumed the entire string if (m_position != m_expression.Length) { rootFilter = null; error = new FilterParserError(m_position, ErrorMessages.ExpectedEndOfFilter, StartGroup, EndGroup); return(false); } } catch (FilterParserException ex) { error = ex.Error; return(false); } error = null; return(true); }
/// <summary> /// Creates a FilterParserException from an error /// </summary> public FilterParserException(FilterParserError error) { Error = error; }