Пример #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>
        /// 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);
            }
        }