Commit ffddc245 authored by ijones's avatar ijones
Browse files

toward Wall cleanliness Unlit.hs

parent 9ab9d47d
......@@ -36,8 +36,8 @@ classify _ [] = []
classify _ (('\\':x):xs) | x == "begin{code}" = Blank : allProg xs
where allProg [] = [] -- Should give an error message, but I have no
-- good position information.
allProg (('\\':x):xs) | x == "end{code}" = Blank : classify 0 xs
allProg (x:xs) = Program x:allProg xs
allProg (('\\':x'):xs') | x' == "end{code}" = Blank : classify 0 xs'
allProg (x':xs') = Program x':allProg xs'
classify 0 (('>':x):xs) = let (sp,code) = span isSpace x in
Program code : classify (length sp + 1) xs
classify n (('>':x):xs) = Program (drop (n-1) x) : classify n xs
......@@ -47,7 +47,7 @@ classify _ (('#':x):xs) =
_ -> Pre x
) : classify 0 xs
classify _ (x:xs) | all isSpace x = Blank:classify 0 xs
classify _ (x:xs) = Comment:classify 0 xs
classify _ (_:xs) = Comment:classify 0 xs
unclassify :: Classified -> String
unclassify (Program s) = s
......@@ -59,19 +59,20 @@ unclassify Comment = ""
adjacent :: String -> Int -> Classified -> [Classified] -> [Classified]
adjacent file 0 _ (x :xs) = x: adjacent file 1 x xs
-- force evaluation of line number
adjacent file n y@(Program _) (x@Comment :xs) =
adjacent file n (Program _) (Comment :_) =
error (message file n "program" "comment")
adjacent file n y@(Program _) (x@(Include i f):xs) = x: adjacent f i y xs
adjacent _ _ y@(Program _) (x@(Include i f):xs) = x: adjacent f i y xs
adjacent file n y@(Program _) (x@(Pre _) :xs) = x: adjacent file (n+1) y xs
adjacent file n y@Comment (x@(Program _) :xs) =
adjacent file n Comment ((Program _) :_) =
error (message file n "comment" "program")
adjacent file n y@Comment (x@(Include i f):xs) = x: adjacent f i y xs
adjacent _ _ y@Comment (x@(Include i f):xs) = x: adjacent f i y xs
adjacent file n y@Comment (x@(Pre _) :xs) = x: adjacent file (n+1) y xs
adjacent file n y@Blank (x@(Include i f):xs) = x: adjacent f i y xs
adjacent _ _ y@Blank (x@(Include i f):xs) = x: adjacent f i y xs
adjacent file n y@Blank (x@(Pre _) :xs) = x: adjacent file (n+1) y xs
adjacent file n _ (x@next :xs) = x: adjacent file (n+1) x xs
adjacent file n _ [] = []
adjacent file n _ (x :xs) = x: adjacent file (n+1) x xs
adjacent _ _ _ [] = []
message :: (Show a) => String -> a -> String -> String -> String
message "\"\"" n p c = "Line "++show n++": "++p++ " line before "++c++" line.\n"
message [] n p c = "Line "++show n++": "++p++ " line before "++c++" line.\n"
message file n p c = "In file " ++ file ++ " at line "
......@@ -81,7 +82,8 @@ message file n p c = "In file " ++ file ++ " at line "
-- Re-implementation of 'lines', for better efficiency (but decreased
-- laziness). Also, importantly, accepts non-standard DOS and Mac line
-- ending characters.
tolines s = lines' s id
tolines :: String -> [String]
tolines s' = lines' s' id
where
lines' [] acc = [acc []]
lines' ('\^M':'\n':s) acc = acc [] : lines' s id -- DOS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment