MoveNext() public method

Moves to the next event.
public MoveNext ( ) : bool
return bool
Beispiel #1
0
        static void Main(string[] args)
        {
            using (TextReader input = File.OpenText(args[0]))
            {
                int indent = 0;
                Parser parser = new Parser(input);
                while(parser.MoveNext())
                {
                    if (parser.Current is StreamEnd || parser.Current is DocumentEnd || parser.Current is SequenceEnd || parser.Current is SequenceEnd || parser.Current is MappingEnd)
                    {
                        --indent;
                    }
                    for(int i = 0; i < indent; ++i)
                    {
                        Console.Write("  ");
                    }

                    Console.WriteLine(parser.Current.ToString());

                    if (parser.Current is StreamStart || parser.Current is DocumentStart || parser.Current is SequenceStart || parser.Current is MappingStart)
                    {
                        ++indent;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reads this object's state from a YAML parser.
        /// </summary>
        /// <param name="parser"></param>
        void IYamlSerializable.ReadYaml(Parser parser)
        {
            events.Clear();

            int depth = 0;
            do
            {
                if (!parser.MoveNext())
                {
                    throw new InvalidOperationException("The parser has reached the end before deserialization completed.");
                }

                events.Add(parser.Current);
                depth += parser.Current.NestingIncrease;
            } while (depth > 0);

            Debug.Assert(depth == 0);
        }
		public void Execute(ITextView textView, ITextUndoHistoryRegistry textUndoHistoryRegistry)
		{
			var undoHistory = textUndoHistoryRegistry.RegisterHistory(textView);
			using (var transaction = undoHistory.CreateTransaction("Format Document"))
			{
				var text = textView.TextBuffer.CurrentSnapshot.GetText();

				var formatted = new StringWriter();
				var parser = new Parser(new Scanner(new StringReader(text), skipComments: false));
				var emitter = new Emitter(formatted);

				while (parser.MoveNext())
				{
					emitter.Emit(parser.Current);
				}

				var edit = textView.TextBuffer.CreateEdit();
				edit.Replace(0, text.Length, formatted.ToString());
				edit.Apply();

				transaction.Complete();
			}
		}
Beispiel #4
0
 private void AssertHasNext(Parser parser)
 {
     Assert.True(parser.MoveNext());
 }
Beispiel #5
0
 private void AssertDoesNotHaveNext(Parser parser)
 {
     Assert.False(parser.MoveNext());
 }
Beispiel #6
0
 /// <summary>
 /// Moves to the next event.
 /// </summary>
 private void MoveNext()
 {
     endOfStream = !parser.MoveNext();
 }
Beispiel #7
0
        private void ParseAndEmit(string name)
        {
            string testText = YamlFile(name).ReadToEnd();

            Parser parser = new Parser(new StringReader(testText));
            using(StringWriter output = new StringWriter()) {
                Emitter emitter = new Emitter(output, 2, int.MaxValue, false);
                while(parser.MoveNext()) {
                    //Console.WriteLine(parser.Current.GetType().Name);
                    Console.Error.WriteLine(parser.Current);
                    emitter.Emit(parser.Current);
                }

                string result = output.ToString();

                Console.WriteLine();
                Console.WriteLine("------------------------------");
                Console.WriteLine();
                Console.WriteLine(testText);
                Console.WriteLine();
                Console.WriteLine("------------------------------");
                Console.WriteLine();
                Console.WriteLine(result);
                Console.WriteLine();
                Console.WriteLine("------------------------------");
                Console.WriteLine();

                /*
                Parser resultParser = new Parser(new StringReader(result));
                while(resultParser.MoveNext()) {
                    Console.WriteLine(resultParser.Current.GetType().Name);
                }
                */
                /*

                if(testText != result) {
                    Console.WriteLine();
                    Console.WriteLine("------------------------------");
                    Console.WriteLine();
                    Console.WriteLine("Expected:");
                    Console.WriteLine();
                    Console.WriteLine(testText);
                    Console.WriteLine();
                    Console.WriteLine("------------------------------");
                    Console.WriteLine();
                    Console.WriteLine("Result:");
                    Console.WriteLine();
                    Console.WriteLine(result);
                    Console.WriteLine();
                    Console.WriteLine("------------------------------");
                    Console.WriteLine();
                }

                Assert.AreEqual(testText, result, "The emitter did not generate the correct text.");
                */
            }
        }
Beispiel #8
0
 private void AssertHasNext(Parser parser)
 {
     Assert.IsTrue(parser.MoveNext(), "The parser does not contain more events.");
 }
Beispiel #9
0
 private void AssertDoesNotHaveNext(Parser parser)
 {
     Assert.IsFalse(parser.MoveNext(), "The parser should not contain more events.");
 }