Skip to content

Commit

Permalink
Handle record dot syntax in DAML REPL (digital-asset#6028)
Browse files Browse the repository at this point in the history
* REPL record dot syntax regression test

* REPL: Apply record preprocessor to expressions

CHANGELOG_BEGIN
- [DAML REPL] Record dot syntax is now handled in expressions entered
  into the REPL.
CHANGELOG_END

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
  • Loading branch information
aherrmann-da and aherrmann authored May 19, 2020
1 parent 1b52082 commit 2666c73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/damlc/daml-compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ da_haskell_library(
"text",
"time",
"transformers",
"uniplate",
"unordered-containers",
"utf8-string",
"zip",
Expand Down
6 changes: 5 additions & 1 deletion compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import DA.Daml.LF.Reader (readDalfs, Dalfs(..))
import qualified DA.Daml.LF.ReplClient as ReplClient
import DA.Daml.LFConversion.UtilGHC
import DA.Daml.Options.Types
import qualified DA.Daml.Preprocessor.Records as Preprocessor
import Data.Bifunctor (first)
import qualified Data.ByteString.Lazy as BSL
import Data.Functor.Alt
import Data.Foldable
import Data.Generics.Uniplate.Data (descendBi)
import Data.Graph
import Data.Maybe
import qualified Data.NameMap as NM
Expand Down Expand Up @@ -172,8 +174,10 @@ parseReplInput input dflags =
-- The most common input will be statements. So, we attempt parsing
-- statements last to always emit statement parse errors on failure.
(ReplImport . unLoc <$> tryParse (parseImport input dflags))
<!> (ReplStatement . unLoc <$> tryParse (parseStatement input dflags))
<!> (ReplStatement . preprocess . unLoc <$> tryParse (parseStatement input dflags))
where
preprocess :: Stmt GhcPs (LHsExpr GhcPs) -> Stmt GhcPs (LHsExpr GhcPs)
preprocess = descendBi Preprocessor.onExp
tryParse :: ParseResult a -> Either Error a
tryParse (POk _ result) = Right result
tryParse (PFailed _ _ errMsg) = Left (ParseError errMsg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module DA.Daml.Preprocessor.Records
( importGenerated
, mkImport
, recordDotPreprocessor
, onExp
) where


Expand Down
9 changes: 9 additions & 0 deletions compiler/damlc/tests/src/DA/Test/Repl/FuncTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ functionalTests replClient serviceOut testDar options ideState = describe "repl
[ input "abort \"foobar\""
, matchServiceOutput "^Error: User abort: foobar$"
]
, testInteraction' "record dot syntax"
[ input "alice <- allocatePartyWithHint \"Alice\" (PartyIdHint \"alice\")"
, input "bob <- allocatePartyWithHint \"Bob\" (PartyIdHint \"bob\")"
, input "proposal <- pure (T alice bob)"
, input "debug proposal.proposer"
, matchServiceOutput "'alice'"
, input "debug proposal.accepter"
, matchServiceOutput "'bob'"
]
]
where
testInteraction' testName steps =
Expand Down

0 comments on commit 2666c73

Please sign in to comment.