public Emit ( |
||
@event | ||
return | void |
public void Serialize(MapNode node, Emitter emitter) { emitter.Emit(new MappingStart()); SerializeScalarProperties(node, emitter); emitter.Emit(new MappingEnd()); }
/// <summary> /// Writes this object's state to a YAML emitter. /// </summary> /// <param name="emitter"></param> void IYamlSerializable.WriteYaml(Emitter emitter) { foreach (var item in events) { emitter.Emit(item); } }
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(); } }
/// <summary> /// Saves the current node to the specified emitter. /// </summary> /// <param name="emitter">The emitter where the node is to be saved.</param> /// <param name="state">The state.</param> internal void Save(Emitter emitter, EmitterState state) { if (!string.IsNullOrEmpty(Anchor) && !state.EmittedAnchors.Add(Anchor)) { emitter.Emit(new AnchorAlias(Anchor)); } else { Emit(emitter, state); } }
public void UnicodeInScalarsCanBeSingleQuotedWhenOutputEncodingSupportsIt(string text, int codePage) { var document = StreamedDocumentWith( SequenceWith( SingleQuotedScalar(text) ) ); var buffer = new MemoryStream(); var encoding = Encoding.GetEncoding(codePage); using (var writer = new StreamWriter(buffer, encoding)) { var emitter = new Emitter(writer, 2, int.MaxValue, false); foreach (var evt in document) { emitter.Emit(evt); } } var yaml = encoding.GetString(buffer.ToArray()); yaml.Should() .Contain("'" + text + "'"); }
private void EmitDocument(Emitter emitter, IObjectGraphTraversalStrategy traversalStrategy, IObjectGraphVisitor emittingVisitor, object graph, Type type) { emitter.Emit(new StreamStart()); emitter.Emit(new DocumentStart()); traversalStrategy.Traverse(graph, type, emittingVisitor); emitter.Emit(new DocumentEnd(true)); emitter.Emit(new StreamEnd()); }
internal void Save(Emitter emitter) { AssignAnchors(); emitter.Emit(new DocumentStart()); RootNode.Save(emitter, new EmitterState()); emitter.Emit(new DocumentEnd(false)); }
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."); */ } }
/// <summary> /// Saves the current node to the specified emitter. /// </summary> /// <param name="emitter">The emitter where the node is to be saved.</param> /// <param name="state">The state.</param> internal override void Emit(Emitter emitter, EmitterState state) { emitter.Emit(new Scalar(Anchor, Tag, Value, Style, true, false)); }
public void Serialize(MetaModel.MetaModel metaModel, TextWriter writer) { Emitter emitter = new Emitter(writer); emitter.Emit(new StreamStart()); emitter.Emit(new DocumentStart()); emitter.Emit(new MappingStart()); //icons emitter.Emit(new Scalar(Icons)); emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Block)); foreach (var modelIcon in metaModel.IconsList) { emitter.Emit(new MappingStart()); emitter.Emit(new Scalar(Name)); emitter.Emit(new Scalar(modelIcon.Name)); emitter.Emit(new Scalar(Title)); emitter.Emit(new Scalar(modelIcon.Title)); emitter.Emit(new Scalar(Shortcut)); emitter.Emit(new Scalar(modelIcon.Shortcut)); emitter.Emit(new MappingEnd()); } emitter.Emit(new SequenceEnd()); //recent files if (metaModel.RecentFiles.Count > 0) { emitter.Emit(new Scalar(RecentFiles)); emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Block)); foreach (var recentFile in metaModel.RecentFiles) { emitter.Emit(new Scalar(recentFile)); } emitter.Emit(new SequenceEnd()); } //last opened file if (metaModel.LastOpenedFile != null) { emitter.Emit(new Scalar(LastOpenedFile)); emitter.Emit(new Scalar(metaModel.LastOpenedFile)); } //map back color emitter.Emit(new Scalar(MapBackColor)); emitter.Emit(new Scalar(Convert.ToColorHexValue(metaModel.MapEditorBackColor))); //note back color emitter.Emit(new Scalar(NoteBackColor)); emitter.Emit(new Scalar(Convert.ToColorHexValue(metaModel.NoteEditorBackColor))); //node styles if (metaModel.NodeStyles.Any()) { emitter.Emit(new Scalar(NodeStyles)); emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Block)); foreach (var nodeStyle in metaModel.NodeStyles) { emitter.Emit(new MappingStart()); emitter.Emit(new Scalar(Title)); emitter.Emit(new Scalar(nodeStyle.Title)); emitter.Emit(new Scalar(RefNode)); new MapYamlSerializer().Serialize(nodeStyle.RefNode, emitter); emitter.Emit(new MappingEnd()); } emitter.Emit(new SequenceEnd()); } emitter.Emit(new MappingEnd()); emitter.Emit(new DocumentEnd(true)); emitter.Emit(new StreamEnd()); }