void SetDataItemProperty(DataItem dataItem, NodeProperty property) { if (property.Anchor != null) { currentDocument.AnchoredItems[property.Anchor] = dataItem; } dataItem.Property = property; }
/// <summary> /// Tries wrap <see cref="DataItem"/> object for using dynamic features. /// </summary> /// <param name="value">The value.</param> /// <param name="result">The result.</param> /// <returns>wrapped <see cref="DataItem"/> object.</returns> internal static bool TryMapValue(DataItem value, out Object result) { if (value is Scalar) { result = (value as Scalar).Text; return true; } if (value is Sequence) { result = (value as Sequence).Enties.Select(MapValue).ToList(); return true; } if (value is Mapping) { result = new YamlMapping(value as Mapping); return true; } result = null; return false; }
private static Object MapValue(DataItem value) { Object result; TryMapValue(value, out result); return result; }
private DataItem ParseAliasNode(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; MatchTerminal('*', out success); if (!success) { Error("Failed to parse '*' of AliasNode."); position = start_position; return dataItem; } string name = ParseAnchorName(out success); if (success) { return GetAnchoredDataItem(name); } else { Error("Failed to parse name of AliasNode."); position = start_position; } return dataItem; }
private DataItem ParseFlowNodeInFlow(out bool success) { DataItem dataItem = new DataItem(); dataItem = ParseAliasNode(out success); if (success) { ClearError(); return dataItem; } dataItem = ParseFlowContentInFlow(out success); if (success) { ClearError(); return dataItem; } while (true) { int seq_start_position1 = position; NodeProperty property = ParseNodeProperty(out success); if (success) { dataItem = new Scalar(); } else { Error("Failed to parse property of FlowNodeInFlow."); break; } while (true) { int seq_start_position2 = position; ParseSeparationLinesInFlow(out success); if (!success) { Error("Failed to parse SeparationLinesInFlow of FlowNodeInFlow."); break; } dataItem = ParseFlowContentInFlow(out success); if (!success) { Error("Failed to parse FlowContentInFlow of FlowNodeInFlow."); position = seq_start_position2; } break; } if (success) { SetDataItemProperty(dataItem, property); } success = true; break; } if (success) { ClearError(); return dataItem; } return dataItem; }
private DataItem ParseSeparatedBlock(out bool success) { DataItem dataItem = new DataItem(); dataItem = ParseSeparatedContent(out success); if (success) { ClearError(); return dataItem; } while (true) { int seq_start_position1 = position; ParseSeparationLines(out success); if (!success) { Error("Failed to parse SeparationLines of SeparatedBlock."); break; } dataItem = ParseAliasNode(out success); if (!success) { Error("Failed to parse AliasNode of SeparatedBlock."); position = seq_start_position1; break; } ParseInlineComments(out success); if (!success) { Error("Failed to parse InlineComments of SeparatedBlock."); position = seq_start_position1; } break; } if (success) { ClearError(); return dataItem; } while (true) { int seq_start_position2 = position; ParseSeparationSpace(out success); if (!success) { Error("Failed to parse SeparationSpace of SeparatedBlock."); break; } NodeProperty property = ParseNodeProperty(out success); if (!success) { Error("Failed to parse property of SeparatedBlock."); position = seq_start_position2; break; } dataItem = ParseSeparatedContent(out success); if (success) { SetDataItemProperty(dataItem, property); } success = true; break; } if (success) { ClearError(); return dataItem; } dataItem = ParseEmptyBlock(out success); if (success) { ClearError(); return dataItem; } return dataItem; }
private DataItem ParseSeparatedBlockNode(out bool success) { IncreaseIndent(); DataItem dataItem = new DataItem(); dataItem = ParseSeparatedBlock(out success); DecreaseIndent(); if (!success) { Error("Failed to parse SeparatedBlock of SeparatedBlockNode."); } return dataItem; }
private DataItem ParseDataItem(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; while (true) { int seq_start_position1 = position; dataItem.Property = ParseNodeProperty(out success); if (!success) { Error("Failed to parse Property of DataItem."); break; } ParseSeparationLines(out success); if (!success) { Error("Failed to parse SeparationLines of DataItem."); position = seq_start_position1; } break; } success = true; while (true) { dataItem = ParseScalar(out success); if (success) { ClearError(); break; } dataItem = ParseSequence(out success); if (success) { ClearError(); break; } dataItem = ParseMapping(out success); if (success) { ClearError(); break; } break; } if (!success) { Error("Failed to parse (Scalar / Sequence / Mapping) of DataItem."); position = start_position; } return dataItem; }
private DataItem ParseBlockSimpleValue(out bool success) { DataItem dataItem = new DataItem(); dataItem = ParseBlockCollectionEntry(out success); if (!success) { Error("Failed to parse BlockCollectionEntry of BlockSimpleValue."); } return dataItem; }
private DataItem ParseBlockSimpleKey(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; dataItem = ParseBlockKey(out success); if (!success) { Error("Failed to parse BlockKey of BlockSimpleKey."); position = start_position; return dataItem; } ParseSeparationLines(out success); success = true; MatchTerminal(':', out success); if (!success) { Error("Failed to parse ':' of BlockSimpleKey."); position = start_position; } return dataItem; }
private DataItem ParseBlockExplicitValue(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; ParseIndent(out success); if (!success) { Error("Failed to parse Indent of BlockExplicitValue."); position = start_position; return dataItem; } MatchTerminal(':', out success); if (!success) { Error("Failed to parse ':' of BlockExplicitValue."); position = start_position; return dataItem; } dataItem = ParseBlockCollectionEntry(out success); if (!success) { Error("Failed to parse BlockCollectionEntry of BlockExplicitValue."); position = start_position; } return dataItem; }
private DataItem ParseSimpleKey(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; dataItem = ParseFlowKey(out success); if (!success) { Error("Failed to parse FlowKey of SimpleKey."); position = start_position; return dataItem; } ParseSeparationLinesInFlow(out success); success = true; return dataItem; }
private DataItem ParseBlockSequenceEntry(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; MatchTerminal('-', out success); if (!success) { Error("Failed to parse '-' of BlockSequenceEntry."); position = start_position; return dataItem; } dataItem = ParseBlockCollectionEntry(out success); if (!success) { Error("Failed to parse BlockCollectionEntry of BlockSequenceEntry."); position = start_position; } return dataItem; }
private DataItem ParseEmptyBlock(out bool success) { DataItem dataItem = new DataItem(); int start_position = position; dataItem = ParseEmptyFlow(out success); ParseInlineComments(out success); if (!success) { Error("Failed to parse InlineComments of EmptyBlock."); position = start_position; } return dataItem; }
private DataItem ParseEmptyFlow(out bool success) { DataItem dataItem = new DataItem(); success = true; if (success) { return new Scalar(); } return dataItem; }
private void AddNode(DataItem node, String path) { var mapping = node as Mapping; if (mapping != null) { foreach (var record in mapping.Enties) { var key = record.Key as Scalar; if (key != null) { AddNode(record.Value, Combine(key.Text, path)); } } } var scalar = node as Scalar; if (scalar != null) { resources[path] = scalar.Text; } }