bond 0.11.0.3 → 0.12.0.1
raw patch · 7 files changed
+243/−175 lines, 7 filesdep +quickcheck-arbitrary-templatedep −derivedep ~Diffdep ~aesondep ~aeson-pretty
Dependencies added: quickcheck-arbitrary-template
Dependencies removed: derive
Dependency ranges changed: Diff, aeson, aeson-pretty, async, base, bytestring, cmdargs, directory, filepath, megaparsec, monad-loops, mtl, process, scientific, shakespeare, text, unordered-containers
Files
- IO.hs +7/−9
- bond.cabal +152/−138
- src/Language/Bond/Codegen/Cs/Grpc_cs.hs +4/−0
- src/Language/Bond/Codegen/CustomMapping.hs +3/−3
- src/Language/Bond/Parser.hs +9/−4
- tests/Tests/Syntax.hs +66/−19
- tests/Tests/Syntax/JSON.hs +2/−2
IO.hs view
@@ -16,7 +16,6 @@ import Data.Aeson (eitherDecode) import Data.Void (Void) import qualified Data.ByteString.Lazy as BL -import qualified Data.List.NonEmpty as NE import qualified Data.Text as T import Language.Bond.Codegen.TypeMapping import Language.Bond.Parser @@ -30,7 +29,6 @@ import Text.Megaparsec import Text.Printf - parseFile :: [FilePath] -> FilePath -> IO(Bond) parseFile importDirs file = if takeExtension file == ".json" then @@ -89,21 +87,21 @@ Left err -> fail $ show err Right m -> return m -msbuildErrorMessage :: (ParseError Char Void) -> String +msbuildErrorMessage :: (ParseErrorBundle String Void) -> String msbuildErrorMessage err = printf "%s(%d,%d) : error B0000: %s" name line col message where message = combinedMessage err - pos = errorPos err - name = sourceName (NE.head pos) - line = unPos $ sourceLine (NE.head pos) - col = unPos $ sourceColumn (NE.head pos) + pos = pstateSourcePos . bundlePosState $ err + name = sourceName pos + line = unPos $ sourceLine pos + col = unPos $ sourceColumn pos -combinedMessage :: (ParseError Char Void) -> String +combinedMessage :: (ParseErrorBundle String Void) -> String combinedMessage err = id $ T.unpack $ T.intercalate (T.pack ", ") messages where -- parseErrorPretty returns a multi-line String. -- We need to break it up to make a useful one-line message. - messages = T.splitOn (T.pack "\n") $ T.strip $ T.pack $ parseErrorTextPretty err + messages = T.splitOn (T.pack "\n") $ T.strip $ T.pack $ errorBundlePretty err -- | Normalizes a file path to only use the current platform's preferred -- directory separator.
bond.cabal view
@@ -1,153 +1,167 @@--- Copyright (c) Microsoft. All rights reserved. --- Licensed under the MIT license. See LICENSE file in the project root for full license information. +cabal-version: 1.12 -name: bond -version: 0.11.0.3 -cabal-version: >= 1.8 -tested-with: GHC>=8.0.1 -synopsis: Bond schema compiler and code generator -description: Bond is a cross-platform framework for handling schematized - data. It supports cross-language de/serialization and - powerful generic mechanisms for efficiently manipulating - data. - . - This package contains a library for parsing the Bond - schema definition language and performing template-based - code generation. The library includes built-in templates - for generating standard Bond C++ and C# code, as well as - utilities for writing custom codegen templates. - . - The package also contains a command-line compiler/codegen - tool, named gbc, which is primarily used to generate code - for C++ and C# programs using Bond. +-- This file has been generated from package.yaml by hpack version 0.31.2. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: b913222488b7035eec255444fe3bf82606f82eb0940c6ae5a4a3af784638c527 -homepage: https://github.com/Microsoft/bond -license: MIT -license-file: LICENSE -author: Adam Sapek <adamsap@microsoft.com> -maintainer: Bond Development Team <bond-dev@microsoft.com> -bug-reports: https://github.com/Microsoft/bond/issues -copyright: Copyright (c) Microsoft. All rights reserved. -category: Language, Compiler, Code Generation -build-type: Simple +name: bond +version: 0.12.0.1 +synopsis: Bond schema compiler and code generator +description: Bond is a cross-platform framework for handling schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. . This package contains a library for parsing the Bond schema definition language and performing template-based code generation. The library includes built-in templates for generating standard Bond C++ and C# code, as well as utilities for writing custom codegen templates. . The package also contains a command-line compiler/codegen tool, named gbc, which is primarily used to generate code for C++ and C# programs using Bond. +category: Language, Compiler, Code Generation +homepage: https://github.com/microsoft/bond#readme +bug-reports: https://github.com/microsoft/bond/issues +author: Adam Sapek <adamsap@microsoft.com> +maintainer: Bond Development Team <bond-dev@microsoft.com> +copyright: Copyright (c) Microsoft. All rights reserved. +license: MIT +license-file: LICENSE +build-type: Simple +source-repository head + type: git + location: https://github.com/microsoft/bond + flag warningsAsErrors - default: False + description: Treat warnings as errors for building bond manual: True - -source-repository head - type: git - location: git@github.com:Microsoft/bond.git + default: False library - hs-source-dirs: src - build-depends: aeson >= 0.7.0.6 && < 0.12.0.0, - base >= 4.9 && < 5, - bytestring >= 0.10, - filepath >= 1.0, - mtl >= 2.1, - megaparsec >= 6.2, - scientific >= 0.3.4.6, - shakespeare >= 2.0, - text >= 0.11, - unordered-containers >= 0.2.3.0 - if flag(warningsAsErrors) - ghc-options: -Wall -Werror - exposed-modules: Language.Bond.Parser - Language.Bond.Util - Language.Bond.Syntax.Types - Language.Bond.Syntax.JSON - Language.Bond.Syntax.Util - Language.Bond.Syntax.SchemaDef - Language.Bond.Codegen.Util - Language.Bond.Codegen.TypeMapping - Language.Bond.Codegen.Templates - other-modules: Language.Bond.Codegen.CustomMapping - Language.Bond.Codegen.Cpp.Apply_cpp - Language.Bond.Codegen.Cpp.Apply_h - Language.Bond.Codegen.Cpp.Enum_h - Language.Bond.Codegen.Cpp.Reflection_h - Language.Bond.Codegen.Cpp.Types_cpp - Language.Bond.Codegen.Cpp.Types_h - Language.Bond.Codegen.Cpp.Grpc_cpp - Language.Bond.Codegen.Cpp.Grpc_h - Language.Bond.Codegen.Cs.Types_cs - Language.Bond.Codegen.Cs.Grpc_cs - Language.Bond.Codegen.Cpp.ApplyOverloads - Language.Bond.Codegen.Cpp.Util - Language.Bond.Codegen.Cs.Util - Language.Bond.Codegen.Java.Class_java - Language.Bond.Codegen.Java.Enum_java - Language.Bond.Codegen.Java.Util - Language.Bond.Lexer - Language.Bond.Syntax.Internal - Paths_bond - -test-suite gbc-tests - type: exitcode-stdio-1.0 - hs-source-dirs: tests, . - main-is: TestMain.hs - other-modules: IO - Options - Tests.Codegen - Tests.Codegen.Util - Tests.Syntax - Tests.Syntax.JSON - - ghc-options: -threaded - if flag(warningsAsErrors) - ghc-options: -threaded -Wall -Werror - + exposed-modules: + Language.Bond.Codegen.Cpp.Apply_cpp + Language.Bond.Codegen.Cpp.Apply_h + Language.Bond.Codegen.Cpp.ApplyOverloads + Language.Bond.Codegen.Cpp.Enum_h + Language.Bond.Codegen.Cpp.Grpc_cpp + Language.Bond.Codegen.Cpp.Grpc_h + Language.Bond.Codegen.Cpp.Reflection_h + Language.Bond.Codegen.Cpp.Types_cpp + Language.Bond.Codegen.Cpp.Types_h + Language.Bond.Codegen.Cpp.Util + Language.Bond.Codegen.Cs.Grpc_cs + Language.Bond.Codegen.Cs.Types_cs + Language.Bond.Codegen.Cs.Util + Language.Bond.Codegen.CustomMapping + Language.Bond.Codegen.Java.Class_java + Language.Bond.Codegen.Java.Enum_java + Language.Bond.Codegen.Java.Util + Language.Bond.Codegen.Templates + Language.Bond.Codegen.TypeMapping + Language.Bond.Codegen.Util + Language.Bond.Lexer + Language.Bond.Parser + Language.Bond.Syntax.Internal + Language.Bond.Syntax.JSON + Language.Bond.Syntax.SchemaDef + Language.Bond.Syntax.Types + Language.Bond.Syntax.Util + Language.Bond.Util + other-modules: + Paths_bond + hs-source-dirs: + src + build-depends: + aeson + , base >=4.7 && <5 + , bytestring + , filepath + , megaparsec + , mtl + , scientific + , shakespeare + , text + , unordered-containers if os(windows) && arch(i386) - ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware + ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware if os(windows) && arch(x86_64) - ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va - - build-depends: bond, - aeson >= 0.7.0.6 && < 0.12.0.0, - aeson-pretty == 0.7.2, - base >= 4.9 && < 5, - bytestring >= 0.10, - cmdargs >= 0.10.10, - directory >= 1.1, - filepath >= 1.0, - monad-loops >= 0.4, - text >= 0.11, - derive < 2.6, - HUnit, - QuickCheck, - Diff >= 0.2 && < 0.4, - pretty, - tasty, - tasty-golden, - tasty-hunit, - tasty-quickcheck, - shakespeare >= 2.0, - megaparsec >= 6.2 + ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va + if flag(warningsAsErrors) + ghc-options: -Wall -Werror + default-language: Haskell2010 executable gbc - main-is: Main.hs - other-modules: IO - Options - - ghc-options: -threaded + main-is: Main.hs + other-modules: + IO + Options + Paths_bond + hs-source-dirs: + ./. + build-depends: + aeson + , async + , base + , bond + , bytestring + , cmdargs + , directory + , filepath + , megaparsec + , monad-loops + , mtl + , process + , scientific + , shakespeare + , text + , unordered-containers + if os(windows) && arch(i386) + ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware + if os(windows) && arch(x86_64) + ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va if flag(warningsAsErrors) - ghc-options: -threaded -Wall -Werror + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror + else + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 +test-suite gbc-tests + type: exitcode-stdio-1.0 + main-is: TestMain.hs + other-modules: + Tests.Codegen + Tests.Codegen.Util + Tests.Syntax + Tests.Syntax.JSON + Paths_bond + IO + Options + hs-source-dirs: + tests + ./. + build-depends: + Diff + , HUnit + , QuickCheck + , aeson + , aeson-pretty + , base + , bond + , bytestring + , cmdargs + , directory + , filepath + , megaparsec + , monad-loops + , mtl + , pretty + , quickcheck-arbitrary-template + , scientific + , shakespeare + , tasty + , tasty-golden + , tasty-hunit + , tasty-quickcheck + , text + , unordered-containers if os(windows) && arch(i386) - ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware + ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware if os(windows) && arch(x86_64) - ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va - - build-depends: bond, - aeson >= 0.7.0.6 && < 0.12.0.0, - async >= 2.0.1.0, - base >= 4.9 && < 5, - bytestring >= 0.10, - cmdargs >= 0.10.10, - process < 1.5, - directory >= 1.1, - filepath >= 1.0, - monad-loops >= 0.4, - text >= 0.11, - megaparsec >= 6.2 + ld-options: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va + if flag(warningsAsErrors) + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror + else + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010
src/Language/Bond/Codegen/Cs/Grpc_cs.hs view
@@ -77,6 +77,10 @@ { } + public #{declName}Client(global::Grpc.Core.CallInvoker callInvoker) : base(callInvoker) + { + } + protected #{declName}Client() : base() { }
src/Language/Bond/Codegen/CustomMapping.hs view
@@ -79,12 +79,12 @@ -- -- > > parseAliasMapping "Example.OrderedSet=SortedSet<{0}>" -- > Right (AliasMapping {aliasName = ["Example","OrderedSet"], aliasTemplate = [Fragment "SortedSet<",Placeholder 0,Fragment ">"]}) -parseAliasMapping :: String -> Either (ParseError Char Void) AliasMapping +parseAliasMapping :: String -> Either (ParseErrorBundle String Void) AliasMapping parseAliasMapping s = parse aliasMapping "" s where aliasMapping = AliasMapping <$> qualifiedName <* equal <*> some (placeholder <|> fragment) <* eof placeholder = Placeholder <$> fromIntegral <$> between (char '{') (char '}') integer - fragment = Fragment <$> some (notChar '{') + fragment = Fragment <$> some (anySingleBut '{') -- | Parse a namespace mapping specification used in command-line arguments of -- <https://microsoft.github.io/bond/manual/compiler.html#command-line-options gbc>. @@ -93,7 +93,7 @@ -- -- > > parseNamespaceMapping "bond=Microsoft.Bond" -- > Right (NamespaceMapping {fromNamespace = ["bond"], toNamespace = ["Microsoft","Bond"]}) -parseNamespaceMapping :: String -> Either (ParseError Char Void) NamespaceMapping +parseNamespaceMapping :: String -> Either (ParseErrorBundle String Void) NamespaceMapping parseNamespaceMapping s = parse namespaceMapping "" s where namespaceMapping = NamespaceMapping <$> qualifiedName <* equal <*> qualifiedName
src/Language/Bond/Parser.hs view
@@ -45,7 +45,7 @@ -> String -- ^ content of a schema file to parse -> FilePath -- ^ path of the file being parsed, used to resolve relative import paths -> ImportResolver -- ^ function to resolve and load imported files - -> IO (Either (ParseError Char Void) Bond) -- ^ function returns 'Bond' which represents the parsed abstract syntax tree + -> IO (Either (ParseErrorBundle String Void) Bond) -- ^ function returns 'Bond' which represents the parsed abstract syntax tree -- or 'ParserError' if parsing failed parseBond s c f r = runReaderT (runParserT (evalStateT bond (Symbols [] [])) s c) (Environment [] [] f r) @@ -63,10 +63,10 @@ import_ = do i <- Import <$ keyword "import" <*> unescapedStringLiteral <* optional semi <?> "import statement" src <- getInput - pos <- getPosition + pos <- getOffset processImport i setInput src - setPosition pos + setOffset pos return i processImport :: Import -> Parser() @@ -77,7 +77,7 @@ if path `elem` imports then return () else do modify (\u -> u { imports = path:imports } ) setInput content - setPosition $ initialPos path + setSourcePos $ initialPos path void $ local (\e -> e { currentFile = path }) bond -- parser for struct, enum or type alias declaration/definition @@ -469,3 +469,8 @@ -- The value of the second parameter is never used: only its type is used. isInBounds :: forall a. (Integral a, Bounded a) => Integer -> a -> Bool isInBounds value _ = value >= (toInteger (minBound :: a)) && value <= (toInteger (maxBound :: a)) + +-- sets source position +setSourcePos :: MonadParsec e s m => SourcePos -> m () +setSourcePos src = updateParserState setPos + where setPos (State s o (PosState i o' _ t l)) = State s o (PosState i o' src t l)
tests/Tests/Syntax.hs view
@@ -16,8 +16,8 @@ import Data.Maybe import Data.List import Data.Aeson (encode, decode) -import Data.Aeson.Encode.Pretty (Config(..), encodePretty') -import Data.DeriveTH +import Data.Aeson.Encode.Pretty (Config(..), NumberFormat(..), Indent(..), encodePretty') +import Test.QuickCheck.TH.Generators import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import System.FilePath @@ -30,21 +30,66 @@ import Language.Bond.Syntax.SchemaDef import IO -derive makeArbitrary ''Attribute -derive makeArbitrary ''Bond -derive makeArbitrary ''Constant -derive makeArbitrary ''Constraint -derive makeArbitrary ''Declaration -derive makeArbitrary ''Default -derive makeArbitrary ''Field -derive makeArbitrary ''Import -derive makeArbitrary ''Language -derive makeArbitrary ''Modifier -derive makeArbitrary ''Namespace -derive makeArbitrary ''Type -derive makeArbitrary ''TypeParam -derive makeArbitrary ''MethodType +makeArbitrary ''Attribute +makeArbitrary ''Constant +makeArbitrary ''Constraint +makeArbitrary ''Default +makeArbitrary ''Field +makeArbitrary ''Declaration +makeArbitrary ''Import +makeArbitrary ''Language +makeArbitrary ''Modifier +makeArbitrary ''Namespace +makeArbitrary ''Type +makeArbitrary ''TypeParam +makeArbitrary ''MethodType +makeArbitrary ''Bond + +instance Arbitrary Attribute where + arbitrary = arbitraryAttribute + +instance Arbitrary Field where + arbitrary = arbitraryField + +instance Arbitrary Constant where + arbitrary = arbitraryConstant + +instance Arbitrary Default where + arbitrary = arbitraryDefault + +instance Arbitrary Declaration where + arbitrary = arbitraryDeclaration + +instance Arbitrary Import where + arbitrary = arbitraryImport + +instance Arbitrary Constraint where + arbitrary = arbitraryConstraint + +instance Arbitrary Language where + arbitrary = arbitraryLanguage + +instance Arbitrary Modifier where + arbitrary = arbitraryModifier + + +instance Arbitrary Namespace where + arbitrary = arbitraryNamespace + +instance Arbitrary TypeParam where + arbitrary = arbitraryTypeParam + +instance Arbitrary Type where + arbitrary = arbitraryType + +instance Arbitrary MethodType where + arbitrary = arbitraryMethodType + +instance Arbitrary Bond where + arbitrary = arbitraryBond + + instance Arbitrary Method where arbitrary = oneof [ Function <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary @@ -125,15 +170,17 @@ (Bond _ _ declarations) <- parseBondFile [] $ "tests" </> "schema" </> baseName <.> "bond" let schema = fromJust $ find ((schemaName ==) . declName) declarations return $ - -- some versions aeson encode angle brackets BL.fromStrict $ + -- aeson-pretty-print prints anything above 1e19 in scientific notation + replace "1.8446744073709551615e19" "18446744073709551615" $ + -- some versions aeson encode angle brackets replace "\\u003c" "<" $ replace "\\u003e" ">" $ BL.toStrict $ prettyEncode $ makeSchemaDef $ BT_UserDefined schema [] where - prettyEncode = encodePretty' (Config indentSpaces compare) + prettyEncode = encodePretty' (Config indentSpaces compare Generic False) where - indentSpaces = 2 + indentSpaces = Spaces 2 replace s r bs = if B.null t then h else B.append h (B.append r $ replace s r (B.drop (B.length s) t)) where
tests/Tests/Syntax/JSON.hs view
@@ -8,7 +8,7 @@ ) where import Data.Aeson (FromJSON, ToJSON, eitherDecode) -import Data.Aeson.Encode.Pretty (Config(..), encodePretty') +import Data.Aeson.Encode.Pretty (Config(..),NumberFormat(..), Indent(..), encodePretty') import Data.ByteString.Lazy (ByteString) import Data.Maybe () import Data.Text.Lazy as LT @@ -96,7 +96,7 @@ -- | Helper method that JSON encodes to lazy text encodeText :: ToJSON a => a -> LT.Text encodeText o = decodeUtf8 (encodePretty' config o) - where config = (Config 2 compare) + where config = (Config (Spaces 2) compare Generic False) -- | Asserts that the given JSON decodes into the expected value assertJsonDecode :: (Eq a, FromJSON a, Show a) =>