File: state.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 (32 lines) | stat: -rw-r--r-- 569 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
{
module Main (main) where
}

%wrapper "gscan"

state :-

  $white+	{ skip }
  \{ [^\}]* \}  { code }
  [A-Za-z]+	{ ide }

{
code _ _ inp len cont (sc,frags) = cont (sc,frag:frags)
	where
	frag = take (len-4) (drop 2 inp)

ide _ _ inp len cont st = Ide (take len inp):cont st

skip _ _ inp len cont st = cont st

data Token = Ide String | Eof String | Err 	deriving Show

stop_act _ _ "" (_,frags) = [Eof (unlines(reverse frags))]
stop_act _ _ _ _ = [Err]

tokens:: String -> [Token]
tokens inp = alexGScan stop_act [] inp

main:: IO ()
main = interact (show.tokens)
}