Exemplo n.º 1
0
        /// <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());
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }