kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/textproto/textproto_schema.h (about)

     1  /*
     2   * Copyright 2019 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_EXTRACTOR_TEXTPROTO_SCHEMA_H_
    18  #define KYTHE_CXX_EXTRACTOR_TEXTPROTO_SCHEMA_H_
    19  
    20  #include <string>
    21  #include <vector>
    22  
    23  #include "absl/strings/string_view.h"
    24  
    25  namespace kythe {
    26  namespace lang_textproto {
    27  
    28  struct TextprotoSchema {
    29    absl::string_view proto_message, proto_file;
    30    std::vector<absl::string_view> proto_imports;
    31  };
    32  
    33  /// Parses comments at the top of textproto files that specify the corresponding
    34  /// proto message and which file that message comes from. The "proto-file" and
    35  /// "proto-message" lines are generally required, while "proto-import" is
    36  /// optional and only needed if the textproto uses extensions that aren't
    37  /// already imported by "proto-file". The comments should be of the form:
    38  ///
    39  ///   # proto-file: some/file.proto
    40  ///   # proto-message: some_namespace.MyMessage
    41  ///   # proto-import: some/other/file.proto
    42  ///   # proto-import: file/with/extensions.proto
    43  ///
    44  /// \param textproto the contents of the textproto file
    45  /// \return the schema information seen in the textproto. May be
    46  /// incomplete.
    47  /// WARNING: The return value is made up of string_views that reference the
    48  /// input. Therefore the input string_view must outlive any use of the output.
    49  TextprotoSchema ParseTextprotoSchemaComments(absl::string_view textproto);
    50  
    51  }  // namespace lang_textproto
    52  }  // namespace kythe
    53  
    54  #endif  // KYTHE_CXX_EXTRACTOR_TEXTPROTO_SCHEMA_H_