Example #1
0
            private void ReadSectionHeader()
            {
                if (_sections.Peek() is Mode)
                {
                    throw new ParseException(Location, "Cannot start section inside mode.");
                }
                ReadSome(' ');
                var sectionType = ReadIdentifier();

                ReadSome(' ');
                var argument = ReadArguments().Require(targetCount: 1, delimiter: Constants.ArgumentDelimiter);

                Read('\n');
                var section = CreateSection(sectionType, argument);

                if (section is Mode mode)
                {
                    if (_sections.Count > 1)
                    {
                        throw new ParseException(sectionType.Location, "A mode is only valid at the top level.");
                    }
                    section = _parserOutput.AddMode(mode);
                }
                _sections.Push(section);
            }