diff --git a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs index e4d62ca085..3c911b7dcb 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,7 +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 Wingman.Types (Context) ------------------------------------------------------------------------------ @@ -45,6 +46,31 @@ 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 '~' + , P.char '|' + , P.char '\\' + ] + lexeme :: Parser a -> Parser a lexeme = L.lexeme sc @@ -66,14 +92,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 (<>) |]