Example #1
0
        /// <summary>
        /// Parse the productions:
        /// flow_mapping         ::= FLOW-MAPPING-START
        ///                          ******************
        ///                          (flow_mapping_entry FLOW-ENTRY)*
        ///                           *                  **********
        ///                          flow_mapping_entry?
        ///                          ******************
        ///                          FLOW-MAPPING-END
        ///                          ****************
        /// flow_mapping_entry   ::= flow_node | KEY flow_node? (VALUE flow_node?)?
        ///                          *           *** *
        /// </summary>
        private Event ParseFlowMappingKey(bool isFirst)
        {
            if (isFirst)
            {
                GetCurrentToken();
                Skip();
            }

            if (!(GetCurrentToken() is FlowMappingEnd))
            {
                if (!isFirst)
                {
                    if (GetCurrentToken() is FlowEntry)
                    {
                        Skip();
                    }
                    else
                    {
                        var current = GetCurrentToken();
                        throw new SemanticErrorException(current.Start, current.End, "While parsing a flow mapping,  did not find expected ',' or '}'.");
                    }
                }

                if (GetCurrentToken() is Key)
                {
                    Skip();

                    if (!(GetCurrentToken() is Value || GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowMappingEnd))
                    {
                        states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE);
                        return(ParseNode(false, false));
                    }
                    else
                    {
                        state = ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE;
                        return(ProcessEmptyScalar(GetCurrentToken().Start));
                    }
                }
                else if (!(GetCurrentToken() is FlowMappingEnd))
                {
                    states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE);
                    return(ParseNode(false, false));
                }
            }

            state = states.Pop();
            Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);

            Skip();
            return(evt);
        }
Example #2
0
        /// <summary>
        /// Parse the productions:
        /// block_mapping        ::= BLOCK-MAPPING_START
        ///                          *******************
        ///                          ((KEY block_node_or_indentless_sequence?)?
        ///                            *** *
        ///                          (VALUE block_node_or_indentless_sequence?)?)*
        ///
        ///                          BLOCK-END
        ///                          *********
        /// </summary>
        private Event ParseBlockMappingKey(bool isFirst)
        {
            if (isFirst)
            {
                GetCurrentToken();
                Skip();
            }

            if (GetCurrentToken() is Key)
            {
                Mark mark = GetCurrentToken().End;
                Skip();
                if (!(GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
                {
                    states.Push(ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE);
                    return(ParseNode(true, true));
                }
                else
                {
                    state = ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE;
                    return(ProcessEmptyScalar(mark));
                }
            }

            else if (GetCurrentToken() is BlockEnd)
            {
                state = states.Pop();
                Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
                Skip();
                return(evt);
            }

            else
            {
                var current = GetCurrentToken();
                throw new SemanticErrorException(current.Start, current.End, "While parsing a block mapping, did not find expected key.");
            }
        }
Example #3
0
		/// <summary>
		/// Parse the productions:
		/// flow_mapping         ::= FLOW-MAPPING-START
		///                          ******************
		///                          (flow_mapping_entry FLOW-ENTRY)*
		///                           *                  **********
		///                          flow_mapping_entry?
		///                          ******************
		///                          FLOW-MAPPING-END
		///                          ****************
		/// flow_mapping_entry   ::= flow_node | KEY flow_node? (VALUE flow_node?)?
		///                          *           *** *
		/// </summary>
		private Event ParseFlowMappingKey(bool isFirst)
		{
			if (isFirst)
			{
				GetCurrentToken();
				Skip();
			}

			if (!(GetCurrentToken() is FlowMappingEnd))
			{
				if (!isFirst)
				{
					if (GetCurrentToken() is FlowEntry)
					{
						Skip();
					}
					else
					{
						var current = GetCurrentToken();
						throw new SemanticErrorException(current.Start, current.End, "While parsing a flow mapping,  did not find expected ',' or '}'.");
					}
				}

				if (GetCurrentToken() is Key)
				{
					Skip();

					if (!(GetCurrentToken() is Value || GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowMappingEnd))
					{
						states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE);
						return ParseNode(false, false);
					}
					else
					{
						state = ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE;
						return ProcessEmptyScalar(GetCurrentToken().Start);
					}
				}
				else if (!(GetCurrentToken() is FlowMappingEnd))
				{
					states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE);
					return ParseNode(false, false);
				}
			}

			state = states.Pop();
			Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
			Skip();
			return evt;
		}
Example #4
0
		/// <summary>
		/// Parse the productions:
		/// block_mapping        ::= BLOCK-MAPPING_START
		///                          *******************
		///                          ((KEY block_node_or_indentless_sequence?)?
		///                            *** *
		///                          (VALUE block_node_or_indentless_sequence?)?)*
		///
		///                          BLOCK-END
		///                          *********
		/// </summary>
		private Event ParseBlockMappingKey(bool isFirst)
		{
			if (isFirst)
			{
				GetCurrentToken();
				Skip();
			}

			if (GetCurrentToken() is Key)
			{
				Mark mark = GetCurrentToken().End;
				Skip();
				if (!(GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
				{
					states.Push(ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE);
					return ParseNode(true, true);
				}
				else
				{
					state = ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE;
					return ProcessEmptyScalar(mark);
				}
			}

			else if (GetCurrentToken() is BlockEnd)
			{
				state = states.Pop();
				Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
				Skip();
				return evt;
			}

			else
			{
				var current = GetCurrentToken();
				throw new SemanticErrorException(current.Start, current.End, "While parsing a block mapping, did not find expected key.");
			}
		}