|
2 | 2 |
|
3 | 3 | ## Table of Contents
|
4 | 4 |
|
| 5 | +- [`proto_schema_parser`](#proto-schema-parser) |
| 6 | + - [`ast`](#proto-schema-parser-ast) |
| 7 | + - [`FieldCardinality`](#proto-schema-parser-ast-fieldcardinality) |
| 8 | + - [`File`](#proto-schema-parser-ast-file) |
| 9 | + - [`Comment`](#proto-schema-parser-ast-comment) |
| 10 | + - [`Package`](#proto-schema-parser-ast-package) |
| 11 | + - [`Import`](#proto-schema-parser-ast-import) |
| 12 | + - [`MessageLiteralField`](#proto-schema-parser-ast-messageliteralfield) |
| 13 | + - [`MessageLiteral`](#proto-schema-parser-ast-messageliteral) |
| 14 | + - [`Option`](#proto-schema-parser-ast-option) |
| 15 | + - [`Message`](#proto-schema-parser-ast-message) |
| 16 | + - [`Field`](#proto-schema-parser-ast-field) |
| 17 | + - [`MapField`](#proto-schema-parser-ast-mapfield) |
| 18 | + - [`Group`](#proto-schema-parser-ast-group) |
| 19 | + - [`OneOf`](#proto-schema-parser-ast-oneof) |
| 20 | + - [`ExtensionRange`](#proto-schema-parser-ast-extensionrange) |
| 21 | + - [`Reserved`](#proto-schema-parser-ast-reserved) |
| 22 | + - [`Enum`](#proto-schema-parser-ast-enum) |
| 23 | + - [`EnumValue`](#proto-schema-parser-ast-enumvalue) |
| 24 | + - [`EnumReserved`](#proto-schema-parser-ast-enumreserved) |
| 25 | + - [`Extension`](#proto-schema-parser-ast-extension) |
| 26 | + - [`Service`](#proto-schema-parser-ast-service) |
| 27 | + - [`Method`](#proto-schema-parser-ast-method) |
| 28 | + - [`MessageType`](#proto-schema-parser-ast-messagetype) |
| 29 | + - [`Identifier`](#proto-schema-parser-ast-identifier) |
| 30 | + - [`generator`](#proto-schema-parser-generator) |
| 31 | + - [`Generator`](#proto-schema-parser-generator-generator) |
| 32 | + - [`generate`](#proto-schema-parser-generator-generator-generate) |
| 33 | + - [`parser`](#proto-schema-parser-parser) |
| 34 | + - [`Parser`](#proto-schema-parser-parser-parser) |
| 35 | + - [`__init__`](#proto-schema-parser-parser-parser-init) |
| 36 | + - [`parse`](#proto-schema-parser-parser-parser-parse) |
5 | 37 |
|
| 38 | +<a id="proto-schema-parser"></a> |
| 39 | +# `proto_schema_parser` |
| 40 | + |
| 41 | + |
| 42 | +**Exports:** |
| 43 | + |
| 44 | +- `Parser` |
| 45 | +- `Message` |
| 46 | +- `Field` |
| 47 | +- `Option` |
| 48 | +- `FieldCardinality` |
| 49 | + |
| 50 | +<a id="proto-schema-parser-ast"></a> |
| 51 | +## `ast` |
| 52 | + |
| 53 | +<a id="proto-schema-parser-ast-fieldcardinality"></a> |
| 54 | +### `FieldCardinality` |
| 55 | + |
| 56 | +<a id="proto-schema-parser-ast-file"></a> |
| 57 | +### `File` |
| 58 | + |
| 59 | +Represents a .proto file. |
| 60 | + |
| 61 | +<a id="proto-schema-parser-ast-comment"></a> |
| 62 | +### `Comment` |
| 63 | + |
| 64 | +Represents a comment in a .proto file. |
| 65 | + |
| 66 | +<a id="proto-schema-parser-ast-package"></a> |
| 67 | +### `Package` |
| 68 | + |
| 69 | +Represents a package declaration in a .proto file. |
| 70 | + |
| 71 | +<a id="proto-schema-parser-ast-import"></a> |
| 72 | +### `Import` |
| 73 | + |
| 74 | +Represents an import declaration in a .proto file. |
| 75 | + |
| 76 | +<a id="proto-schema-parser-ast-messageliteralfield"></a> |
| 77 | +### `MessageLiteralField` |
| 78 | + |
| 79 | +Represents a field in a message literal. |
| 80 | + |
| 81 | +<a id="proto-schema-parser-ast-messageliteral"></a> |
| 82 | +### `MessageLiteral` |
| 83 | + |
| 84 | +Represents a message literal. |
| 85 | + |
| 86 | +<a id="proto-schema-parser-ast-option"></a> |
| 87 | +### `Option` |
| 88 | + |
| 89 | +Represents an option in a .proto file. |
| 90 | + |
| 91 | +<a id="proto-schema-parser-ast-message"></a> |
| 92 | +### `Message` |
| 93 | + |
| 94 | +Represents a message in a .proto file. |
| 95 | + |
| 96 | +<a id="proto-schema-parser-ast-field"></a> |
| 97 | +### `Field` |
| 98 | + |
| 99 | +Represents a field in a message. |
| 100 | + |
| 101 | +<a id="proto-schema-parser-ast-mapfield"></a> |
| 102 | +### `MapField` |
| 103 | + |
| 104 | +Represents a map field in a message. |
| 105 | + |
| 106 | +<a id="proto-schema-parser-ast-group"></a> |
| 107 | +### `Group` |
| 108 | + |
| 109 | +Represents a group in a message. |
| 110 | + |
| 111 | +<a id="proto-schema-parser-ast-oneof"></a> |
| 112 | +### `OneOf` |
| 113 | + |
| 114 | +Represents an oneof in a message. |
| 115 | + |
| 116 | +<a id="proto-schema-parser-ast-extensionrange"></a> |
| 117 | +### `ExtensionRange` |
| 118 | + |
| 119 | +Represents an extension range in a message. |
| 120 | + |
| 121 | +<a id="proto-schema-parser-ast-reserved"></a> |
| 122 | +### `Reserved` |
| 123 | + |
| 124 | +Represents a reserved range or name in a message. |
| 125 | + |
| 126 | +<a id="proto-schema-parser-ast-enum"></a> |
| 127 | +### `Enum` |
| 128 | + |
| 129 | +Represents an enum in a message. |
| 130 | + |
| 131 | +<a id="proto-schema-parser-ast-enumvalue"></a> |
| 132 | +### `EnumValue` |
| 133 | + |
| 134 | +Represents an enum value in an enum. |
| 135 | + |
| 136 | +<a id="proto-schema-parser-ast-enumreserved"></a> |
| 137 | +### `EnumReserved` |
| 138 | + |
| 139 | +Represents a reserved range or name in an enum. |
| 140 | + |
| 141 | +<a id="proto-schema-parser-ast-extension"></a> |
| 142 | +### `Extension` |
| 143 | + |
| 144 | +Represents an extension in a message. |
| 145 | + |
| 146 | +<a id="proto-schema-parser-ast-service"></a> |
| 147 | +### `Service` |
| 148 | + |
| 149 | +Represents a service in a message. |
| 150 | + |
| 151 | +<a id="proto-schema-parser-ast-method"></a> |
| 152 | +### `Method` |
| 153 | + |
| 154 | +Represents a method in a service. |
| 155 | + |
| 156 | +<a id="proto-schema-parser-ast-messagetype"></a> |
| 157 | +### `MessageType` |
| 158 | + |
| 159 | +Represents a message type in a message. |
| 160 | + |
| 161 | +<a id="proto-schema-parser-ast-identifier"></a> |
| 162 | +### `Identifier` |
| 163 | + |
| 164 | +Identifier is a simple dataclass to represent an unquoted identifier (such |
| 165 | + |
| 166 | +as an enumerator name). It's used as a value for scalar types that can't be |
| 167 | +parsed into a string, int, float, or bool. |
| 168 | + |
| 169 | +<a id="proto-schema-parser-generator"></a> |
| 170 | +## `generator` |
| 171 | + |
| 172 | +<a id="proto-schema-parser-generator-generator"></a> |
| 173 | +### `Generator` |
| 174 | + |
| 175 | +Generator class that takes an abstract syntax tree (AST) and |
| 176 | + |
| 177 | +generates a protobuf schema string. |
| 178 | + |
| 179 | +<a id="proto-schema-parser-generator-generator-generate"></a> |
| 180 | +#### `generate` |
| 181 | + |
| 182 | +```python |
| 183 | +def generate(self, file: ast.File) -> str: |
| 184 | +``` |
| 185 | + |
| 186 | +Generates a protobuf schema string from an abstract syntax tree (AST). |
| 187 | + |
| 188 | +**Args:** |
| 189 | + |
| 190 | +- `file` (*ast.File*): The abstract syntax tree of the .proto file. |
| 191 | + |
| 192 | +**Returns:** (*str*) The generated protobuf schema string. |
| 193 | + |
| 194 | +<a id="proto-schema-parser-parser"></a> |
| 195 | +## `parser` |
| 196 | + |
| 197 | +<a id="proto-schema-parser-parser-parser"></a> |
| 198 | +### `Parser` |
| 199 | + |
| 200 | +Parser class that takes a string representing a protobuf schema and returns an |
| 201 | + |
| 202 | +abstract syntax tree (AST). |
| 203 | + |
| 204 | +<a id="proto-schema-parser-parser-parser-init"></a> |
| 205 | +#### `__init__` |
| 206 | + |
| 207 | +```python |
| 208 | +def __init__(self, *, setup_lexer: Optional[SetupLexerCb], setup_parser: Optional[SetupParserCb]) -> None: |
| 209 | +``` |
| 210 | + |
| 211 | +Initializes a new instance of the Parser class. |
| 212 | + |
| 213 | +**Args:** |
| 214 | + |
| 215 | +- `setup_lexer` (*Optional[SetupLexerCb]*): A callback function to |
| 216 | +modify the lexer during parsing. Defaults to None. |
| 217 | +- `setup_parser` (*Optional[SetupParserCb]*): A callback function |
| 218 | +to modify the parser during parsing. Defaults to None. |
| 219 | + |
| 220 | +<a id="proto-schema-parser-parser-parser-parse"></a> |
| 221 | +#### `parse` |
| 222 | + |
| 223 | +```python |
| 224 | +def parse(self, text: str) -> ast.File: |
| 225 | +``` |
| 226 | + |
| 227 | +Parses a string representing a protobuf schema and returns an abstract syntax tree (AST). |
| 228 | + |
| 229 | +**Args:** |
| 230 | + |
| 231 | +- `text` (*str*): The string representing the protobuf schema. |
| 232 | + |
| 233 | +**Returns:** (*ast.File*) The abstract syntax tree representation of the protobuf schema. |
0 commit comments