From 9d60069d0fba47c5e45709b87984dc3c536ce43e Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Mon, 14 Jun 2021 04:57:53 -0700 Subject: [PATCH 1/3] Allow symbol identifiers in tactics --- .../src/Wingman/Metaprogramming/Lexer.hs | 38 ++++++++++++++++--- .../test/CodeAction/RunMetaprogramSpec.hs | 1 + .../test/golden/MetaUseSymbol.expected.hs | 4 ++ .../test/golden/MetaUseSymbol.hs | 4 ++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.expected.hs create mode 100644 plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.hs diff --git a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs index e4d62ca085..de3ba30ef8 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs @@ -18,6 +18,7 @@ import qualified Text.Megaparsec as P import qualified Text.Megaparsec.Char as P import qualified Text.Megaparsec.Char.Lexer as L import Wingman.Types (Context) +import Data.Foldable (asum) ------------------------------------------------------------------------------ @@ -45,6 +46,29 @@ sc = L.space P.space1 lineComment blockComment ichar :: Parser Char ichar = P.alphaNumChar <|> P.char '_' <|> P.char '\'' +symchar :: Parser Char +symchar = asum + [ P.symbolChar + , P.char '!' + , P.char '#' + , P.char '$' + , P.char '%' + , P.char '^' + , P.char '&' + , P.char '*' + , P.char '-' + , P.char '=' + , P.char '+' + , P.char ':' + , P.char '<' + , P.char '>' + , P.char ',' + , P.char '.' + , P.char '/' + , P.char '?' + , P.char '~' + ] + lexeme :: Parser a -> Parser a lexeme = L.lexeme sc @@ -66,14 +90,18 @@ parens = P.between (symbol "(") (symbol ")") identifier :: Text -> Parser () identifier i = lexeme (P.string i *> P.notFollowedBy ichar) --- FIXME [Reed M. 2020-10-18] Check to see if the variables are in the reserved list variable :: Parser OccName variable = lexeme $ do - c <- P.alphaNumChar - cs <- P.many ichar - pure $ mkVarOcc (c:cs) + c <- P.alphaNumChar <|> P.char '(' + fmap mkVarOcc $ case c of + '(' -> do + cs <- P.many symchar + void $ P.char ')' + pure cs + _ -> do + cs <- P.many ichar + pure $ c : cs --- FIXME [Reed M. 2020-10-18] Check to see if the variables are in the reserved list name :: Parser Text name = lexeme $ do c <- P.alphaNumChar diff --git a/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs index a54cd44999..e87ed0560d 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs @@ -33,4 +33,5 @@ spec = do metaTest 11 11 "MetaUseMethod" metaTest 9 38 "MetaCataCollapse" metaTest 7 16 "MetaCataCollapseUnary" + metaTest 4 28 "MetaUseSymbol" diff --git a/plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.expected.hs b/plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.expected.hs new file mode 100644 index 0000000000..20db691ef6 --- /dev/null +++ b/plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.expected.hs @@ -0,0 +1,4 @@ +import Data.Monoid + +resolve :: Sum Int +resolve = _ <> _ diff --git a/plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.hs b/plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.hs new file mode 100644 index 0000000000..4afe5f572d --- /dev/null +++ b/plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.hs @@ -0,0 +1,4 @@ +import Data.Monoid + +resolve :: Sum Int +resolve = [wingman| use (<>) |] From dd2df292a5df90afc1acc52c143d9cb697f9d9aa Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Mon, 14 Jun 2021 04:58:48 -0700 Subject: [PATCH 2/3] Cleanup imports --- .../hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs index de3ba30ef8..84a6a106cb 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs @@ -8,6 +8,7 @@ module Wingman.Metaprogramming.Lexer where import Control.Applicative import Control.Monad import Control.Monad.Reader (ReaderT) +import Data.Foldable (asum) import Data.Text (Text) import qualified Data.Text as T import Data.Void @@ -17,8 +18,7 @@ import Name import qualified Text.Megaparsec as P import qualified Text.Megaparsec.Char as P import qualified Text.Megaparsec.Char.Lexer as L -import Wingman.Types (Context) -import Data.Foldable (asum) +import Wingman.Types (Context) ------------------------------------------------------------------------------ From a19d48709319f6cc1447df032fa8f0b6cf0bcceb Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Mon, 14 Jun 2021 10:24:52 -0700 Subject: [PATCH 3/3] Also allow pipes and backslash --- plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs index 84a6a106cb..3c911b7dcb 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs @@ -67,6 +67,8 @@ symchar = asum , P.char '/' , P.char '?' , P.char '~' + , P.char '|' + , P.char '\\' ] lexeme :: Parser a -> Parser a