\begin{code}
data Token
- = ITcase -- Haskell keywords
+ = ITas -- Haskell keywords
+ | ITcase
| ITclass
| ITdata
| ITdefault
| ITderiving
| ITdo
| ITelse
+ | IThiding
| ITif
| ITimport
| ITin
| ITmodule
| ITnewtype
| ITof
+ | ITqualified
| ITthen
| ITtype
| ITwhere
haskellKeywordsFM = listToUFM $
map (\ (x,y) -> (_PK_ x,y))
[( "_", ITunderscore ),
+ ( "as", ITas ),
( "case", ITcase ),
( "class", ITclass ),
( "data", ITdata ),
( "deriving", ITderiving ),
( "do", ITdo ),
( "else", ITelse ),
+ ( "hiding", IThiding ),
( "if", ITif ),
( "import", ITimport ),
( "in", ITin ),
( "module", ITmodule ),
( "newtype", ITnewtype ),
( "of", ITof ),
+ ( "qualified", ITqualified ),
( "then", ITthen ),
( "type", ITtype ),
( "where", ITwhere ),
,("!", ITbang)
,(".", ITdot) -- sadly, for 'forall a . t'
]
-
-not_special_op ITminus = False
-not_special_op ITbang = False
-not_special_op _ = True
\end{code}
-----------------------------------------------------------------------------
-- real lexeme is M.<sym>
new_buf = mergeLexemes buf buf'
in
- case lookupUFM haskellKeySymsFM lexeme of {
- Just kwd_token | not_special_op kwd_token
- -> just_a_conid; -- avoid M.::, but not M.!
- other -> cont (mk_qvar_token mod lexeme) new_buf
- }}
+ cont (mk_qvar_token mod lexeme) new_buf
+ -- wrong, but arguably morally right: M... is now a qvarsym
+ }
| otherwise =
let
case _scc_ "Lex.haskellKeyword" lookupUFM haskellKeywordsFM lexeme of {
Just kwd_token -> just_a_conid; -- avoid M.where etc.
Nothing -> is_a_qvarid
+ -- TODO: special ids (as, qualified, hiding) shouldn't be
+ -- recognised as keywords here. ie. M.as is a qualified varid.
}}}
- we still need to insert another '}' followed by a ';',
hence the atbol trick.
+There's also a special hack in here to deal with
+
+ do
+ ....
+ e $ do
+ blah
+
+i.e. the inner context is at the same indentation level as the outer
+context. This is strictly illegal according to Haskell 98, but
+there's a lot of existing code using this style and it doesn't make
+any sense to disallow it, since empty 'do' lists don't make sense.
-}
-layoutOn :: P ()
-layoutOn buf s@(PState{ bol = bol, context = ctx }) =
+layoutOn :: Bool -> P ()
+layoutOn strict buf s@(PState{ bol = bol, context = ctx }) =
let offset = lexemeIndex buf -# bol in
case ctx of
- Layout prev_off : _ | prev_off >=# offset ->
+ Layout prev_off : _
+ | if strict then prev_off >=# offset else prev_off ># offset ->
--trace ("layout on, column: " ++ show (I# offset)) $
POk s{ context = Layout (offset +# 1#) : ctx, atbol = 1# } ()
other ->