示例#1
0
        /// <summary>
        /// Returns a value indicating whether the next character matches the lexical rule.
        /// </summary>
        /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
        /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
        public override bool Match(BranchedReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException();
            }
            BranchedReader branch1 = reader.NewBranch();
            BranchedReader branch2 = reader.NewBranch();
            bool           check1  = First.Match(branch1);
            bool           check2  = Second.Match(branch2);

            if (!check1 && !check2)
            {
                branch1.Dispose();
                branch2.Dispose();
                return(false);
            }
            if (check1 && check2)
            {
                reader.Merge(branch1.Position > branch2.Position ? branch1 : branch2);
            }
            else if (check1)
            {
                reader.Merge(branch1);
            }
            else if (check2)
            {
                reader.Merge(branch2);
            }
            branch1.Dispose();
            branch2.Dispose();
            return(true);
        }
示例#2
0
 /// <summary>
 /// Merges the reader to the state of another specified branch, and returns a string that contains the characters between the positions of the current reader and <paramref name="branch"/>.
 /// </summary>
 /// <param name="branch">The specified branch.</param>
 /// <returns>A string that contains the characters between the positions of the current reader and <paramref name="branch"/> if the current reader is ahead of <paramref name="branch"/>; A empty string if the current reader and <paramref name="branch"/> are in the same position; <see langword="null"/> if the current reader is behind <paramref name="branch"/>.</returns>
 /// <exception cref="ObjectDisposedException">The current reader is closed.</exception>
 /// <exception cref="InvalidOperationException">The reader has a different root with the specified branch.</exception>
 /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception>
 public string Merge(BranchedReader branch)
 {
     if (branch == null)
     {
         throw new ArgumentNullException();
     }
     if (HasSameRoot(branch))
     {
         if (Position <= branch.Position)
         {
             var sb = new StringBuilder();
             while (Position < branch.Position)
             {
                 sb.Append(Read());
             }
             return(sb.ToString());
         }
         else
         {
             _buffer  = new Queue <char>(branch._buffer);
             Line     = branch.Line;
             Span     = branch.Span;
             Position = branch.Position;
             return(null);
         }
     }
     else
     {
         throw new InvalidOperationException(ExceptionResource.DifferentRoot);
     }
 }
示例#3
0
 /// <summary>
 /// Returns a value indicating whether the next character matches the lexical rule.
 /// </summary>
 /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
 /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
 public override bool Match(BranchedReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException();
     }
     return(First.Match(reader) && Second.Match(reader));
 }
示例#4
0
 /// <summary>
 /// Returns a value indicating whether the next character matches the lexical rule.
 /// </summary>
 /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
 /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
 public override bool Match(BranchedReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException();
     }
     return(true);
 }
示例#5
0
 private BranchedReader(BranchedReader parent)
 {
     _reader   = parent._reader;
     _branches = parent._branches;
     _branches.Add(this);
     _buffer  = new Queue <char>(parent._buffer);
     Line     = parent.Line;
     Span     = parent.Span;
     Position = parent.Position;
 }
示例#6
0
 /// <summary>
 /// Returns a value indicating whether the reader has the same root reader as another specified branch.
 /// </summary>
 /// <param name="branch">The specified branch.</param>
 /// <returns><see langword="true"/> if the lexer has the same root reader as <paramref name="branch"/>; otherwise <see langword="false"/>.</returns>
 /// <exception cref="ObjectDisposedException">The current reader is closed.</exception>
 /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception>
 public bool HasSameRoot(BranchedReader branch)
 {
     if (branch == null)
     {
         throw new ArgumentNullException();
     }
     if (!_branches.Contains(this))
     {
         throw new ObjectDisposedException(ToString());
     }
     else if (!_branches.Contains(branch))
     {
         throw new ObjectDisposedException(branch.ToString());
     }
     return(this._reader.Equals(branch._reader));
 }
示例#7
0
        /// <summary>
        /// Returns a value indicating whether the next character matches the lexical rule.
        /// </summary>
        /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
        /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
        public override bool Match(BranchedReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException();
            }
            char c = reader.Read();

            if (Predicate(c))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        /// <summary>
        /// Returns a value indicating whether the next character matches the lexical rule.
        /// </summary>
        /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
        /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
        public override bool Match(BranchedReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException();
            }
            BranchedReader branch0, branch1;

            branch0 = reader.NewBranch();
            bool check = true;
            int  count = 0;

            while (true)
            {
                branch1 = branch0.NewBranch();
                check   = Content.Match(branch1);
                if (check)
                {
                    branch0.Dispose();
                    branch0 = branch1;
                    count++;
                }
                else
                {
                    break;
                }
                if (Max > 0 && count == Max)
                {
                    break;
                }
            }
            branch1.Dispose();
            if (count < Min)
            {
                branch0.Dispose();
                return(false);
            }
            else
            {
                reader.Merge(branch0);
                branch0.Dispose();
                return(true);
            }
        }
示例#9
0
        /// <summary>
        /// Returns a value indicating whether the next character matches the lexical rule.
        /// </summary>
        /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
        /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
        public override bool Match(BranchedReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException();
            }
            char c = reader.Read();

            if (c == '\0')
            {
                return(false);
            }
            if (!(From <= c && c <= To))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#10
0
        /// <summary>
        /// Returns a value indicating whether the next character matches the lexical rule.
        /// </summary>
        /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
        /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
        public override bool Match(BranchedReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException();
            }
            char c = reader.Read();

            if (c == '\0')
            {
                return(false);
            }
            if (!CharSet.Contains(c))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#11
0
 /// <summary>
 /// Returns a value indicating whether the next character matches the lexical rule.
 /// </summary>
 /// <param name="reader">The <see cref="BranchedReader"/> that provides the input character.</param>
 /// <returns><see langword="true"/> if the next character matches the lexical rule; otherwise <see langword="false"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="reader"/> is <see langword="null"/>.</exception>
 public abstract bool Match(BranchedReader reader);