Skip to content

Commit

Permalink
Merge pull request #13 from f-o-a-m/decode-remapping
Browse files Browse the repository at this point in the history
Add DecodeJson instance for Remapping
  • Loading branch information
martyall authored Sep 27, 2023
2 parents a17d9ee + cb1fcd2 commit d7a2d53
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Language/Solidity/Compiler/Types/Settings.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ module Language.Solidity.Compiler.Types.Settings

import Prelude

import Control.Alternative ((<|>))
import Data.Argonaut (class DecodeJson, class EncodeJson, Json, decodeJson, encodeJson, fromString, jsonEmptyArray, jsonEmptyObject, jsonSingletonObject, (.!=), (.:), (.:!), (:=?), (~>?))
import Data.Argonaut as A
import Data.Argonaut.Decode.Error (JsonDecodeError(..), printJsonDecodeError)
import Data.Array (nub, null, uncons)
import Data.Bifunctor (lmap)
import Data.Either (Either(..), note)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.String (Pattern(..), joinWith, split)
import Data.String (Pattern(..), joinWith, split, stripPrefix)
import Data.Traversable (for, traverse)
import Data.Tuple (Tuple(..))
import Foreign.Object as FO
Expand All @@ -55,6 +56,20 @@ instance encodeJsonRemapping :: EncodeJson Remapping where
GlobalRemapping g -> ":g=" <> g.to
Remapping r -> r.from <> "=" <> r.to

instance DecodeJson Remapping where
decodeJson json = do
str <- decodeJson json
global str <|> remap str
where
global str = do
case stripPrefix (Pattern ":g=") str of
Nothing -> Left $ Named "GlobalRemapping" $ UnexpectedValue json
Just to -> pure $ GlobalRemapping { to }
remap str = do
case split (Pattern "=") str of
[ from, to ] -> pure $ Remapping { from, to }
_ -> Left $ Named "Remapping" $ UnexpectedValue json

--------------------------------------------------
--- "settings.optimizer.yulDetails"

Expand Down

0 comments on commit d7a2d53

Please sign in to comment.