diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-05-29 22:17:55 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-06-01 06:41:18 -0400 |
commit | c68e7e1e4c0bddd8b07cd8a2b3651c8cbb4b7851 (patch) | |
tree | 1a9c315982b9e089cde38e5ea062eb2ab078ad9c | |
parent | 0fde53770cacb0d54f0583707ef7ceec78f92c41 (diff) | |
download | haskell-c68e7e1e4c0bddd8b07cd8a2b3651c8cbb4b7851.tar.gz |
Improve parser error messages for TemplateHaskellQuotes
While [e| |], [t| |], [d| |], and so on, steal syntax from list
comprehensions, [| |] and [|| ||] do not steal any syntax.
Thus we can improve error messages by always accepting them in the
lexer. Turns out the renamer already performs necessary validation.
-rw-r--r-- | compiler/GHC/Parser/Lexer.x | 13 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/T18251e.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/T18251e.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/parser/should_fail/all.T | 1 |
4 files changed, 18 insertions, 4 deletions
diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x index 8245974db6..5633fd0b0d 100644 --- a/compiler/GHC/Parser/Lexer.x +++ b/compiler/GHC/Parser/Lexer.x @@ -366,15 +366,20 @@ $tab { warnTab } -- "special" symbols <0> { - "[|" / { ifExtension ThQuotesBit } { token (ITopenExpQuote NoE NormalSyntax) } - "[||" / { ifExtension ThQuotesBit } { token (ITopenTExpQuote NoE) } + + -- Don't check ThQuotesBit here as the renamer can produce a better + -- error message than the lexer (see the thQuotesEnabled check in rnBracket). + "[|" { token (ITopenExpQuote NoE NormalSyntax) } + "[||" { token (ITopenTExpQuote NoE) } + "|]" { token (ITcloseQuote NormalSyntax) } + "||]" { token ITcloseTExpQuote } + + -- Check ThQuotesBit here as to not steal syntax. "[e|" / { ifExtension ThQuotesBit } { token (ITopenExpQuote HasE NormalSyntax) } "[e||" / { ifExtension ThQuotesBit } { token (ITopenTExpQuote HasE) } "[p|" / { ifExtension ThQuotesBit } { token ITopenPatQuote } "[d|" / { ifExtension ThQuotesBit } { layout_token ITopenDecQuote } "[t|" / { ifExtension ThQuotesBit } { token ITopenTypQuote } - "|]" / { ifExtension ThQuotesBit } { token (ITcloseQuote NormalSyntax) } - "||]" / { ifExtension ThQuotesBit } { token ITcloseTExpQuote } "[" @varid "|" / { ifExtension QqBit } { lex_quasiquote_tok } diff --git a/testsuite/tests/parser/should_fail/T18251e.hs b/testsuite/tests/parser/should_fail/T18251e.hs new file mode 100644 index 0000000000..c471a9601c --- /dev/null +++ b/testsuite/tests/parser/should_fail/T18251e.hs @@ -0,0 +1,3 @@ +module T18251e where + +a = [| id |] diff --git a/testsuite/tests/parser/should_fail/T18251e.stderr b/testsuite/tests/parser/should_fail/T18251e.stderr new file mode 100644 index 0000000000..7b869c09c8 --- /dev/null +++ b/testsuite/tests/parser/should_fail/T18251e.stderr @@ -0,0 +1,5 @@ + +T18251e.hs:3:5: error: + • Syntax error on [| id |] + Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes + • In the Template Haskell quotation [| id |] diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T index 3b31682cb2..9142eb0393 100644 --- a/testsuite/tests/parser/should_fail/all.T +++ b/testsuite/tests/parser/should_fail/all.T @@ -171,4 +171,5 @@ test('T18251a', normal, compile_fail, ['']) test('T18251b', normal, compile_fail, ['']) test('T18251c', normal, compile_fail, ['']) test('T18251d', normal, compile_fail, ['']) +test('T18251e', normal, compile_fail, ['']) test('T18251f', normal, compile_fail, ['']) |