Skip to content

Commit 8f5558a

Browse files
Allow symbol identifiers in tactics (#1920)
* Allow symbol identifiers in tactics * Cleanup imports * Also allow pipes and backslash Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 8a10c50 commit 8f5558a

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Wingman.Metaprogramming.Lexer where
88
import Control.Applicative
99
import Control.Monad
1010
import Control.Monad.Reader (ReaderT)
11+
import Data.Foldable (asum)
1112
import Data.Text (Text)
1213
import qualified Data.Text as T
1314
import Data.Void
@@ -17,7 +18,7 @@ import Name
1718
import qualified Text.Megaparsec as P
1819
import qualified Text.Megaparsec.Char as P
1920
import qualified Text.Megaparsec.Char.Lexer as L
20-
import Wingman.Types (Context)
21+
import Wingman.Types (Context)
2122

2223

2324
------------------------------------------------------------------------------
@@ -45,6 +46,31 @@ sc = L.space P.space1 lineComment blockComment
4546
ichar :: Parser Char
4647
ichar = P.alphaNumChar <|> P.char '_' <|> P.char '\''
4748

49+
symchar :: Parser Char
50+
symchar = asum
51+
[ P.symbolChar
52+
, P.char '!'
53+
, P.char '#'
54+
, P.char '$'
55+
, P.char '%'
56+
, P.char '^'
57+
, P.char '&'
58+
, P.char '*'
59+
, P.char '-'
60+
, P.char '='
61+
, P.char '+'
62+
, P.char ':'
63+
, P.char '<'
64+
, P.char '>'
65+
, P.char ','
66+
, P.char '.'
67+
, P.char '/'
68+
, P.char '?'
69+
, P.char '~'
70+
, P.char '|'
71+
, P.char '\\'
72+
]
73+
4874
lexeme :: Parser a -> Parser a
4975
lexeme = L.lexeme sc
5076

@@ -66,14 +92,18 @@ parens = P.between (symbol "(") (symbol ")")
6692
identifier :: Text -> Parser ()
6793
identifier i = lexeme (P.string i *> P.notFollowedBy ichar)
6894

69-
-- FIXME [Reed M. 2020-10-18] Check to see if the variables are in the reserved list
7095
variable :: Parser OccName
7196
variable = lexeme $ do
72-
c <- P.alphaNumChar
73-
cs <- P.many ichar
74-
pure $ mkVarOcc (c:cs)
97+
c <- P.alphaNumChar <|> P.char '('
98+
fmap mkVarOcc $ case c of
99+
'(' -> do
100+
cs <- P.many symchar
101+
void $ P.char ')'
102+
pure cs
103+
_ -> do
104+
cs <- P.many ichar
105+
pure $ c : cs
75106

76-
-- FIXME [Reed M. 2020-10-18] Check to see if the variables are in the reserved list
77107
name :: Parser Text
78108
name = lexeme $ do
79109
c <- P.alphaNumChar

plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ spec = do
3333
metaTest 11 11 "MetaUseMethod"
3434
metaTest 9 38 "MetaCataCollapse"
3535
metaTest 7 16 "MetaCataCollapseUnary"
36+
metaTest 4 28 "MetaUseSymbol"
3637

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Data.Monoid
2+
3+
resolve :: Sum Int
4+
resolve = _ <> _
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Data.Monoid
2+
3+
resolve :: Sum Int
4+
resolve = [wingman| use (<>) |]

0 commit comments

Comments
 (0)