| SYM Char
| INT Int
| STR String
+ | CAT String
deriving (Eq,Show)
initLexer :: String -> [Token]
lexer (c:cs) line column
| c == '\n' = lexer cs (succ line) 0
| c == '\"' = lexerSTR cs line (succ column)
+ | c == '[' = lexerCAT cs "" line (succ column)
| c `elem` "{};-:"
= (line,column,SYM c) : lexer cs line (succ column)
| isSpace c = lexer cs line (succ column)
-- not technically correct for the new column count, but a good approximation.
lexerSTR cs line column
= case lex ('"' : cs) of
- [(str,rest)] -> (line,succ column,STR str)
+ [(str,rest)] -> (line,succ column,STR (read str))
: lexer rest line (length (show str) + column + 1)
_ -> error "bad string"
+lexerCAT (c:cs) s line column
+ | c == ']' = (line,column,CAT s) : lexer cs line (succ column)
+ | otherwise = lexerCAT cs (s ++ [c]) line (succ column)
+lexerCAT other s line column = error "lexer failure in CAT"
+
test = do
t <- readFile "EXAMPLE.tc"
print (initLexer t)