leLex l n (c:cs)
   = if   c == '#'
     then if n == 1
          then
          {- This is a CPP line number thingy -}
          let lineNoText  = takeWhile isDigit (tail cs)
              lineNo      = leStringToInt lineNoText
              nextLine    = drop 1 (dropWhile ((/=) '\n') cs)
          in
              leLex lineNo 1 nextLine
          else
          {- it's a symbol starting with # -}
          case leChunk (n+1) leIsSymbol cs of
             (restSym, nn, restText) -> (l, n, Lvarop, c:restSym) :
                                        leLex l nn restText
     else
     if   isAlpha c
     then case leChunk (n+1) leIsTailChar cs of
             (restSym, nn, restText) -> (l, n, if   isUpper c 
                                               then Lcon 
                                               else Lvar, c:restSym) :
                                        leLex l nn restText 
     else
     if   isDigit c
     then case leChunk (n+1) isDigit cs of
             (restSym, nn, restText) -> (l, n, Lintlit, c:restSym) :
                                        leLex l nn restText 
     else
     if   leIsSymbol c
     then case leChunk (n+1) leIsSymbol cs of
             (restSym, nn, restText) -> (l, n, if   c == ':' 
                                               then Lconop 
                                               else Lvarop, c:restSym) :
                                        leLex l nn restText 
     else
     leFail l n ("Illegal character  " ++ [c])
leLex l n (c:cs)
   = if   c == '#'
     then if n == 1
          then
          {- This is a CPP line number thingy -}
          let lineNoText  = takeWhile isDigit (tail cs)
              lineNo      = leStringToInt lineNoText
              nextLine    = drop 1 (dropWhile ((/=) '\n') cs)
          in
              leLex lineNo 1 nextLine
          else
          {- it's a symbol starting with # -}
          case leChunk (n+1) leIsSymbol cs of
             (restSym, nn, restText) -> (l, n, Lvarop, c:restSym) :
                                        leLex l nn restText
     else
     if   isAlpha c
     then case leChunk (n+1) leIsTailChar cs of
             (restSym, nn, restText) -> (l, n, if   isUpper c 
                                               then Lcon 
                                               else Lvar, c:restSym) :
                                        leLex l nn restText 
     else
     if   isDigit c
     then case leChunk (n+1) isDigit cs of
             (restSym, nn, restText) -> (l, n, Lintlit, c:restSym) :
                                        leLex l nn restText 
     else
     if   leIsSymbol c
     then case leChunk (n+1) leIsSymbol cs of
             (restSym, nn, restText) -> (l, n, if   c == ':' 
                                               then Lconop 
                                               else Lvarop, c:restSym) :
                                        leLex l nn restText 
     else
     leFail l n ("Illegal character  " ++ [c])
leLex l n (c:cs)
   = if   c == '#'
     then if n == 1
          then
          {- This is a CPP line number thingy -}
          let lineNoText  = takeWhile isDigit (tail cs)
              lineNo      = leStringToInt lineNoText
              nextLine    = drop 1 (dropWhile ((/=) '\n') cs)
          in
              leLex lineNo 1 nextLine
          else
          {- it's a symbol starting with # -}
          case leChunk (n+1) leIsSymbol cs of
             (restSym, nn, restText) -> (l, n, Lvarop, c:restSym) :
                                        leLex l nn restText
     else
     if   isAlpha c
     then case leChunk (n+1) leIsTailChar cs of
             (restSym, nn, restText) -> (l, n, if   isUpper c 
                                               then Lcon 
                                               else Lvar, c:restSym) :
                                        leLex l nn restText 
     else
     if   isDigit c
     then case leChunk (n+1) isDigit cs of
             (restSym, nn, restText) -> (l, n, Lintlit, c:restSym) :
                                        leLex l nn restText 
     else
     if   leIsSymbol c
     then case leChunk (n+1) leIsSymbol cs of
             (restSym, nn, restText) -> (l, n, if   c == ':' 
                                               then Lconop 
                                               else Lvarop, c:restSym) :
                                        leLex l nn restText 
     else
     leFail l n ("Illegal character  " ++ [c])