protobuf-simple 0.1.0.4 → 0.1.0.5
raw patch · 7 files changed
+76/−32 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- protobuf-simple.cabal +1/−1
- src/Data/ProtoBuf/WireFormat.hs +1/−1
- src/Parser/CaseUtils.hs +17/−7
- src/Parser/Generator.hs +2/−2
- src/Parser/MessageGenerator.hs +1/−1
- src/Parser/ProtoParser.hs +41/−19
- test/Parser/ProtoParserSpec.hs +13/−1
protobuf-simple.cabal view
@@ -3,7 +3,7 @@ name: protobuf-simple synopsis: Simple Protocol Buffers library (proto2)-version: 0.1.0.4+version: 0.1.0.5 homepage: https://github.com/sru-systems/protobuf-simple license: MIT license-file: LICENSE
src/Data/ProtoBuf/WireFormat.hs view
@@ -308,7 +308,7 @@ tag <- getWireTag msg' <- fieldToValue tag msg loop msg' reqs- loop msg reqs | otherwise = do+ loop msg reqs = do done <- isEmpty if done then fail "Missing required field(s)"
src/Parser/CaseUtils.hs view
@@ -6,17 +6,18 @@ -- -- Utility functions for converting string cases. -module Parser.CaseUtils- ( fromSnake- , toCamel- , toPascal- ) where+module Parser.CaseUtils where import Data.Char (toLower, toUpper)+import Data.List (intercalate) import Data.List.Split (splitOn) +fromDotted :: String -> [String]+fromDotted = splitOn "."++ fromSnake :: String -> [String] fromSnake = splitOn "_" @@ -26,14 +27,23 @@ toCamel [] = "" -toPascal :: [String] -> String-toPascal = concatMap toPascalWord+toDotted :: [String] -> String+toDotted = intercalate "." toLowerWord :: String -> String toLowerWord = map toLower +toPascal :: [String] -> String+toPascal = concatMap toPascalWord++ toPascalWord :: String -> String toPascalWord (c:cs) = toUpper c : map toLower cs toPascalWord [] = ""+++toTitleWord :: String -> String+toTitleWord (c:cs) = toUpper c : cs+toTitleWord [] = ""
src/Parser/Generator.hs view
@@ -133,9 +133,9 @@ getFullEnumName :: FileDesc -> EnumDesc -> String-getFullEnumName fd ed = (getNamespace fd) ++ "." ++ (EnumDesc.getName ed)+getFullEnumName fd ed = getNamespace fd ++ "." ++ EnumDesc.getName ed getFullMessageName :: FileDesc -> MessageDesc -> String-getFullMessageName fd md = (getNamespace fd) ++ "." ++ (MessageDesc.getName md)+getFullMessageName fd md = getNamespace fd ++ "." ++ MessageDesc.getName md
src/Parser/MessageGenerator.hs view
@@ -69,7 +69,7 @@ getImports :: FileDesc -> MessageDesc -> State GenState Builder getImports f md = return $- (if MessageDesc.getFields md == []+ (if null (MessageDesc.getFields md) then fromString "" else getUnqualifiedImport "Control.Applicative" "(<$>)") <> getUnqualifiedImport "Prelude" "" <>
src/Parser/ProtoParser.hs view
@@ -12,8 +12,8 @@ import Control.Monad (void)+import Data.Functor (($>)) import Data.Int (Int32)-import Parser.CaseUtils (fromSnake, toCamel, toPascal) import Parser.EnumDesc (EnumDesc) import Parser.FieldDesc (FieldDesc) import Parser.FileDesc (FileDesc)@@ -23,6 +23,7 @@ import System.FilePath (dropExtensions, splitFileName) import Text.Parsec +import qualified Parser.CaseUtils as CU import qualified Parser.EnumDesc as EnumDesc import qualified Parser.EnumValueDesc as EnumValueDesc import qualified Parser.FieldDesc as FieldDesc@@ -46,17 +47,39 @@ -- FileDesc functions file :: FileDesc -> Parsec String u FileDesc file s = (eof >> return s) <|> (choice- [ package s+ [ comments s+ , syntax s+ , package s , fileOption s , enumDesc s , messageDesc s ] >>= file) +comments :: FileDesc -> Parsec String u FileDesc+comments s = do+ void $ choice+ [ string "//" *> manyTill anyChar (void eol <|> eof)+ , many1 (oneOf " \t\n\r")+ ]+ return s+++syntax :: FileDesc -> Parsec String u FileDesc+syntax s = do+ void $ keyword "syntax"+ void $ symbol '='+ void $ char '"'+ void $ string "proto2"+ void $ char '"'+ void $ symbol ';'+ return s++ package :: FileDesc -> Parsec String u FileDesc package s = do void $ keyword "package"- val <- dString+ val <- (CU.toDotted . fmap CU.toTitleWord . CU.fromDotted) <$> dString void $ symbol ';' return $ FileDesc.setPackage val s @@ -129,9 +152,9 @@ optimizeMode :: Parsec String u OptimizeMode optimizeMode = choice- [ string "SPEED" *> return OptimizeMode.Speed- , string "CODE_SIZE" *> return OptimizeMode.CodeSize- , string "LITE_RUNTIME" *> return OptimizeMode.LiteRuntime+ [ string "SPEED" $> OptimizeMode.Speed+ , string "CODE_SIZE" $> OptimizeMode.CodeSize+ , string "LITE_RUNTIME" $> OptimizeMode.LiteRuntime ] @@ -291,7 +314,7 @@ enumValueName :: Parsec String u String-enumValueName = fmap (toPascal . fromSnake) identifier+enumValueName = fmap (CU.toPascal . CU.fromSnake) identifier enumValueNumber :: Parsec String u Int32@@ -313,9 +336,9 @@ fieldLabel :: Parsec String u Label fieldLabel = choice- [ try $ keyword "optional" *> return Label.Optional- , try $ keyword "required" *> return Label.Required- , try $ keyword "repeated" *> return Label.Repeated+ [ try $ keyword "optional" $> Label.Optional+ , try $ keyword "required" $> Label.Required+ , try $ keyword "repeated" $> Label.Repeated ] @@ -324,7 +347,7 @@ fieldName :: Parsec String u String-fieldName = fmap (toCamel . fromSnake) identifier+fieldName = fmap (CU.toCamel . CU.fromSnake) identifier fieldNumber :: Parsec String u Int32@@ -375,19 +398,18 @@ getFieldOption name parser = do void $ keyword name void $ symbol '='- val <- parser- return val+ parser -- General functions bool :: Parsec String u Bool bool = choice- [try (keyword "FALSE") *> return False- ,keyword "False" *> return False- ,keyword "false" *> return False- ,try (keyword "TRUE") *> return True- ,keyword "True" *> return True- ,keyword "true" *> return True+ [try (keyword "FALSE") $> False+ ,keyword "False" $> False+ ,keyword "false" $> False+ ,try (keyword "TRUE") $> True+ ,keyword "True" $> True+ ,keyword "true" $> True ]
test/Parser/ProtoParserSpec.hs view
@@ -32,8 +32,20 @@ FileDesc.new "Test" + it "parses leading comments" $+ parseProto "Test.proto" "// Comment test"+ `shouldParse`+ FileDesc.new "Test"+++ it "parses syntax statement" $+ parseProto "Test.proto" "syntax = \"proto2\";"+ `shouldParse`+ FileDesc.new "Test"++ it "parses package name" $- parseProto "Test.proto" "package Google.ProtoBuf;"+ parseProto "Test.proto" "package google.protoBuf;" `shouldParse` FileDesc.setPackage "Google.ProtoBuf" (FileDesc.new "Test")