setALRContext (ALRLayout expectingOCurly thisCol : context)
setNextToken t
return (L thisLoc ITocurly)
+ -- 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)
+ (ITeof, _, _) ->
+ return t
+ -- the other ITeof case omitted; general case below covers it
(ITin, ALRLayout ALRLayoutLet _ : ls, _)
| newLine ->
do setPendingImplicitTokens [t]
setALRContext ls
return (L thisLoc ITccurly)
- (_, ls@(ALRLayout _ col : _), _)
- | newLine && thisCol <= col ->
- do let f ls'@(ALRLayout _ col' : ls'')
- | thisCol < col' = case f ls'' of
- (ts, ls''') ->
- (L thisLoc ITccurly : ts, ls''')
- | thisCol == col' = ([L thisLoc ITsemi], ls')
- | otherwise = ([], ls')
- f ls' = ([], ls')
- case f ls of
- (t' : ts, ls') ->
- do setPendingImplicitTokens ts
- setNextToken t
- return t'
- _ -> panic "Layout rule: [] when considering newline"
+ (_, ALRLayout _ col : ls, _)
+ | newLine && thisCol == col ->
+ do setNextToken t
+ return (L thisLoc ITsemi)
+ | newLine && thisCol < col ->
+ do setALRContext ls
+ -- Note that we use lastLoc, as we may need to close
+ -- more layouts, or give a semicolon
+ return (L lastLoc ITccurly)
(u, _, _)
| isALRopen u ->
do setALRContext (ALRNoLayout (containsCommas u) : context)
do setALRContext ls
setPendingImplicitTokens [t]
return (L thisLoc ITccurly)
- (ITin, _ : ls, _) ->
+ (ITin, ALRLayout _ _ : ls, _) ->
do setALRContext ls
setNextToken t
return (L thisLoc ITccurly)
setPendingImplicitTokens [t]
return (L thisLoc ITccurly)
-- the other ITwhere case omitted; general case below covers it
- -- The first [] case comes before the general case, as we
- -- have an actual EOF token
- (ITeof, ALRLayout _ _ : ls, _) ->
- do setALRContext ls
- setNextToken t
- return (L thisLoc ITccurly)
- -- the other ITeof case omitted; general case below covers it
(_, _, _) -> return t
isALRopen :: Token -> Bool