private ParsingEvent ParseNode(bool isBlock, bool isIndentlessSequence) { YamlDotNet.Core.Tokens.AnchorAlias anchorAlias = GetCurrentToken() as YamlDotNet.Core.Tokens.AnchorAlias; if (anchorAlias != null) { state = states.Pop(); ParsingEvent result = new YamlDotNet.Core.Events.AnchorAlias(anchorAlias.Value, anchorAlias.Start, anchorAlias.End); Skip(); return(result); } Mark start = GetCurrentToken().Start; Anchor anchor = null; YamlDotNet.Core.Tokens.Tag tag = null; while (true) { if (anchor == null && (anchor = (GetCurrentToken() as Anchor)) != null) { Skip(); } else { if (tag != null || (tag = (GetCurrentToken() as YamlDotNet.Core.Tokens.Tag)) == null) { break; } Skip(); } } string text = null; if (tag != null) { if (string.IsNullOrEmpty(tag.Handle)) { text = tag.Suffix; } else { if (!tagDirectives.Contains(tag.Handle)) { throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, find undefined tag handle."); } text = tagDirectives[tag.Handle].Prefix + tag.Suffix; } } if (string.IsNullOrEmpty(text)) { text = null; } string text2 = (anchor == null) ? null : ((!string.IsNullOrEmpty(anchor.Value)) ? anchor.Value : null); bool flag = string.IsNullOrEmpty(text); if (isIndentlessSequence && GetCurrentToken() is BlockEntry) { state = ParserState.IndentlessSequenceEntry; return(new SequenceStart(text2, text, flag, SequenceStyle.Block, start, GetCurrentToken().End)); } YamlDotNet.Core.Tokens.Scalar scalar = GetCurrentToken() as YamlDotNet.Core.Tokens.Scalar; if (scalar != null) { bool isPlainImplicit = false; bool isQuotedImplicit = false; if ((scalar.Style == ScalarStyle.Plain && text == null) || text == "!") { isPlainImplicit = true; } else if (text == null) { isQuotedImplicit = true; } state = states.Pop(); ParsingEvent result2 = new YamlDotNet.Core.Events.Scalar(text2, text, scalar.Value, scalar.Style, isPlainImplicit, isQuotedImplicit, start, scalar.End); Skip(); return(result2); } FlowSequenceStart flowSequenceStart = GetCurrentToken() as FlowSequenceStart; if (flowSequenceStart != null) { state = ParserState.FlowSequenceFirstEntry; return(new SequenceStart(text2, text, flag, SequenceStyle.Flow, start, flowSequenceStart.End)); } FlowMappingStart flowMappingStart = GetCurrentToken() as FlowMappingStart; if (flowMappingStart != null) { state = ParserState.FlowMappingFirstKey; return(new MappingStart(text2, text, flag, MappingStyle.Flow, start, flowMappingStart.End)); } if (isBlock) { BlockSequenceStart blockSequenceStart = GetCurrentToken() as BlockSequenceStart; if (blockSequenceStart != null) { state = ParserState.BlockSequenceFirstEntry; return(new SequenceStart(text2, text, flag, SequenceStyle.Block, start, blockSequenceStart.End)); } BlockMappingStart blockMappingStart = GetCurrentToken() as BlockMappingStart; if (blockMappingStart != null) { state = ParserState.BlockMappingFirstKey; return(new MappingStart(text2, text, flag, MappingStyle.Block, start, GetCurrentToken().End)); } } if (text2 != null || tag != null) { state = states.Pop(); return(new YamlDotNet.Core.Events.Scalar(text2, text, string.Empty, ScalarStyle.Plain, flag, false, start, GetCurrentToken().End)); } Token token = GetCurrentToken(); throw new SemanticErrorException(token.Start, token.End, "While parsing a node, did not find expected node content."); }
/// <summary> /// Parse the productions: /// block_node_or_indentless_sequence ::= /// ALIAS /// ***** /// | properties (block_content | indentless_block_sequence)? /// ********** * /// | block_content | indentless_block_sequence /// * /// block_node ::= ALIAS /// ***** /// | properties block_content? /// ********** * /// | block_content /// * /// flow_node ::= ALIAS /// ***** /// | properties flow_content? /// ********** * /// | flow_content /// * /// properties ::= TAG ANCHOR? | ANCHOR TAG? /// ************************* /// block_content ::= block_collection | flow_collection | SCALAR /// ****** /// flow_content ::= flow_collection | SCALAR /// ****** /// </summary> private Event ParseNode(bool isBlock, bool isIndentlessSequence) { AnchorAlias alias = GetCurrentToken() as AnchorAlias; if (alias != null) { state = states.Pop(); Event evt = new Events.AnchorAlias(alias.Value, alias.Start, alias.End); Skip(); return(evt); } Mark start = GetCurrentToken().Start; Anchor anchor = null; Tag tag = null; // The anchor and the tag can be in any order. This loop repeats at most twice. while (true) { if (anchor == null && (anchor = GetCurrentToken() as Anchor) != null) { Skip(); } else if (tag == null && (tag = GetCurrentToken() as Tag) != null) { Skip(); } else { break; } } string tagName = null; if (tag != null) { if (string.IsNullOrEmpty(tag.Handle)) { tagName = tag.Suffix; } else if (tagDirectives.Contains(tag.Handle)) { tagName = string.Concat(tagDirectives[tag.Handle].Prefix, tag.Suffix); } else { throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, find undefined tag handle."); } } if (string.IsNullOrEmpty(tagName)) { tagName = null; } string anchorName = anchor != null?string.IsNullOrEmpty(anchor.Value) ? null : anchor.Value : null; bool isImplicit = string.IsNullOrEmpty(tagName); if (isIndentlessSequence && GetCurrentToken() is BlockEntry) { state = ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE; return(new Events.SequenceStart( anchorName, tagName, isImplicit, SequenceStyle.Block, start, GetCurrentToken().End )); } else { Scalar scalar = GetCurrentToken() as Scalar; if (scalar != null) { bool isPlainImplicit = false; bool isQuotedImplicit = false; if ((scalar.Style == ScalarStyle.Plain && tagName == null) || tagName == Constants.DefaultHandle) { isPlainImplicit = true; } else if (tagName == null) { isQuotedImplicit = true; } state = states.Pop(); Event evt = new Events.Scalar(anchorName, tagName, scalar.Value, scalar.Style, isPlainImplicit, isQuotedImplicit, start, scalar.End); Skip(); return(evt); } FlowSequenceStart flowSequenceStart = GetCurrentToken() as FlowSequenceStart; if (flowSequenceStart != null) { state = ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE; return(new Events.SequenceStart(anchorName, tagName, isImplicit, SequenceStyle.Flow, start, flowSequenceStart.End)); } FlowMappingStart flowMappingStart = GetCurrentToken() as FlowMappingStart; if (flowMappingStart != null) { state = ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE; return(new Events.MappingStart(anchorName, tagName, isImplicit, MappingStyle.Flow, start, flowMappingStart.End)); } if (isBlock) { BlockSequenceStart blockSequenceStart = GetCurrentToken() as BlockSequenceStart; if (blockSequenceStart != null) { state = ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE; return(new Events.SequenceStart(anchorName, tagName, isImplicit, SequenceStyle.Block, start, blockSequenceStart.End)); } BlockMappingStart blockMappingStart = GetCurrentToken() as BlockMappingStart; if (blockMappingStart != null) { state = ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE; return(new Events.MappingStart(anchorName, tagName, isImplicit, MappingStyle.Block, start, GetCurrentToken().End)); } } if (anchorName != null || tag != null) { state = states.Pop(); return(new Events.Scalar(anchorName, tagName, string.Empty, ScalarStyle.Plain, isImplicit, false, start, GetCurrentToken().End)); } var current = GetCurrentToken(); throw new SemanticErrorException(current.Start, current.End, "While parsing a node, did not find expected node content."); } }
private ParsingEvent ParseNode(bool isBlock, bool isIndentlessSequence) { AnchorAlias currentToken = this.GetCurrentToken() as AnchorAlias; if (currentToken != null) { this.state = this.states.Pop(); ParsingEvent event2 = new AnchorAlias(currentToken.Value, currentToken.Start, currentToken.End); this.Skip(); return(event2); } Mark mark = this.GetCurrentToken().Start; Anchor anchor = null; Tag tag = null; while (true) { if ((anchor == null) && ((anchor = this.GetCurrentToken() as Anchor) != null)) { this.Skip(); continue; } if ((tag != null) || ((tag = this.GetCurrentToken() as Tag) == null)) { string suffix = null; if (tag != null) { if (string.IsNullOrEmpty(tag.Handle)) { suffix = tag.Suffix; } else { if (!this.tagDirectives.Contains(tag.Handle)) { throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, find undefined tag handle."); } suffix = this.tagDirectives[tag.Handle].Prefix + tag.Suffix; } } if (string.IsNullOrEmpty(suffix)) { suffix = null; } string str2 = (anchor == null) ? null : (!string.IsNullOrEmpty(anchor.Value) ? anchor.Value : null); bool isImplicit = string.IsNullOrEmpty(suffix); if (isIndentlessSequence && (this.GetCurrentToken() is BlockEntry)) { this.state = ParserState.IndentlessSequenceEntry; return(new SequenceStart(str2, suffix, isImplicit, SequenceStyle.Block, mark, this.GetCurrentToken().End)); } Scalar scalar = this.GetCurrentToken() as Scalar; if (scalar != null) { bool isPlainImplicit = false; bool isQuotedImplicit = false; if (((scalar.Style == ScalarStyle.Plain) && (suffix == null)) || (suffix == "!")) { isPlainImplicit = true; } else if (suffix == null) { isQuotedImplicit = true; } this.state = this.states.Pop(); ParsingEvent event3 = new Scalar(str2, suffix, scalar.Value, scalar.Style, isPlainImplicit, isQuotedImplicit, mark, scalar.End); this.Skip(); return(event3); } FlowSequenceStart start = this.GetCurrentToken() as FlowSequenceStart; if (start != null) { this.state = ParserState.FlowSequenceFirstEntry; return(new SequenceStart(str2, suffix, isImplicit, SequenceStyle.Flow, mark, start.End)); } FlowMappingStart start2 = this.GetCurrentToken() as FlowMappingStart; if (start2 != null) { this.state = ParserState.FlowMappingFirstKey; return(new MappingStart(str2, suffix, isImplicit, MappingStyle.Flow, mark, start2.End)); } if (isBlock) { BlockSequenceStart start3 = this.GetCurrentToken() as BlockSequenceStart; if (start3 != null) { this.state = ParserState.BlockSequenceFirstEntry; return(new SequenceStart(str2, suffix, isImplicit, SequenceStyle.Block, mark, start3.End)); } if (this.GetCurrentToken() is BlockMappingStart) { this.state = ParserState.BlockMappingFirstKey; return(new MappingStart(str2, suffix, isImplicit, MappingStyle.Block, mark, this.GetCurrentToken().End)); } } if ((str2 == null) && (tag == null)) { Token token = this.GetCurrentToken(); throw new SemanticErrorException(token.Start, token.End, "While parsing a node, did not find expected node content."); } this.state = this.states.Pop(); return(new Scalar(str2, suffix, string.Empty, ScalarStyle.Plain, isImplicit, false, mark, this.GetCurrentToken().End)); } this.Skip(); } }