Exemplo n.º 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 ParsingEvent 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.FlowMappingValue);
                        return(ParseNode(false, false));
                    }
                    else
                    {
                        state = ParserState.FlowMappingValue;
                        return(ProcessEmptyScalar(GetCurrentToken().Start));
                    }
                }
                else if (!(GetCurrentToken() is FlowMappingEnd))
                {
                    states.Push(ParserState.FlowMappingEmptyValue);
                    return(ParseNode(false, false));
                }
            }

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

            Skip();
            return(evt);
        }
Exemplo n.º 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 ParsingEvent 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.BlockMappingValue);
                    return(ParseNode(true, true));
                }
                else
                {
                    state = ParserState.BlockMappingValue;
                    return(ProcessEmptyScalar(mark));
                }
            }

            else if (GetCurrentToken() is BlockEnd)
            {
                state = states.Pop();
                ParsingEvent 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.");
            }
        }
Exemplo n.º 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 ParsingEvent 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.FlowMappingValue);
						return ParseNode(false, false);
					}
					else
					{
						state = ParserState.FlowMappingValue;
						return ProcessEmptyScalar(GetCurrentToken().Start);
					}
				}
				else if (!(GetCurrentToken() is FlowMappingEnd))
				{
					states.Push(ParserState.FlowMappingEmptyValue);
					return ParseNode(false, false);
				}
			}

			state = states.Pop();
			ParsingEvent evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
			Skip();
			return evt;
		}
Exemplo n.º 4
0
			void IParsingEventVisitor.Visit(MappingEnd e)
			{
				clonedEvent = new MappingEnd(e.Start, e.End);
			}
Exemplo n.º 5
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 ParsingEvent 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.BlockMappingValue);
					return ParseNode(true, true);
				}
				else
				{
					state = ParserState.BlockMappingValue;
					return ProcessEmptyScalar(mark);
				}
			}

			else if (GetCurrentToken() is BlockEnd)
			{
				state = states.Pop();
				ParsingEvent 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.");
			}
		}