{ -- alex scanner for use with uulib -- compile with alex -o Scanner.hs -g Scanner.x module Graphics.LambdaCube.Loader.Generated.OverlayScriptScanner(tokenize) where import UU.Scanner } $litChar = [^[\" \\]] $identChar = [a-zA-Z0-9_\.\-\/\~] tokens :- $white+ ; -- whitespace "//".* ; -- comment \" ($litChar | \\ \\ | \\ \" )* \" { valueToken TkString } -- string [0-9]+ { valueToken TkInteger16 } -- int ( zorder | element | container | metrics_mode | pixels | relative | horz_align | left | center | right | vert_align | top | center | bottom | left | top | width | height | material | caption | rotation | Panel | transparent | true | false | tiling | uv_coords | BorderPanel | border_size | border_material | border_topleft_uv | border_topright_uv | border_bottomleft_uv | border_bottomright_uv | border_left_uv | border_right_uv | border_top_uv | border_bottom_uv | TextArea | font_name | char_height | colour | colour_top | colour_bottom | alignment | space_width | Panel | BorderPanel | TextArea) { reserved } -- reserved keywords [\{\}\:\(\)] { reserved } -- reserved symbols $identChar+ { valueToken TkVarid } -- identifier { -- boilerplate code needed for Alex type AlexInput = (Pos, String) alexInputPrevChar :: AlexInput -> Char alexInputPrevChar = error "alexInputPrevChar: there is no need to go back in the input." alexGetChar :: AlexInput -> Maybe (Char, AlexInput) alexGetChar (_, []) = Nothing alexGetChar (p, (c:cs)) = let p' = adv p c in Just (c, (p', cs)) -- use the Alex scanner to generate a list of tokens for the uulib token parsers tokenize :: String -> String -> [Token] tokenize filename str = go (initpos, str) where initpos = Pos 1 1 filename go inp@(pos, cs) = case alexScan inp 0 of AlexEOF -> [] AlexError inp' -> valueToken TkError [head cs] pos : go inp' AlexSkip inp' _ -> go inp' AlexToken inp' len act -> act (take len cs) pos : go inp' }