on master help sign in
Add Literate Haskell syntax test file
commite91778493204c29d875975b81a52074419bbbfa9 authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com> dateSat 29 May 2021, 05:44 (5 years ago) parentf46b90d
2 files changed+94
tests/syntax-tests/highlighted/Literate Haskell/Main.lhs+47 tests/syntax-tests/source/Literate Haskell/Main.lhs+47
tests/syntax-tests/highlighted/Literate Haskell/Main.lhsnew file+47
@@ -0,0 +1,47 @@
1+\documentclass{article}
2+
3+\begin{document}
4+
5+\section*{Introduction}
6+
7+Text outside code environments should follow TeX/LaTeX highlighting.
8+
9+The code environment delimiters themselves should be highlighted.
10+
11+Text inside code environments should follow regular Haskell highlighting.
12+
13+\begin{code}
14+import Data.List
15+import System.Environment
16+import Text.Printf
17+
18+twoSumN :: Int -> [Int] -> [Int]
19+twoSumN _ [] = []
20+twoSumN n (x : xs) | (n - x) `elem` xs = [x, n - x]
21+ | otherwise = twoSumN n xs
22+
23+threeSumN :: Int -> [Int] -> [Int]
24+threeSumN _ [] = []
25+threeSumN n (x : xs) | null partial = threeSumN n xs
26+ | otherwise = x : partial
27+ where partial = twoSumN (n - x) xs
28+\end{code}
29+
30+Text in-between code environments.
31+% LaTeX comment.
32+
33+\begin{code}
34+output :: String -> IO ()
35+output path = do
36+ input <- sort . map read . filter (not . null) . lines <$> readFile path
37+ printf "File: %s\n" path
38+ printf " Part 1: %d\n" . product . twoSumN 2020 $ input
39+ printf " Part 2: %d\n" . product . threeSumN 2020 $ input
40+
41+-- Haskell comment inside code environment.
42+
43+main :: IO ()
44+main = getArgs >>= mapM_ output
45+\end{code}
46+
47+\end{document}
tests/syntax-tests/source/Literate Haskell/Main.lhsnew file+47
@@ -0,0 +1,47 @@
1+\documentclass{article}
2+
3+\begin{document}
4+
5+\section*{Introduction}
6+
7+Text outside code environments should follow TeX/LaTeX highlighting.
8+
9+The code environment delimiters themselves should be highlighted.
10+
11+Text inside code environments should follow regular Haskell highlighting.
12+
13+\begin{code}
14+import Data.List
15+import System.Environment
16+import Text.Printf
17+
18+twoSumN :: Int -> [Int] -> [Int]
19+twoSumN _ [] = []
20+twoSumN n (x : xs) | (n - x) `elem` xs = [x, n - x]
21+ | otherwise = twoSumN n xs
22+
23+threeSumN :: Int -> [Int] -> [Int]
24+threeSumN _ [] = []
25+threeSumN n (x : xs) | null partial = threeSumN n xs
26+ | otherwise = x : partial
27+ where partial = twoSumN (n - x) xs
28+\end{code}
29+
30+Text in-between code environments.
31+% LaTeX comment.
32+
33+\begin{code}
34+output :: String -> IO ()
35+output path = do
36+ input <- sort . map read . filter (not . null) . lines <$> readFile path
37+ printf "File: %s\n" path
38+ printf " Part 1: %d\n" . product . twoSumN 2020 $ input
39+ printf " Part 2: %d\n" . product . threeSumN 2020 $ input
40+
41+-- Haskell comment inside code environment.
42+
43+main :: IO ()
44+main = getArgs >>= mapM_ output
45+\end{code}
46+
47+\end{document}