| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Proto3.Suite.DotProto.Generate
Description
This module provides functions to generate Haskell declarations for protobuf messages
Synopsis
- data CompileError
- = CircularImport FilePath
- | CompileParseError ParseError
- | InternalError String
- | InvalidPackageName DotProtoIdentifier
- | InvalidMethodName DotProtoIdentifier
- | InvalidModuleName String
- | InvalidTypeName String
- | InvalidMapKeyType String
- | NoPackageDeclaration
- | NoSuchType DotProtoIdentifier
- | NonzeroFirstEnumeration String DotProtoIdentifier Int32
- | EmptyEnumeration String
- | Unimplemented String
- | RedefinedFields (Histogram FieldName) (Histogram FieldNumber)
- data StringType = StringType String String
- parseStringType :: String -> Either String StringType
- type TypeContext = Map DotProtoIdentifier DotProtoTypeInfo
- data CompileArgs = CompileArgs {}
- compileDotProtoFile :: Logger -> CompileArgs -> IO (Either CompileError ())
- compileDotProtoFileOrDie :: Logger -> CompileArgs -> IO ()
- renameProtoFile :: MonadError CompileError m => String -> m String
- hsModuleForDotProto :: (MonadError CompileError m, ?stringType :: StringType, ?typeLevelFormat :: Bool) => ([HsImportDecl], [HsDecl]) -> DotProto -> TypeContext -> m (HsModule GhcPs)
- renderHsModuleForDotProto :: (MonadError CompileError m, ?stringType :: StringType, ?typeLevelFormat :: Bool) => ([HsImportDecl], [HsDecl]) -> DotProto -> TypeContext -> m String
- readDotProtoWithContext :: (MonadError CompileError m, MonadIO m) => [FilePath] -> FilePath -> m (DotProto, TypeContext)
Documentation
data CompileError Source #
Constructors
| CircularImport FilePath | |
| CompileParseError ParseError | |
| InternalError String | |
| InvalidPackageName DotProtoIdentifier | |
| InvalidMethodName DotProtoIdentifier | |
| InvalidModuleName String | |
| InvalidTypeName String | |
| InvalidMapKeyType String | |
| NoPackageDeclaration | |
| NoSuchType DotProtoIdentifier | |
| NonzeroFirstEnumeration String DotProtoIdentifier Int32 | |
| EmptyEnumeration String | |
| Unimplemented String | |
| RedefinedFields (Histogram FieldName) (Histogram FieldNumber) | At least one field/oneof name and or field number was used more than once within the same message definition, which violates the protobuf specification. The histograms mention only the repeated names and numbers, not the ones used only once. |
Instances
| Show CompileError Source # | |
Defined in Proto3.Suite.DotProto.Internal Methods showsPrec :: Int -> CompileError -> ShowS # show :: CompileError -> String # showList :: [CompileError] -> ShowS # | |
| Eq CompileError Source # | |
Defined in Proto3.Suite.DotProto.Internal | |
data StringType Source #
Constructors
| StringType String String | Qualified module name, then unqualified type name. |
type TypeContext = Map DotProtoIdentifier DotProtoTypeInfo Source #
A mapping from .proto type identifiers to their type information
data CompileArgs Source #
Constructors
| CompileArgs | |
Fields
| |
compileDotProtoFile :: Logger -> CompileArgs -> IO (Either CompileError ()) Source #
Generate a Haskell module corresponding to a .proto file
compileDotProtoFileOrDie :: Logger -> CompileArgs -> IO () Source #
Same as compileDotProtoFile, except terminates the program with an error
message on failure.
renameProtoFile :: MonadError CompileError m => String -> m String Source #
Renaming protobuf file names to valid Haskell module names.
By convention, protobuf filenames are snake case. rnProtoFile renames
snake-cased protobuf filenames by:
- Replacing occurrences of one or more underscores followed by an alphabetical character with one less underscore.
- Capitalizing the first character following the string of underscores.
Examples
>>>renameProtoFile @(Either CompileError) "abc_xyz"Right "AbcXyz"
>>>renameProtoFile @(Either CompileError) "abc_1bc"Left (InvalidModuleName "abc_1bc")
>>>renameProtoFile @(Either CompileError) "_"Left (InvalidModuleName "_")
Arguments
| :: (MonadError CompileError m, ?stringType :: StringType, ?typeLevelFormat :: Bool) | |
| => ([HsImportDecl], [HsDecl]) | Extra user-define instances that override default generated instances |
| -> DotProto | |
| -> TypeContext | |
| -> m (HsModule GhcPs) |
Compile a Haskell module AST given a DotProto package AST.
Instances given in eis override those otherwise generated.
renderHsModuleForDotProto :: (MonadError CompileError m, ?stringType :: StringType, ?typeLevelFormat :: Bool) => ([HsImportDecl], [HsDecl]) -> DotProto -> TypeContext -> m String Source #
readDotProtoWithContext :: (MonadError CompileError m, MonadIO m) => [FilePath] -> FilePath -> m (DotProto, TypeContext) Source #
Parses the file at the given path and produces an AST along with a
TypeContext representing all types from imported .proto files, using the
first parameter as a list of paths to search for imported files. Terminates
with exit code 1 when an included file cannot be found in the search path.