Skip to content

Allow symbol identifiers in tactics #1920

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

Merged
merged 4 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


------------------------------------------------------------------------------
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ spec = do
metaTest 11 11 "MetaUseMethod"
metaTest 9 38 "MetaCataCollapse"
metaTest 7 16 "MetaCataCollapseUnary"
metaTest 4 28 "MetaUseSymbol"

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Data.Monoid

resolve :: Sum Int
resolve = _ <> _
4 changes: 4 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/MetaUseSymbol.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Data.Monoid

resolve :: Sum Int
resolve = [wingman| use (<>) |]