kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/indexer/textproto/recordio_textparser.h (about) 1 /* 2 * Copyright 2023 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef KYTHE_CXX_INDEXER_TEXTPROTO_RECORDIO_TEXTPARSER_H_ 18 #define KYTHE_CXX_INDEXER_TEXTPROTO_RECORDIO_TEXTPARSER_H_ 19 20 #include <optional> 21 22 #include "absl/functional/function_ref.h" 23 #include "absl/strings/string_view.h" 24 #include "google/protobuf/descriptor.h" 25 #include "google/protobuf/dynamic_message.h" 26 #include "google/protobuf/text_format.h" 27 28 namespace kythe { 29 namespace lang_textproto { 30 31 // Parses recordio text-formatted content separated by record delimiter. 32 // Callback is invoked for each chunk that is parsed into proto message along 33 // with the line offset of where that chunk begins in the file. 34 // 35 // Empty lines can be record delimiter and they can also separate two chunks 36 // of comments. Always gather chunk of comments into one big chunk along 37 // with next message. For example: 38 // 1. # FooBar 39 // 2. # Bar 40 // 3. 41 // 4. # BarBar 42 // 5. name: "hello" 43 // 44 // In the above example, line 1-5 should be read as one chunk even if the 45 // delimiter is empty line. Also, note that last record usually does not have 46 // delimiter specified and the record ends at EOF. 47 // Also, note that delimiter could start with '#' which is also for the 48 // comment. 49 void ParseRecordTextChunks( 50 absl::string_view content, absl::string_view record_delimiter, 51 absl::FunctionRef<void(absl::string_view chunk, int chunk_start_line)> 52 callback); 53 54 } // namespace lang_textproto 55 } // namespace kythe 56 57 #endif // KYTHE_CXX_INDEXER_TEXTPROTO_RECORDIO_TEXTPARSER_H_