Exemplo n.º 1
0
        internal POParseResult(POCatalog catalog, DiagnosticCollection diagnostics)
        {
            if (diagnostics == null)
            {
                throw new ArgumentNullException(nameof(diagnostics));
            }

            Catalog      = catalog;
            _diagnostics = diagnostics;
        }
Exemplo n.º 2
0
        public POParseResult Parse(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _reader = reader;

            _diagnostics = new DiagnosticCollection();
            _catalog     = new POCatalog();

            _line      = null;
            _lineIndex = -1;

            // resets _commentBuffer and _columnIndex
            SeekNextToken();

            try
            {
                if (!TryReadEntry(allowEmptyId: true, result: out IPOEntry entry))
                {
                    return(new POParseResult(_catalog, _diagnostics));
                }

                var isHeader = CheckHeader(entry);
                if (isHeader)
                {
                    ParseHeader((POSingularEntry)entry);
                }

                if (!_flags.HasFlag(Flags.ReadHeaderOnly))
                {
                    if (!isHeader)
                    {
                        _catalog.Add(entry);
                    }

                    while (TryReadEntry(allowEmptyId: false, result: out entry))
                    {
                        _catalog.Add(entry);
                    }
                }

                return(new POParseResult(_catalog, _diagnostics));
            }
            finally
            {
                _builder.Clear();
                if (_builder.Capacity > 1024)
                {
                    _builder.Capacity = 1024;
                }
            }
        }