HsLexerPass1a

Plain source file: HsLexerPass1a.hs (Mar 19)

HsLexerPass1a is imported by: StripComments.

module HsLexerPass1a where
import HsLex(haskellLex)
import HsTokens
import List(mapAccumL)

default(Int)

-- Tokenize, add position information and remove white space:
lexerPass1 = filter (notWhite.fst) . lexerPass0
  where
    notWhite t = t/=Whitespace && t/=Commentstart

-- Tokenize and add position information:
lexerPass0 = addPos . haskellLex
  where
    addPos = snd . mapAccumL pos startPos


    pos p (t,r) = (nextPos p s,(t,(p,s)))
      where s = reverse r

-- The first column is designated column 1, not 0.
startPos = (1,1)

nextPos = foldl nextPos1

nextPos1 (y,x) c =
      case c of
        -- The characters newline, return, linefeed, and formfeed, all start
	-- a new line.
	'\n'  -> (y+1, 1)
	'\CR'  -> (y+1, 1)
	'\LF' -> (y+1, 1)
	'\FF' -> (y+1, 1)
        -- Tab stops are 8 characters apart.
	-- A tab character causes the insertion of enough spaces to align the
	-- current position with the next tab stop.
	-- + (not in the report) the first tab stop is column 1.
	'\t'  -> (y, x+8-(x-1) `mod` 8)
	_ -> (y, x+1)

Index

(HTML for this module was generated on Mar 20. About the conversion tool.)