Skip to content

Commit c8bc599

Browse files
committed
Merged in main branch
2 parents 387cc05 + 9252598 commit c8bc599

File tree

23 files changed

+1874
-1106
lines changed

23 files changed

+1874
-1106
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ nix profile install nixpkgs#direnv
102102
nix profile install nixpkgs#nix-direnv
103103
```
104104

105-
Your shell and editors should pick up on the `.envrc` files in different directories and prepare the environment accordingly.
106-
Use `direnv allow` to enable the direnv environment and `direnv reload` to reload it when necessary.
105+
Your shell and editors should pick up on the `.envrc` files in different
106+
directories and prepare the environment accordingly.
107+
Use `direnv allow` to enable the direnv environment and `direnv reload` to
108+
reload it when necessary.
107109

108110
Additionally, throughout the repository one can use:
109111

lambda-buffers-compiler/app/LambdaBuffers/Compiler/Cli/Compile.hs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
module LambdaBuffers.Compiler.Cli.Compile (CompileOpts (..), compile) where
22

3-
import Control.Lens (makeLenses)
3+
import Control.Lens (makeLenses, (&), (.~))
44
import Control.Lens.Getter ((^.))
55
import Data.ByteString qualified as BS
6+
import Data.ProtoLens (Message (defMessage))
67
import Data.ProtoLens qualified as Pb
78
import Data.ProtoLens.TextFormat qualified as PbText
89
import Data.Text.Lazy qualified as Text
910
import Data.Text.Lazy.IO qualified as Text
10-
import LambdaBuffers.Compiler.KindCheck (check)
11-
import LambdaBuffers.Compiler.ProtoCompat (
12-
FromProtoErr (NamingError, ProtoError),
13-
IsMessage (fromProto, toProto),
14-
)
15-
import LambdaBuffers.Compiler.ProtoCompat.Types qualified as ProtoCompat
16-
import Proto.Compiler as ProtoLib (CompilerInput, CompilerOutput)
11+
import LambdaBuffers.Compiler (runCompiler)
12+
import Proto.Compiler (CompilerError, CompilerInput, CompilerOutput)
13+
import Proto.Compiler_Fields (compilerError, compilerResult)
1714
import System.FilePath.Lens (extension)
1815

1916
data CompileOpts = CompileOpts
@@ -24,20 +21,19 @@ data CompileOpts = CompileOpts
2421

2522
makeLenses ''CompileOpts
2623

27-
-- NOTE(cstml) - let's use Katip instead of print.
24+
-- NOTE(cstml): Let's use Katip instead of print.
2825

2926
-- | Compile LambdaBuffers modules
3027
compile :: CompileOpts -> IO ()
3128
compile opts = do
32-
compIn <- readCompilerInput (opts ^. input)
33-
case fromProto @CompilerInput @ProtoCompat.CompilerInput compIn of
34-
Left err -> case err of
35-
NamingError ne -> print $ "Encountered a naming error " <> show ne
36-
ProtoError pe -> print $ "Encountered a proto error " <> show pe
37-
Right compIn' -> do
38-
print @String "Successfully processed the CompilerInput"
39-
let result = check compIn'
40-
writeCompilerOutput (opts ^. output) (toProto result)
29+
compInp <- readCompilerInput (opts ^. input)
30+
case runCompiler compInp of
31+
Left compErr -> do
32+
putStrLn "Encountered errors during Compilation"
33+
writeCompilerError (opts ^. output) compErr
34+
Right compRes -> do
35+
putStrLn "Compilation succeeded"
36+
writeCompilerOutput (opts ^. output) (defMessage & compilerResult .~ compRes)
4137
return ()
4238

4339
readCompilerInput :: FilePath -> IO CompilerInput
@@ -52,7 +48,10 @@ readCompilerInput fp = do
5248
return $ PbText.readMessageOrDie content
5349
_ -> error $ "Unknown CompilerInput format " <> ext
5450

55-
writeCompilerOutput :: FilePath -> ProtoLib.CompilerOutput -> IO ()
51+
writeCompilerError :: FilePath -> CompilerError -> IO ()
52+
writeCompilerError fp err = writeCompilerOutput fp (defMessage & compilerError .~ err)
53+
54+
writeCompilerOutput :: FilePath -> CompilerOutput -> IO ()
5655
writeCompilerOutput fp cr = do
5756
let ext = fp ^. extension
5857
case ext of

lambda-buffers-compiler/lambda-buffers-compiler.cabal

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ library
107107
, text >=1.2
108108

109109
exposed-modules:
110+
LambdaBuffers.Compiler
110111
LambdaBuffers.Compiler.KindCheck
111112
LambdaBuffers.Compiler.KindCheck.Context
112113
LambdaBuffers.Compiler.KindCheck.Derivation
@@ -117,8 +118,8 @@ library
117118
LambdaBuffers.Compiler.KindCheck.Variable
118119
LambdaBuffers.Compiler.NamingCheck
119120
LambdaBuffers.Compiler.ProtoCompat
121+
LambdaBuffers.Compiler.ProtoCompat.FromProto
120122
LambdaBuffers.Compiler.ProtoCompat.Types
121-
LambdaBuffers.Compiler.TypeClass.Compat
122123
LambdaBuffers.Compiler.TypeClass.Pat
123124
LambdaBuffers.Compiler.TypeClass.Pretty
124125
LambdaBuffers.Compiler.TypeClass.Rules
@@ -129,7 +130,7 @@ library
129130

130131
hs-source-dirs: src
131132

132-
-- note(cstml): should we name this something shorter? lb-cli?
133+
-- NOTE(cstml): should we name this something shorter? lb-cli?
133134
executable lambda-buffers-compiler-cli
134135
import: common-language
135136
import: common-imports
@@ -156,7 +157,7 @@ test-suite tests
156157
, generic-lens
157158
, lambda-buffers-compiler
158159
, lambda-buffers-compiler-pb >=0.1
159-
, lens
160+
, mtl >=2.2
160161
, proto-lens >=0.7
161162
, QuickCheck >=2.14
162163
, tasty >=1.4
@@ -167,9 +168,10 @@ test-suite tests
167168
other-modules:
168169
Test.DeriveCheck
169170
Test.KindCheck
171+
Test.LambdaBuffers.Compiler
172+
Test.LambdaBuffers.Compiler.Gen
170173
Test.TypeClassCheck
171174
Test.Utils.CompilerInput
172175
Test.Utils.Constructors
173176
Test.Utils.Module
174-
Test.Utils.SourceInfo
175177
Test.Utils.TyDef
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module LambdaBuffers.Compiler (runCompiler) where
2+
3+
import Data.ProtoLens (Message (defMessage))
4+
import LambdaBuffers.Compiler.KindCheck (check_)
5+
import LambdaBuffers.Compiler.ProtoCompat.FromProto (
6+
runFromProto,
7+
toProto,
8+
)
9+
import Proto.Compiler (CompilerError, CompilerInput, CompilerResult)
10+
11+
runCompiler :: CompilerInput -> Either CompilerError CompilerResult
12+
runCompiler compInp = do
13+
compInp' <- runFromProto compInp
14+
case check_ compInp' of
15+
Left err -> Left $ toProto err
16+
Right _ -> Right defMessage

0 commit comments

Comments
 (0)