summaryrefslogtreecommitdiff
path: root/compiler/parser/Lexer.x
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2019-02-03 10:27:42 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2019-02-03 20:16:18 +0200
commitdc16e6fb4ea021ad18f1e1bf07f5bac791de64eb (patch)
tree007ee5629ce310d2c5bd3b2dc97e22b751e88ebd /compiler/parser/Lexer.x
parent71dae4eb1a4891fc1a428caf70a06830864ffdc3 (diff)
downloadhaskell-wip/T16279.tar.gz
Lexer: Alternate Layout Rule injects actual not virtual braceswip/T16279
When the alternate layout rule is activated via a pragma, it injects tokens for { and } to make sure that the source is parsed properly. But it injects ITocurly and ITccurly, rather than their virtual counterparts ITvocurly and ITvccurly. This causes problems for ghc-exactprint, which tries to print these. Test case (the existing T13087.hs) {-# LANGUAGE AlternativeLayoutRule #-} {-# LANGUAGE LambdaCase #-} isOne :: Int -> Bool isOne = \case 1 -> True _ -> False main = return () Closes #16279
Diffstat (limited to 'compiler/parser/Lexer.x')
-rw-r--r--compiler/parser/Lexer.x28
1 files changed, 14 insertions, 14 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index c4d0d4d127..f82422deed 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -2686,23 +2686,23 @@ alternativeLayoutRuleToken t
do setAlrExpectingOCurly Nothing
setALRContext (ALRLayout expectingOCurly thisCol : context)
setNextToken t
- return (L thisLoc ITocurly)
+ return (L thisLoc ITvocurly)
| otherwise ->
do setAlrExpectingOCurly Nothing
- setPendingImplicitTokens [L lastLoc ITccurly]
+ setPendingImplicitTokens [L lastLoc ITvccurly]
setNextToken t
- return (L lastLoc ITocurly)
+ return (L lastLoc ITvocurly)
(_, _, Just expectingOCurly) ->
do setAlrExpectingOCurly Nothing
setALRContext (ALRLayout expectingOCurly thisCol : context)
setNextToken t
- return (L thisLoc ITocurly)
+ return (L thisLoc ITvocurly)
-- We do the [] cases earlier than in the spec, as we
-- have an actual EOF token
(ITeof, ALRLayout _ _ : ls, _) ->
do setALRContext ls
setNextToken t
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
(ITeof, _, _) ->
return t
-- the other ITeof case omitted; general case below covers it
@@ -2713,7 +2713,7 @@ alternativeLayoutRuleToken t
| newLine ->
do setPendingImplicitTokens [t]
setALRContext ls
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
-- This next case is to handle a transitional issue:
(ITwhere, ALRLayout _ col : ls, _)
| newLine && thisCol == col && transitional ->
@@ -2725,7 +2725,7 @@ alternativeLayoutRuleToken t
setNextToken t
-- Note that we use lastLoc, as we may need to close
-- more layouts, or give a semicolon
- return (L lastLoc ITccurly)
+ return (L lastLoc ITvccurly)
-- This next case is to handle a transitional issue:
(ITvbar, ALRLayout _ col : ls, _)
| newLine && thisCol == col && transitional ->
@@ -2737,7 +2737,7 @@ alternativeLayoutRuleToken t
setNextToken t
-- Note that we use lastLoc, as we may need to close
-- more layouts, or give a semicolon
- return (L lastLoc ITccurly)
+ return (L lastLoc ITvccurly)
(_, ALRLayout _ col : ls, _)
| newLine && thisCol == col ->
do setNextToken t
@@ -2747,7 +2747,7 @@ alternativeLayoutRuleToken t
setNextToken t
-- Note that we use lastLoc, as we may need to close
-- more layouts, or give a semicolon
- return (L lastLoc ITccurly)
+ return (L lastLoc ITvccurly)
-- We need to handle close before open, as 'then' is both
-- an open and a close
(u, _, _)
@@ -2756,7 +2756,7 @@ alternativeLayoutRuleToken t
ALRLayout _ _ : ls ->
do setALRContext ls
setNextToken t
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
ALRNoLayout _ isLet : ls ->
do let ls' = if isALRopen u
then ALRNoLayout (containsCommas u) False : ls
@@ -2779,21 +2779,21 @@ alternativeLayoutRuleToken t
(ITin, ALRLayout ALRLayoutLet _ : ls, _) ->
do setALRContext ls
setPendingImplicitTokens [t]
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
(ITin, ALRLayout _ _ : ls, _) ->
do setALRContext ls
setNextToken t
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
-- the other ITin case omitted; general case below covers it
(ITcomma, ALRLayout _ _ : ls, _)
| topNoLayoutContainsCommas ls ->
do setALRContext ls
setNextToken t
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
(ITwhere, ALRLayout ALRLayoutDo _ : ls, _) ->
do setALRContext ls
setPendingImplicitTokens [t]
- return (L thisLoc ITccurly)
+ return (L thisLoc ITvccurly)
-- the other ITwhere case omitted; general case below covers it
(_, _, _) -> return t