/// <summary> /// Accepts the source context (by <see cref="IParsingContextStream.Accept"/>) and returns accepted fragment (<see cref="IParsingContextStream.GetAcceptedFragmentOrEmpty"/>). /// <seealso cref="IParsingContextStream.Accept"/> /// <seealso cref="IParsingContextStream.GetAcceptedFragmentOrEmpty"/> /// <seealso cref="GetAcceptedFragment"/> /// <seealso cref="TryGetAcceptedFragment"/> /// </summary> /// <param name="source">The source.</param> /// <returns>The accepted fragment.</returns> public static ISourceCodeFragment AcceptAndGetFragment(this IParsingContextStream source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } source.Accept(); return(source.GetAcceptedFragmentOrEmpty()); }
public static ISourceCodeFragment GetAcceptedFragment(this IParsingContextStream source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source.AcceptedPosition < 0) { throw new ArgumentException("Unable to get accepted fragment: the parsing context is not accepted.", nameof(source)); } return(source.GetAcceptedFragmentOrEmpty()); }
public static bool TryGetAcceptedFragment(this IParsingContextStream source, out ISourceCodeFragment acceptedFragment) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source.AcceptedPosition < 0) { acceptedFragment = null; return(false); } acceptedFragment = source.GetAcceptedFragmentOrEmpty(); return(true); }