1 
    2 
    3 module Lex
    4 
    5 ( uncomment
    6 , isDel
    7 , isAlphanum', updown
    8 
    9 , myLex
   10 
   11 )
   12 
   13 where
   14 
   15 import Char
   16 
   17 
   18 --------------------------------------------------------
   19 
   20 uncomment :: String -> String
   21 uncomment [] = []
   22 uncomment ('-' : '-' : cs) = uncomment (dropWhile (/= '\n') cs)
   23 uncomment ('{' : '-' : cs) = recomment cs
   24 uncomment (c : cs) = c : uncomment cs
   25 
   26 recomment :: String -> String
   27 recomment [] = []
   28 recomment ('-' : '-' : cs) = recomment (dropWhile (/= '\n') cs)
   29 recomment ('-' : '}' : cs) = uncomment cs
   30 recomment (c : cs) = recomment cs
   31 
   32 -------------------------------------------------------
   33 
   34 -- treat TeX operators 
   35 updown c = c `elem` "_^'"
   36 
   37 isAlphanum' c = isAlphaNum c || updown c
   38 
   39 -------------------------------------------------------
   40 
   41 
   42 myLex [] = []
   43 
   44 myLex ('"' : cs) = 
   45     let (as, bs) = span (/= '"') cs
   46     in  ('"' : as ++ "\"") : myLex (drop 1 bs)
   47 
   48 
   49 myLex (c : cs) | isSpace c = myLex cs
   50 myLex (c : cs) | isAlpha c =
   51         let (ds, es) = span isAlphanum' cs
   52         in (c : ds) : myLex es
   53 myLex (c : cs) | isDigit c =
   54         let (ds, es) = span isDigit cs
   55         in (c : ds) : myLex es
   56 myLex (c : cs) | isDel c =
   57         [c] : myLex cs
   58 
   59 myLex (c : cs) = 
   60         let (ds, es) = break (\ c -> isAlphanum' c || isSpace c || isDel c) cs
   61         in (c : ds) : myLex es
   62 
   63 ----------------------------------------------------------------------------
   64 
   65 isDel '(' = True; isDel ')' = True
   66 isDel '[' = True; isDel ']' = True
   67 isDel '{' = True; isDel '}' = True
   68 isDel '`' = True
   69 isDel '"' = True
   70 isDel ',' = True
   71 
   72 -- isDel ';' = True  NOT: semicolon is an operator, has semantics
   73 
   74 isDel _ = False
   75 
   76