Plain source file: base/parse2/Lexer/HsLexUtils.hs (2009-01-04)

HsLexUtils is imported by: HsLex, HsLexerPass1.

{-# OPTIONS_GHC -cpp -O #-}

module HsLexUtils(module HsLexUtils,Token(..),isSymbol) where
import HsTokens
import qualified Data.Char as C

gotEOF [] = []
gotEOF as = [(GotEOF, reverse as)]

gotError as is =
  (ErrorToken, reverse as):
  if null is then [(GotEOF,[])] else [(TheRest,is{-reverse (take 80 is)-})]

-- Inlining the call to output does not make a big difference.
--output token as cont = (token, reverse as):cont

-- Not reversing the token string seems to save about 10% of the time with HBC.
-- The difference in speed seems insignificant with ghc-6.0.1 -O.
output token as cont = (token,reverse as):cont

-- This avoids constructing a closure for the call to reverse.
-- This saves about 10% too.
output token as cont =
    rev as []
    rev [] as' = (token,as'):cont
    rev (a:as) as' = rev as (a:as')

isSymbol _ = False

nestedComment as is next = nest 0 as is
    nest n as is =
      case is of
	'-':'}':is -> if n==0
		      then next gotError ('}':'-':as) is
		      else nest (n-1) ('}':'-':as) is
        '{':'-':is -> nest (n+1) ('-':'{':as) is
	c:is -> nest n (c:as) is
	_ -> gotError as is -- EOF inside comment


(HTML for this module was generated on 2009-01-04. About the conversion tool.)