1
1
mirror of https://github.com/github/semantic.git synced 2025-01-06 06:46:07 +03:00

Define an instance for QualifiedName

This commit is contained in:
joshvera 2018-07-23 13:59:45 -04:00
parent ba52c57700
commit 8296372c71

View File

@ -15,7 +15,7 @@ import Diffing.Algorithm
import GHC.Generics import GHC.Generics
import Prologue import Prologue
import System.FilePath.Posix import System.FilePath.Posix
import Proto3.Suite (Primitive(..), Message(..), Message1(..), Named1(..), Named(..), MessageField(..)) import Proto3.Suite (Primitive(..), Message(..), Message1(..), Named1(..), Named(..), MessageField(..), DotProtoIdentifier(..), DotProtoPrimType(..), DotProtoType(..), messageField)
import qualified Proto3.Wire.Encode as Encode import qualified Proto3.Wire.Encode as Encode
import qualified Proto3.Wire.Decode as Decode import qualified Proto3.Wire.Decode as Decode
@ -26,11 +26,13 @@ data QualifiedName
instance MessageField QualifiedName where instance MessageField QualifiedName where
encodeMessageField num QualifiedName{..} = Encode.embedded num (encodeMessageField 1 paths) encodeMessageField num QualifiedName{..} = Encode.embedded num (encodeMessageField 1 paths)
encodeMessageField num RelativeQualifiedName{..} = Encode.embedded num (encodeMessageField 1 path <> encodeMessageField 2 maybeQualifiedName) encodeMessageField num RelativeQualifiedName{..} = Encode.embedded num (encodeMessageField 1 path <> (encodeMessageField 2 maybeQualifiedName))
decodeMessageField = undefined -- qualifiedName <|> relativeName decodeMessageField = Decode.embedded'' (qualifiedName <|> relativeQualifiedName)
protoType = undefined where
-- embeddedAt num = Decode.at (Decode.embedded'' parser) num embeddedAt parser num = Decode.at parser num
-- qualifiedName = Decode.embedded'' (QualifiedName <$> embeddedAt 1 <*> embeddedAt 2) qualifiedName = QualifiedName <$> embeddedAt decodeMessageField 1
relativeQualifiedName = RelativeQualifiedName <$> embeddedAt decodeMessageField 1 <*> embeddedAt decodeMessageField 2
protoType _ = messageField (Prim $ Named (Single (nameOf (Proxy @QualifiedName)))) Nothing
qualifiedName :: NonEmpty Text -> QualifiedName qualifiedName :: NonEmpty Text -> QualifiedName
qualifiedName xs = QualifiedName (T.unpack <$> xs) qualifiedName xs = QualifiedName (T.unpack <$> xs)
@ -164,7 +166,7 @@ instance Named Prelude.String where nameOf _ = "string"
instance Message Prelude.String where instance Message Prelude.String where
encodeMessage _ x = encodePrimitive 1 x encodeMessage _ x = encodePrimitive 1 x
decodeMessage _ = undefined decodeMessage _ = Decode.at (Decode.one decodePrimitive mempty) 1
dotProto = undefined dotProto = undefined
instance Eq1 QualifiedImport where liftEq = genericLiftEq instance Eq1 QualifiedImport where liftEq = genericLiftEq