~ubuntu-branches/ubuntu/jaunty/alex/jaunty

« back to all changes in this revision

Viewing changes to alex/examples/state.x

  • Committer: Bazaar Package Importer
  • Author(s): Ian Lynagh (wibble)
  • Date: 2003-10-01 12:31:01 UTC
  • Revision ID: james.westby@ubuntu.com-20031001123101-yquo14mvjqh3e0sk
Tags: upstream-2.0
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
module Main (main) where
 
3
}
 
4
 
 
5
%wrapper "gscan"
 
6
 
 
7
state :-
 
8
 
 
9
  $white+       { skip }
 
10
  \{ [^\}]* \}  { code }
 
11
  [A-Za-z]+     { ide }
 
12
 
 
13
{
 
14
code _ _ inp len cont (sc,frags) = cont (sc,frag:frags)
 
15
        where
 
16
        frag = take (len-4) (drop 2 inp)
 
17
 
 
18
ide _ _ inp len cont st = Ide (take len inp):cont st
 
19
 
 
20
skip _ _ inp len cont st = cont st
 
21
 
 
22
data Token = Ide String | Eof String | Err      deriving Show
 
23
 
 
24
stop_act _ _ "" (_,frags) = [Eof (unlines(reverse frags))]
 
25
stop_act _ _ _ _ = [Err]
 
26
 
 
27
tokens:: String -> [Token]
 
28
tokens inp = alexGScan stop_act [] inp
 
29
 
 
30
main:: IO ()
 
31
main = interact (show.tokens)
 
32
}