- π Ό proto_schema_parser
- π Ό proto_schema_parser.ast
- π Ό proto_schema_parser.generator
- π Ό proto_schema_parser.parser
- π
Ό
Parser - π
Ό
Message - π
Ό
Field - π
Ό
Option - π
Ό
FieldCardinality
- Classes:
- π ² FieldCardinality
- π ² File
- π ² Comment
- π ² Package
- π ² Import
- π ² MessageLiteralField
- π ² MessageLiteral
- π ² Option
- π ² Message
- π ² Field
- π ² MapField
- π ² Group
- π ² OneOf
- π ² ExtensionRange
- π ² Reserved
- π ² Enum
- π ² EnumValue
- π ² EnumReserved
- π ² Extension
- π ² Service
- π ² Method
- π ² MessageType
- π ² Identifier
class FieldCardinality(str, PyEnum):class File:Represents a .proto file.
Attributes:
- syntax: Union[str, None] The syntax level of the .proto file.
- edition: Union[str, None] The edition level of the .proto file.
- file_elements: List[FileElement] A list of file elements in the .proto file.
class Comment:Represents a comment in a .proto file.
Attributes:
class Package:Represents a package declaration in a .proto file.
Attributes:
class Import:Represents an import declaration in a .proto file.
Attributes:
- name: str The name of the imported file.
- weak: bool True if the import is weak, False otherwise.
- public: bool True if the import is public, False otherwise.
class MessageLiteralField:Represents a field in a message literal.
Attributes:
class MessageLiteral:Represents a message literal.
Attributes:
class Option:Represents an option in a .proto file.
Attributes:
- name: str The name of the option.
- value: Union[ScalarValue, MessageLiteral] The value of the option.
class Message:Represents a message in a .proto file.
Attributes:
class Field:Represents a field in a message.
Attributes:
- name: str The name of the field.
- number: int The number of the field.
- type: str The type of the field.
- cardinality: Union[FieldCardinality, None] = None The cardinality of the field.
- options: List[Option] = field(default_factory=list) The options of the field.
class MapField:Represents a map field in a message.
Attributes:
- name: str The name of the field.
- number: int The number of the field.
- key_type: str The type of the key.
- value_type: str The type of the value.
- options: List[Option] = field(default_factory=list) The options of the field.
class Group:Represents a group in a message.
Attributes:
- name: str The name of the group.
- number: int The number of the group.
- cardinality: Union[FieldCardinality, None] = None The cardinality of the group.
- elements: List[MessageElement] = field(default_factory=list) The elements of the group.
class OneOf:Represents an oneof in a message.
Attributes:
- name: str The name of the oneof.
- elements: List[OneOfElement] = field(default_factory=list) The elements of the oneof.
class ExtensionRange:Represents an extension range in a message.
Attributes:
- ranges: List[str] The ranges of the extension.
- options: List[Option] = field(default_factory=list) The options of the extension.
class Reserved:Represents a reserved range or name in a message.
Attributes:
- ranges: List[str] The ranges of the reserved field.
- names: List[str] The names of the reserved field.
class Enum:Represents an enum in a message.
Attributes:
- name: str The name of the enum.
- elements: List[EnumElement] = field(default_factory=list) The elements of the enum.
class EnumValue:Represents an enum value in an enum.
Attributes:
- name: str The name of the enum value.
- number: int The number of the enum value.
- options: List[Option] = field(default_factory=list) The options of the enum value.
class EnumReserved:Represents a reserved range or name in an enum.
Attributes:
- ranges: List[str] The ranges of the reserved field.
- names: List[str] The names of the reserved field.
class Extension:Represents an extension in a message.
Attributes:
- typeName: str The type name of the extension.
- elements: List[ExtensionElement] = field(default_factory=list) The elements of the extension.
class Service:Represents a service in a message.
Attributes:
- name: str The name of the service.
- elements: List[ServiceElement] = field(default_factory=list) The elements of the service.
class Method:Represents a method in a service.
Attributes:
- name: str The name of the method.
- input_type: MessageType The input type of the method.
- output_type: MessageType The output type of the method.
- elements: List[MethodElement] = field(default_factory=list) The elements of the method.
class MessageType:Represents a message type in a message.
Attributes:
class Identifier:Identifier is a simple dataclass to represent an unquoted identifier (such
as an enumerator name). It's used as a value for scalar types that can't be parsed into a string, int, float, or bool.
- Classes:
- π ² Generator
class Generator:Generator class that takes an abstract syntax tree (AST) and
generates a protobuf schema string.
Functions:
def generate(self, file: ast.File) -> str:Generates a protobuf schema string from an abstract syntax tree (AST).
Parameters:
- file (
ast.File): The abstract syntax tree of the .proto file.
Returns:
- Classes:
- π ² Parser
class Parser:Parser class that takes a string representing a protobuf schema and returns an
abstract syntax tree (AST).
Functions:
def __init__(self, setup_lexer: Optional[SetupLexerCb] = None, setup_parser: Optional[SetupParserCb] = None) -> None:Initializes a new instance of the Parser class.
Parameters:
- setup_lexer (
Optional[SetupLexerCb]): A callback function to modify the lexer during parsing. Defaults to None. - setup_parser (
Optional[SetupParserCb]): A callback function to modify the parser during parsing. Defaults to None.
def parse(self, text: str) -> ast.File:Parses a string representing a protobuf schema and returns an abstract syntax tree (AST).
Parameters:
- text (
str): The string representing the protobuf schema.
Returns:
ast.File: The abstract syntax tree representation of the protobuf schema.