当前位置: 首页>>代码示例>>C#>>正文


C# IScanner.Seek方法代码示例

本文整理汇总了C#中IScanner.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# IScanner.Seek方法的具体用法?C# IScanner.Seek怎么用?C# IScanner.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IScanner的用法示例。


在下文中一共展示了IScanner.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryMatch

        public override ParserMatch TryMatch(IScanner scan)
        {
            // save scanner state
            int offset = scan.Offset;

            // apply the first parser
            var m = LeftParser.Parse(scan);

            // rewind
            scan.Seek(offset);

            // apply the second parser
            var m2 = RightParser.Parse(scan);

            // pick the longest result
            if (m.Success || m2.Success)
            {
                if (m2.Length >= m.Length)
                {
                    scan.Seek(m2.Offset + m2.Length);
                    return m2;
                }
                scan.Seek(m.Offset + m.Length);
                return m;
            }

            // rewind to point of failure
            scan.Seek(offset);
            return scan.NoMatch;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:30,代码来源:Union.cs

示例2: TryMatch

        public override ParserMatch TryMatch(IScanner scan)
        {
            int offset = scan.Offset;

            var m = LeftParser.Parse(scan);

            int goodOffset = scan.Offset;

            if (!m.Success)
            {
                scan.Seek(offset);
                return scan.NoMatch;
            }

            // doing difference
            scan.Seek(offset);
            var m2 = RightParser.Parse(scan);
            if (m2.Success)
            {
                // fail: must match left but NOT right
                scan.Seek(offset);
                return scan.NoMatch;
            }

            // Good match
            scan.Seek(goodOffset);
            return m;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:28,代码来源:Difference.cs

示例3: ParseMain

				/// <summary>
				/// Inner parse method
				/// </summary>
				/// <param name="scanner">scanner</param>
				/// <returns>the match</returns>
				protected override ParserMatch ParseMain(IScanner scanner)
		{
			// save scanner state
			long offset = scanner.Offset;

			// apply the first parser
			ParserMatch m = FirstParser.Parse(scanner);
			// if m1 successful, do m2
			if (m.Success)
			{
				return m;
			}

			// not found try the next
			scanner.Seek(offset);

			// apply the second parser
			m = SecondParser.Parse(scanner);
			if (m.Success)
			{
				return m;
			}

			scanner.Seek(offset);
			return ParserMatch.CreateFailureMatch(scanner);
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:31,代码来源:AlternativeParser.cs

示例4: TryMatch

        public override ParserMatch TryMatch(IScanner scan)
        {
            int offset = scan.Offset;

            var left = LeftParser.Parse(scan);

            if (left.Success)
            {
                var right = RightParser.Parse(scan);
                if (right.Success)
                {
                    return ParserMatch.Concat(this, left, right);
                }
            }
            else
            {
                scan.Seek(offset);
                left = RightParser.Parse(scan);
                if (left.Success)
                {
                    var right = LeftParser.Parse(scan);
                    if (right.Success)
                    {
                        return ParserMatch.Concat(this, left, right);
                    }
                }
            }

            scan.Seek(offset);
            return scan.NoMatch;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:31,代码来源:Intersection.cs

示例5: TryMatch

        public override ParserMatch TryMatch(IScanner scan)
        {
            int offset = scan.Offset;

            var m = new ParserMatch(this, scan, offset, -1);

            while (!scan.EndOfInput)
            {
                offset = scan.Offset;

                var a = LeftParser.Parse(scan);

                if (!a.Success)
                {
                    scan.Seek(offset);
                    return m;
                }

                var b = RightParser.Parse(scan);

                if (!b.Success)
                {
                    scan.Seek(offset);
                    return m;
                }

                m.AddSubmatch(a);
                m.AddSubmatch(b);
            }

            return m;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:32,代码来源:TerminatedList.cs

示例6: ParseMain

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

			ParserMatch m = FirstParser.Parse(scanner);
			if (!m.Success)
			{
				scanner.Seek(offset);
				return m;
			}

			while (!scanner.AtEnd)
			{
				offset = scanner.Offset;

				ParserMatch b = SecondParser.Parse(scanner);
				if (!b.Success)
				{
					scanner.Seek(offset);
					return m;
				}
				ParserMatch a = FirstParser.Parse(scanner);
				if (!a.Success)
				{
					scanner.Seek(offset);
					return m;
				}

				m.Concat(b);
				m.Concat(a);
			}

			return m;
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:39,代码来源:ListParser.cs

示例7: TryMatch

        public ParserMatch TryMatch(IScanner scan)
        {
            int offset = scan.Offset;

            string compare = scan.Substring(offset, test.Length);

            if (compare == test)
            {
                scan.Seek(offset + test.Length);
                return scan.CreateMatch(this, offset, test.Length);
            }

            scan.Seek(offset);
            return scan.NoMatch;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:15,代码来源:LiteralString.cs

示例8: TryMatch

        public ParserMatch TryMatch(IScanner scan)
        {
            int offset = scan.Offset;
            int len = 0;

            if (!scan.EndOfInput && scan.Peek() == '\r') // CR
            {
                scan.Read();
                len++;
            }

            if (!scan.EndOfInput && scan.Peek() == '\n') // LF
            {
                scan.Read();
                len++;
            }

            if (len > 0)
            {
                return scan.CreateMatch(this, offset, len);
            }

            scan.Seek(offset);
            return scan.NoMatch;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:25,代码来源:EndOfLine.cs

示例9: ParseMain

		/// <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);
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:30,代码来源:EolParser.cs

示例10: ParseMain

				/// <summary>
				/// Inner parse method
				/// </summary>
				/// <param name="scanner">scanner</param>
				/// <returns>the match</returns>
				protected override ParserMatch ParseMain(IScanner scanner)
		{
			// save scanner state
			long offset = scanner.Offset;

			// apply the first parser
			ParserMatch m = FirstParser.Parse(scanner);
			// if m1 successful, do m2
			if (m.Success)
			{
				ParserMatch m2 = SecondParser.Parse(scanner);
				if (m2.Success)
				{
					m.Concat(m2);
				}
				else
				{
					m = ParserMatch.CreateFailureMatch(scanner, offset);
				}
			}

			// restoring parser failed, rewind scanner
			if (!m.Success)
			{
				scanner.Seek(offset);
			}

			return m;
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:34,代码来源:SequenceParser.cs

示例11: TryMatch

        public override ParserMatch TryMatch(IScanner scan)
        {
            // save scanner state
            int offset = scan.Offset;

            // apply the first parser
            var m1 = LeftParser.Parse(scan);
            int m1off = scan.Offset;

            // Go back and try the second
            scan.Seek(offset);

            // apply the second parser
            var m2 = RightParser.Parse(scan);
            int m2off = scan.Offset;

            if (m2.Success && m1.Success)
            {
                // FAIL! they are not exclusive
                scan.Seek(offset);
                return scan.NoMatch;
            }

            // now return whichever one suceeded
            if (m1.Success)
            {
                scan.Seek(m1off);
                return m1;
            }
            if (m2.Success)
            {
                scan.Seek(m2off);
                return m2;
            }

            // neither were matched!
            scan.Seek(offset);
            return scan.NoMatch;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:39,代码来源:Exclusive.cs

示例12: TryMatch

        /// <summary>
        /// Test the regular expression.
        /// </summary>
        /// <remarks>This is done on the entire input.
        /// This might cause problems with file-stream parsing.</remarks>
        public ParserMatch TryMatch(IScanner scan)
        {
            int offset = scan.Offset;

            string remains = scan.RemainingData();
            var result = test.Match(remains);

            if (result.Success && result.Index == 0)
            {
                scan.Seek(offset + result.Length);
                return scan.CreateMatch(this, offset, result.Length);
            }

            return scan.NoMatch;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:20,代码来源:RegularExpression.cs

示例13: ParseMain

		/// <summary>
		/// Inner parse method
		/// </summary>
		/// <param name="scanner">scanner</param>
		/// <returns>the match</returns>
		protected override ParserMatch ParseMain(IScanner scanner)
		{
			long offset = scanner.Offset;
			ParserMatch m = FirstParser.Parse(scanner);
			if (m.Success)
			{
				StringScanner firstMatch = new StringScanner(m.Value);
				ParserMatch m2 = SecondParser.Parse(firstMatch);
				if (m2.Success)
				{
					return m;
				}
			}

			scanner.Seek(offset);
			return ParserMatch.CreateFailureMatch(scanner);
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:22,代码来源:IntersectionParser.cs

示例14: ParseMain

		/// <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;
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:28,代码来源:StringParser.cs

示例15: TryMatch

        public override ParserMatch TryMatch(IScanner scan)
        {
            // save scanner state
            int offset = scan.Offset;
            var m = scan.NoMatch;

            // apply the first parser
            var left = LeftParser.Parse(scan);

            // if left successful, do right
            if (left.Success)
            {
                var right = RightParser.Parse(scan);

                m = right.Success ? ParserMatch.Concat(this, left, right) : scan.NoMatch;
            }

            // restoring parser failed, rewind scanner
            if (!m.Success)
                scan.Seek(offset);

            return m;
        }
开发者ID:i-e-b,项目名称:Phantom2,代码行数:23,代码来源:Sequence.cs


注:本文中的IScanner.Seek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。