{
{-# OPTIONS -Wwarn -w #-}
--- The above warning supression flag is a temporary kludge.
+-- The above -Wwarn supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and fix
-- any warnings in the module. See
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
module Lexer (
Token(..), lexer, pragState, mkPState, PState(..),
P(..), ParseResult(..), getSrcLoc,
- getPState,
+ getPState, getDynFlags, withThisPackage,
failLocMsgP, failSpanMsgP, srcParseFail,
- getMessages,
+ getMessages,
popContext, pushCurrentContext, setLastToken, setSrcLoc,
getLexState, popLexState, pushLexState,
extension, standaloneDerivingEnabled, bangPatEnabled,
import SrcLoc
import UniqFM
import DynFlags
+import Module
import Ctype
import Util ( readRational )
| ITstdcallconv
| ITccallconv
| ITprimcallconv
- | ITdotnet
| ITmdo
| ITfamily
| ITgroup
| ITdupipvarid FastString -- GHC extension: implicit param: ?x
- | ITpragma StringBuffer
-
| ITchar Char
| ITstring FastString
| ITinteger Integer
| ITprimfloat Rational
| ITprimdouble Rational
- -- MetaHaskell extension tokens
+ -- Template Haskell extension tokens
| ITopenExpQuote -- [| or [e|
| ITopenPatQuote -- [p|
| ITopenDecQuote -- [d|
( "stdcall", ITstdcallconv, bit ffiBit),
( "ccall", ITccallconv, bit ffiBit),
( "prim", ITprimcallconv, bit ffiBit),
- ( "dotnet", ITdotnet, bit ffiBit),
- ( "rec", ITrec, bit arrowsBit),
+ ( "rec", ITrec, bit recBit),
( "proc", ITproc, bit arrowsBit)
]
begin code _span _str _len = do pushLexState code; lexToken
pop :: Action
-pop _span _buf _len = do popLexState; lexToken
+pop _span _buf _len = do _ <- popLexState
+ lexToken
pop_and :: Action -> Action
-pop_and act span buf len = do popLexState; act span buf len
+pop_and act span buf len = do _ <- popLexState
+ act span buf len
{-# INLINE nextCharIs #-}
nextCharIs :: StringBuffer -> (Char -> Bool) -> Bool
-- RULES pragmas turn on the forall and '.' keywords, and we turn them
-- off again at the end of the pragma.
rulePrag :: Action
-rulePrag span _ _ = do
+rulePrag span _buf _len = do
setExts (.|. bit inRulePragBit)
return (L span ITrules_prag)
endPrag :: Action
-endPrag span _ _ = do
+endPrag span _buf _len = do
setExts (.&. complement (bit inRulePragBit))
return (L span ITclose_prag)
return (L span ITvccurly)
EQ -> do
--trace "layout: inserting ';'" $ do
- popLexState
+ _ <- popLexState
return (L span ITsemi)
GT -> do
- popLexState
+ _ <- popLexState
lexToken
-- certain keywords put us in the "layout" state, where we might
--
new_layout_context :: Bool -> Action
new_layout_context strict span _buf _len = do
- popLexState
+ _ <- popLexState
(AI _ offset _) <- getInput
ctx <- getContext
case ctx of
do_layout_left :: Action
do_layout_left span _buf _len = do
- popLexState
+ _ <- popLexState
pushLexState bol -- we must be at the start of a line
return (L span ITvccurly)
let line = parseUnsignedInteger buf len 10 octDecDigit
setSrcLoc (mkSrcLoc (srcSpanFile span) (fromIntegral line - 1) 0)
-- subtract one: the line number refers to the *following* line
- popLexState
+ _ <- popLexState
pushLexState code
lexToken
setFile code span buf len = do
let file = lexemeToFastString (stepOn buf) (len-2)
setSrcLoc (mkSrcLoc file (srcSpanEndLine span) (srcSpanEndCol span))
- popLexState
+ _ <- popLexState
pushLexState code
lexToken
getPState :: P PState
getPState = P $ \s -> POk s s
+getDynFlags :: P DynFlags
+getDynFlags = P $ \s -> POk s (dflags s)
+
+withThisPackage :: (PackageId -> a) -> P a
+withThisPackage f
+ = do pkg <- liftM thisPackage getDynFlags
+ return $ f pkg
+
extension :: (Int -> Bool) -> P Bool
extension p = P $ \s -> POk s (p $! extsBitmap s)
rawTokenStreamBit = 20 -- producing a token stream with all comments included
newQualOpsBit :: Int
newQualOpsBit = 21 -- Haskell' qualified operator syntax, e.g. Prelude.(+)
+recBit :: Int
+recBit = 22 -- rec
always :: Int -> Bool
always _ = True
}
where
bitmap = genericsBit `setBitIf` dopt Opt_Generics flags
- .|. ffiBit `setBitIf` dopt Opt_ForeignFunctionInterface flags
- .|. parrBit `setBitIf` dopt Opt_PArr flags
- .|. arrowsBit `setBitIf` dopt Opt_Arrows flags
- .|. thBit `setBitIf` dopt Opt_TemplateHaskell flags
- .|. qqBit `setBitIf` dopt Opt_QuasiQuotes flags
- .|. ipBit `setBitIf` dopt Opt_ImplicitParams flags
- .|. explicitForallBit `setBitIf` dopt Opt_ScopedTypeVariables flags
- .|. explicitForallBit `setBitIf` dopt Opt_LiberalTypeSynonyms flags
- .|. explicitForallBit `setBitIf` dopt Opt_PolymorphicComponents flags
- .|. explicitForallBit `setBitIf` dopt Opt_ExistentialQuantification flags
- .|. explicitForallBit `setBitIf` dopt Opt_Rank2Types flags
- .|. explicitForallBit `setBitIf` dopt Opt_RankNTypes flags
- .|. bangPatBit `setBitIf` dopt Opt_BangPatterns flags
- .|. tyFamBit `setBitIf` dopt Opt_TypeFamilies flags
- .|. haddockBit `setBitIf` dopt Opt_Haddock flags
- .|. magicHashBit `setBitIf` dopt Opt_MagicHash flags
- .|. kindSigsBit `setBitIf` dopt Opt_KindSignatures flags
- .|. recursiveDoBit `setBitIf` dopt Opt_RecursiveDo flags
- .|. unicodeSyntaxBit `setBitIf` dopt Opt_UnicodeSyntax flags
- .|. unboxedTuplesBit `setBitIf` dopt Opt_UnboxedTuples flags
+ .|. ffiBit `setBitIf` dopt Opt_ForeignFunctionInterface flags
+ .|. parrBit `setBitIf` dopt Opt_PArr flags
+ .|. arrowsBit `setBitIf` dopt Opt_Arrows flags
+ .|. thBit `setBitIf` dopt Opt_TemplateHaskell flags
+ .|. qqBit `setBitIf` dopt Opt_QuasiQuotes flags
+ .|. ipBit `setBitIf` dopt Opt_ImplicitParams flags
+ .|. explicitForallBit `setBitIf` dopt Opt_ExplicitForAll flags
+ .|. bangPatBit `setBitIf` dopt Opt_BangPatterns flags
+ .|. tyFamBit `setBitIf` dopt Opt_TypeFamilies flags
+ .|. haddockBit `setBitIf` dopt Opt_Haddock flags
+ .|. magicHashBit `setBitIf` dopt Opt_MagicHash flags
+ .|. kindSigsBit `setBitIf` dopt Opt_KindSignatures flags
+ .|. recursiveDoBit `setBitIf` dopt Opt_RecursiveDo flags
+ .|. recBit `setBitIf` dopt Opt_DoRec flags
+ .|. recBit `setBitIf` dopt Opt_Arrows flags
+ .|. unicodeSyntaxBit `setBitIf` dopt Opt_UnicodeSyntax flags
+ .|. unboxedTuplesBit `setBitIf` dopt Opt_UnboxedTuples flags
.|. standaloneDerivingBit `setBitIf` dopt Opt_StandaloneDeriving flags
.|. transformComprehensionsBit `setBitIf` dopt Opt_TransformListComp flags
.|. rawTokenStreamBit `setBitIf` dopt Opt_KeepRawTokenStream flags
"noinline" -> "notinline"
"specialise" -> "specialize"
"constructorlike" -> "conlike"
- otherwise -> prag'
+ _ -> prag'
canon_ws s = unwords (map canonical (words s))
}