File: pp.x

package info (click to toggle)
alex 3.4.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 768 kB
  • sloc: haskell: 4,648; makefile: 138; yacc: 56; ansic: 4
file content (38 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (12)
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
%{
import System
import Char
import Alex
%}


"pp_lx"/"pp_acts":-

{ ^s = ^w#^n                }		-- spaces and tabs, etc.
{ ^f = [A-Za-z0-9`~%-_.,/'] }		-- file name character

  <inc> ::= ^#include^s+^"^f+^"^s*^n
  <txt> ::= .*^n


%{
inc p c inp len cont st = pp fn >> cont st
	where
	fn = (takeWhile ('"'/=) . tail . dropWhile isSpace . drop 8) inp

txt p c inp len cont st = putStr (take len inp) >> cont st


main:: IO ()
main =	getArgs						>>= \args ->
	case args of
	  [fn] -> pp fn
	  _ -> error "usage: pp file\n"
	
pp:: String -> IO ()
pp fn = readFile fn >>= \cts -> gscan pp_scan () cts

pp_scan:: GScan () (IO ())
pp_scan = load_gscan (pp_acts,stop_act) pp_lx
	where
	stop_act _ _ _ _ = return ()
%}