Example #1
0
        /// <summary>
        /// Inner parse method
        /// </summary>
        /// <param name="scanner">scanner</param>
        /// <returns>the match</returns>
        protected override ParserMatch ParseMain(IScanner scanner)
        {
            long offset = scanner.Offset;
            int  len    = 0;

            if (scanner.Peek() == '\r')                // CR
            {
                scanner.Read();
                ++len;
            }

            if (scanner.Peek() == '\n')                // LF
            {
                scanner.Read();
                ++len;
            }

            if (len > 0)
            {
                ParserMatch m = ParserMatch.CreateSuccessfulMatch(scanner, offset, len);
                return(m);
            }
            scanner.Seek(offset);
            return(ParserMatch.CreateFailureMatch(scanner));
        }
Example #2
0
        public void Concat()
        {
            IScanner scanner = Provider.NewScanner;

            scanner.Read();

            long startOffset1 = scanner.Offset;

            scanner.Read();
            long endOffset1 = scanner.Offset;

            ParserMatch match1 = ParserMatch.CreateSuccessfulMatch(scanner, startOffset1, endOffset1);

            long startOffset2 = scanner.Offset;

            scanner.Read();
            scanner.Read();
            long endOffset2 = scanner.Offset;

            ParserMatch match2 = ParserMatch.CreateSuccessfulMatch(scanner, startOffset2, endOffset2);

            match1.Concat(match2);

            Assert.AreEqual(startOffset1, match1.Offset);
            Assert.AreEqual(endOffset2 - startOffset1, match1.Length);
            Assert.IsFalse(match1.Empty);
        }
Example #3
0
        public void Match()
        {
            IScanner    scanner = Provider.NewScanner;
            ParserMatch m       = ParserMatch.CreateSuccessfulMatch(scanner, scanner.Offset, 2);

            Assert.IsTrue(m.Success);
            Assert.IsFalse(m.Empty);
            Assert.AreEqual(2, m.Length);

            Assert.AreEqual(Provider.Text.Substring((int)scanner.Offset, 2), m.Value);
        }
Example #4
0
        public void Concat_MatchOntoEmpty_Match()
        {
            IScanner scanner = Provider.NewScanner;

            scanner.Read();

            ParserMatch emptyMatch = ParserMatch.CreateSuccessfulEmptyMatch(scanner);

            long startOffset = scanner.Offset;

            scanner.Read();
            long        endOffset = scanner.Offset;
            ParserMatch match     = ParserMatch.CreateSuccessfulMatch(scanner, startOffset, endOffset);

            emptyMatch.Concat(match);

            Assert.AreEqual(startOffset, emptyMatch.Offset);
            Assert.AreEqual(endOffset - startOffset, emptyMatch.Length);
            Assert.IsFalse(emptyMatch.Empty);
        }
Example #5
0
        /// <summary>
        /// Inner parse method
        /// </summary>
        /// <param name="scanner">scanner</param>
        /// <returns>the match</returns>

        protected override ParserMatch ParseMain(IScanner scanner)
        {
            long offset = scanner.Offset;

            bool isAccepted = Accepts(scanner.Peek());

            if (isAccepted && Negate || !isAccepted && !Negate)
            {
                return(ParserMatch.CreateFailureMatch(scanner));
            }

            // match character
            scanner.Peek();
            // if we arrive at this point, we have a match
            ParserMatch m = ParserMatch.CreateSuccessfulMatch(scanner, offset, 1);

            // updating offset
            scanner.Read();

            // return match
            return(m);
        }
Example #6
0
        /// <summary>
        /// Inner parse method
        /// </summary>
        /// <param name="scanner">scanner</param>
        /// <returns>the match</returns>
        protected override ParserMatch ParseMain(IScanner scanner)
        {
            long offset = scanner.Offset;

            foreach (Char c in MatchedString)
            {
                // if input consummed return null
                if (scanner.AtEnd || c != scanner.Peek())
                {
                    ParserMatch noMatch = ParserMatch.CreateFailureMatch(scanner, offset);
                    scanner.Seek(offset);
                    return(noMatch);
                }

                // read next characted
                scanner.Read();
            }

            // if we arrive at this point, we have a match
            ParserMatch m = ParserMatch.CreateSuccessfulMatch(scanner, offset, MatchedString.Length);

            // return match
            return(m);
        }