-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathlit.x
48 lines (35 loc) · 971 Bytes
/
lit.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
{-# LANGUAGE NPlusKPatterns #-}
module Main (main) where
}
%wrapper "gscan"
$space = $white # \n
@blank = \n $space*
@scrap = \n \> .*
@comment = \n ( [^ \> $white] | $space+ ~$white ) .*
lit :-
@blank @scrap+ { scrap }
@blank @comment* { comment }
{
scrap _ _ inp len cont st = strip len inp
where
strip 0 _ = cont st
strip (n+1) (c:rst) =
if c=='\n'
then '\n':strip_nl n rst
else c:strip n rst
strip_nl (n+1) ('>':rst) = ' ':strip n rst
strip_nl n rst = strip n rst
comment _ _ inp len cont st = strip len inp
where
strip 0 _ = cont st
strip (n+1) (c:rst) = if c=='\n' then c:strip n rst else strip n rst
main:: IO ()
main = interact literate
literate:: String -> String
literate inp = drop 2 (alexGScan stop_act () ('\n':'\n':inp))
stop_act p _ "" st = []
stop_act p _ _ _ = error (msg ++ loc p ++ "\n")
msg = "literate preprocessing error at "
loc (AlexPn _ l c) = "line " ++ show(l-2) ++ ", column " ++ show c
}