Commit dc2f65f6 authored by pcapriotti's avatar pcapriotti
Browse files

Support qualified identifiers in quasi-quotes (#5555).

parent 50e5a06b
...@@ -321,6 +321,10 @@ $tab+ { warn Opt_WarnTabs (text "Tab character") } ...@@ -321,6 +321,10 @@ $tab+ { warn Opt_WarnTabs (text "Tab character") }
"[" @varid "|" / { ifExtension qqEnabled } "[" @varid "|" / { ifExtension qqEnabled }
{ lex_quasiquote_tok } { lex_quasiquote_tok }
-- qualified quasi-quote (#5555)
"[" @qual @varid "|" / { ifExtension qqEnabled }
{ lex_qquasiquote_tok }
} }
<0> { <0> {
...@@ -562,7 +566,14 @@ data Token ...@@ -562,7 +566,14 @@ data Token
| ITidEscape FastString -- $x | ITidEscape FastString -- $x
| ITparenEscape -- $( | ITparenEscape -- $(
| ITtyQuote -- '' | ITtyQuote -- ''
| ITquasiQuote (FastString,FastString,RealSrcSpan) -- [:...|...|] | ITquasiQuote (FastString,FastString,RealSrcSpan)
-- ITquasiQuote(quoter, quote, loc)
-- represents a quasi-quote of the form
-- [quoter| quote |]
| ITqQuasiQuote (FastString,FastString,FastString,RealSrcSpan)
-- ITqQuasiQuote(Qual, quoter, quote, loc)
-- represents a qualified quasi-quote of the form
-- [Qual.quoter| quote |]
-- Arrow notation extension -- Arrow notation extension
| ITproc | ITproc
...@@ -1423,6 +1434,18 @@ getCharOrFail i = do ...@@ -1423,6 +1434,18 @@ getCharOrFail i = do
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- QuasiQuote -- QuasiQuote
lex_qquasiquote_tok :: Action
lex_qquasiquote_tok span buf len = do
let (qual, quoter) = splitQualName (stepOn buf) (len - 2) False
quoteStart <- getSrcLoc
quote <- lex_quasiquote quoteStart ""
end <- getSrcLoc
return (L (mkRealSrcSpan (realSrcSpanStart span) end)
(ITqQuasiQuote (qual,
quoter,
mkFastString (reverse quote),
mkRealSrcSpan quoteStart end)))
lex_quasiquote_tok :: Action lex_quasiquote_tok :: Action
lex_quasiquote_tok span buf len = do lex_quasiquote_tok span buf len = do
let quoter = tail (lexemeToString buf (len - 1)) let quoter = tail (lexemeToString buf (len - 1))
......
...@@ -350,6 +350,7 @@ TH_ID_SPLICE { L _ (ITidEscape _) } -- $x ...@@ -350,6 +350,7 @@ TH_ID_SPLICE { L _ (ITidEscape _) } -- $x
'$(' { L _ ITparenEscape } -- $( exp ) '$(' { L _ ITparenEscape } -- $( exp )
TH_TY_QUOTE { L _ ITtyQuote } -- ''T TH_TY_QUOTE { L _ ITtyQuote } -- ''T
TH_QUASIQUOTE { L _ (ITquasiQuote _) } TH_QUASIQUOTE { L _ (ITquasiQuote _) }
TH_QQUASIQUOTE { L _ (ITqQuasiQuote _) }
%monad { P } { >>= } { return } %monad { P } { >>= } { return }
%lexer { lexer } { L _ ITeof } %lexer { lexer } { L _ ITeof }
...@@ -1360,6 +1361,10 @@ quasiquote :: { Located (HsQuasiQuote RdrName) } ...@@ -1360,6 +1361,10 @@ quasiquote :: { Located (HsQuasiQuote RdrName) }
; ITquasiQuote (quoter, quote, quoteSpan) = unLoc $1 ; ITquasiQuote (quoter, quote, quoteSpan) = unLoc $1
; quoterId = mkUnqual varName quoter } ; quoterId = mkUnqual varName quoter }
in L1 (mkHsQuasiQuote quoterId (RealSrcSpan quoteSpan) quote) } in L1 (mkHsQuasiQuote quoterId (RealSrcSpan quoteSpan) quote) }
| TH_QQUASIQUOTE { let { loc = getLoc $1
; ITqQuasiQuote (qual, quoter, quote, quoteSpan) = unLoc $1
; quoterId = mkQual varName (qual, quoter) }
in sL (getLoc $1) (mkHsQuasiQuote quoterId (RealSrcSpan quoteSpan) quote) }
exp :: { LHsExpr RdrName } exp :: { LHsExpr RdrName }
: infixexp '::' sigtype { LL $ ExprWithTySig $1 $3 } : infixexp '::' sigtype { LL $ ExprWithTySig $1 $3 }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment