4 -- The above warning supression flag is a temporary kludge.
5 -- While working on this module you are encouraged to remove it and fix
6 -- any warnings in the module. See
7 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
10 module Lexer (lex_tok) where
12 import ParserM (ParserM (..), mkT, mkTv, Token(..), St, start_code,
14 inc_brace_depth, dec_brace_depth,
15 show_pos, position, input,
16 AlexInput, alexGetChar, alexInputPrevChar)
24 set_start_code in_braces;
34 <0> "->" { mkT TArrow }
35 <0> "=" { mkT TEquals }
36 <0> "," { mkT TComma }
37 <0> "(" { mkT TOpenParen }
38 <0> ")" { mkT TCloseParen }
39 <0> "(#" { mkT TOpenParenHash }
40 <0> "#)" { mkT THashCloseParen }
41 <0> "section" { mkT TSection }
42 <0> "primop" { mkT TPrimop }
43 <0> "pseudoop" { mkT TPseudoop }
44 <0> "primtype" { mkT TPrimtype }
45 <0> "with" { mkT TWith }
46 <0> "defaults" { mkT TDefaults }
47 <0> "True" { mkT TTrue }
48 <0> "False" { mkT TFalse }
49 <0> "Dyadic" { mkT TDyadic }
50 <0> "Monadic" { mkT TMonadic }
51 <0> "Compare" { mkT TCompare }
52 <0> "GenPrimOp" { mkT TGenPrimOp }
53 <0> "thats_all_folks" { mkT TThatsAllFolks }
54 <0> [a-z][a-zA-Z0-9\#_]* { mkTv TLowerName }
55 <0> [A-Z][a-zA-Z0-9\#_]* { mkTv TUpperName }
56 <0> \" [^\"]* \" { mkTv (TString . tail . init) }
57 <in_braces> [^\{\}]+ { mkTv TNoBraces }
58 <in_braces> \n { mkTv TNoBraces }
61 get_tok :: ParserM Token
62 get_tok = ParserM $ \i st ->
63 case alexScan i (start_code st) of
64 AlexEOF -> Right (i, st, TEOF)
65 AlexError _ -> Left ("Lexical error at " ++ show_pos (position i))
66 AlexSkip i' _ -> case get_tok of
68 AlexToken i' l a -> case a $ take l $ input i of
71 lex_tok :: (Token -> ParserM a) -> ParserM a
72 lex_tok cont = get_tok >>= cont