Skip to content

Latest commit

Β 

History

History
493 lines (364 loc) Β· 11.8 KB

File metadata and controls

493 lines (364 loc) Β· 11.8 KB

proto_schema_parser

Table of Contents

πŸ…Ό proto_schema_parser

Exports

πŸ…Ό proto_schema_parser.ast

Classes

πŸ…² proto_schema_parser.ast.FieldCardinality

class FieldCardinality(str, PyEnum):

πŸ…² proto_schema_parser.ast.File

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.

πŸ…² proto_schema_parser.ast.Comment

class Comment:

Represents a comment in a .proto file.

Attributes:

  • text: str The text of the comment.

πŸ…² proto_schema_parser.ast.Package

class Package:

Represents a package declaration in a .proto file.

Attributes:

  • name: str The name of the package.

πŸ…² proto_schema_parser.ast.Import

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.

πŸ…² proto_schema_parser.ast.MessageLiteralField

class MessageLiteralField:

Represents a field in a message literal.

Attributes:

  • name: str The name of the field.
  • value: MessageValue The value of the field.

πŸ…² proto_schema_parser.ast.MessageLiteral

class MessageLiteral:

Represents a message literal.

Attributes:

  • elements: List[MessageLiteralElement] The elements (fields and comments) of the message literal.

πŸ…² proto_schema_parser.ast.Option

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.

πŸ…² proto_schema_parser.ast.Message

class Message:

Represents a message in a .proto file.

Attributes:

  • name: str The name of the message.
  • elements: List[MessageElement] The elements of the message.

πŸ…² proto_schema_parser.ast.Field

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.

πŸ…² proto_schema_parser.ast.MapField

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.

πŸ…² proto_schema_parser.ast.Group

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.

πŸ…² proto_schema_parser.ast.OneOf

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.

πŸ…² proto_schema_parser.ast.ExtensionRange

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.

πŸ…² proto_schema_parser.ast.Reserved

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.

πŸ…² proto_schema_parser.ast.Enum

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.

πŸ…² proto_schema_parser.ast.EnumValue

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.

πŸ…² proto_schema_parser.ast.EnumReserved

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.

πŸ…² proto_schema_parser.ast.Extension

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.

πŸ…² proto_schema_parser.ast.Service

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.

πŸ…² proto_schema_parser.ast.Method

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.

πŸ…² proto_schema_parser.ast.MessageType

class MessageType:

Represents a message type in a message.

Attributes:

  • type: str The type of the message.
  • stream: bool = False Whether the message is a stream.

πŸ…² proto_schema_parser.ast.Identifier

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.

πŸ…Ό proto_schema_parser.generator

Classes

πŸ…² proto_schema_parser.generator.Generator

class Generator:

Generator class that takes an abstract syntax tree (AST) and

generates a protobuf schema string.

Functions:

πŸ…΅ proto_schema_parser.generator.Generator.generate

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:

  • str: The generated protobuf schema string.

πŸ…Ό proto_schema_parser.parser

Classes

πŸ…² proto_schema_parser.parser.Parser

class Parser:

Parser class that takes a string representing a protobuf schema and returns an

abstract syntax tree (AST).

Functions:

πŸ…΅ proto_schema_parser.parser.Parser.__init__

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.

πŸ…΅ proto_schema_parser.parser.Parser.parse

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.