Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide context parsing in the mkMessage function #283

Closed
wants to merge 2 commits into from

Conversation

Oleksandr-Zhabenko
Copy link
Contributor

@Oleksandr-Zhabenko Oleksandr-Zhabenko commented Aug 15, 2024

Provided context parsing in the mkMessage function. Resolves issue #282: mkMessage should support context parsing

CI passed successfully. See the link below:
https://github.com/Oleksandr-Zhabenko/shakespeare/actions/runs/10403325875

@Oleksandr-Zhabenko Oleksandr-Zhabenko changed the title Introduced contexts parsing in the mkMessage function. Resolves issue #282: mkMessage should support context parsing Provided context parsing in the mkMessage function. Resolves issue #282: mkMessage should support context parsing Aug 15, 2024
@jezen jezen changed the title Provided context parsing in the mkMessage function. Resolves issue #282: mkMessage should support context parsing Provide context parsing in the mkMessage function Aug 15, 2024
Comment on lines 3 to 4
# Is taken from the https://github.com/yesodweb/yesod/blob/master/.github/workflows/tests.yml template

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment probably isn't necessary.

@@ -62,22 +63,22 @@ module Text.Shakespeare.I18N
) where

import Language.Haskell.TH.Syntax hiding (makeRelativeToProject)
import Control.Applicative ((<$>))
--import Control.Applicative ((<$>))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this import isn't necessary, it's better just to delete the line.

import Control.Arrow ((***))
import Data.Monoid (mempty, mappend)
--import Data.Monoid (mempty, mappend)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can delete this line also.


parseName = do
cxt' <- option [] parseContext
-- name' <- parseWord -- This one is no longer needed as a separate argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just keep the code that we need 🙂

Copy link
Contributor Author

@Oleksandr-Zhabenko Oleksandr-Zhabenko Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I will tidy up the source files.

Copy link
Member

@jezen jezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tidying up. Now we just need to demonstrate that this is not a breaking change, and that it produces correct code for the scenario documented in the associated issue (and we should squash before merging).

This reverts commit 4fcf511, reversing
changes made to 6ca155b.
Comment on lines -3 to -6
### 2.1.1

* Add support for `TypeApplications` inside Shakespeare quasiquotes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good reason why this changelog entry was removed? This looks like a mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Hackage the version 2.1.1 is the last one and is already deprecated.
https://hackage.haskell.org/package/shakespeare-2.1.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but it shouldn't be removed even if it's deprecated. The deprecated version should continue to exist in the version history.

@@ -255,13 +301,13 @@ conP name = ConP name []
conP = ConP
#endif

toCon :: String -> SDef -> Con
toCon :: String -> SDef -> Con
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not introduce trailing whitespace.

version: 2.1.1
version: 2.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this number to go up, not down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be changed to 2.1.2

Comment on lines -36 to -59
it "parseDeref parse single type applications" $ do
runParser parseDeref () "" "x @y" `shouldBe`
Right
(DerefBranch
(DerefIdent (Ident "x"))
(DerefType "y"))
it "parseDeref parse unit type applications" $ do
runParser parseDeref () "" "x @()" `shouldBe`
Right
(DerefBranch
(DerefIdent (Ident "x"))
(DerefType "()"))
it "parseDeref parse compound type applications" $ do
runParser parseDeref () "" "x @(Maybe String)" `shouldBe`
Right
(DerefBranch
(DerefIdent (Ident "x"))
(DerefType "Maybe String"))
it "parseDeref parse single @ as operator" $ do
runParser parseDeref () "" "x @ y" `shouldBe`
Right
(DerefBranch
(DerefBranch (DerefIdent (Ident "@")) (DerefIdent (Ident "x")))
(DerefIdent (Ident "y")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these tests removed?

Copy link
Contributor Author

@Oleksandr-Zhabenko Oleksandr-Zhabenko Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange. I have not edited the file. Should I add these lines into the BaseSpec.hs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a minor git accident then 🙂 You can just revert this change.

Comment on lines 176 to 177
cxt -- Here the parsed context should be added, otherwise []
(ConT ''RenderMessage `AppT` (if ' ' `elem` master' then let (ts, us) = break (== ' ') . filter (\x -> x /= '(' && x /= ')') $ master' in let us1 = filter (/= ' ') us in ParensT (ConT (mkName ts) `AppT` VarT (mkName us1)) else ConT $ mkName master') `AppT` ConT mname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a nicer way to format this? I would prefer to see lines limited to 80 columns.

[ FunD (mkName "renderMessage") $ c1 ++ c2 ++ [c3]
]
]

toClauses :: String -> String -> (Lang, [Def]) -> Q [Clause]
where (dt1, cxt0) = case (parse parseName "" dt) of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's improve the formatting of all the new parsing code here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mkMessage should support context parsing
3 participants