{ module CSVQLTokens where } %wrapper "posn" $whitechar = [ \t\n\r\f\v] $special = [\(\)\,\;\[\]\`\{\}] $ascdigit = 0-9 $unidigit = [] -- TODO $digit = [$ascdigit $unidigit] $ascsymbol = [\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~] $unisymbol = [] -- TODO $symbol = [$ascsymbol $unisymbol] # [$special \_\:\"\'] -- digits -- alphabetic characters $large = [A-Z \xc0-\xd6 \xd8-\xde] $small = [a-z \xdf-\xf6 \xf8-\xff \_] $alpha = [$small $large] $graphic = [$small $large $symbol $digit $special \:\"\'] @string = $graphic # [\"\\] | " " tokens :- $white+ ; "#".* ; $digit+ { \p s -> TokenInt p (read s) } true { \p s -> TokenTrue p } false { \p s -> TokenFalse p } null { \p s -> TokenNull p} and { \p s -> TokenAnd p } or { \p s -> TokenOr p } \" @string* \" { \p s -> TokenString p (read s) } for { \p s -> TokenFor p} in { \p s -> TokenIn p} if { \p s -> TokenIf p } else { \p s -> TokenElse p } \{ { \p s -> TokenLCurly p } \} { \p s -> TokenRCurly p } \. { \p s -> TokenDot p } \; { \p s -> TokenSemi p } \= { \p s -> TokenEq p} \+ { \p s -> TokenPlus p} == { \p s -> TokenEqq p } not { \p s -> TokenNot p } \( { \p s -> TokenLParen p} \) { \p s -> TokenRParen p} \[ { \p s -> TokenSquareL p} \] { \p s -> TokenSquareR p} \, { \p s -> TokenComma p} \< { \p s -> TokenLess p } \> { \p s -> TokenGreater p } $alpha [$alpha $digit \_ \’]* { \s -> TokenVar s } { -- Each action has type :: String -> Token -- The token type: data Token = TokenTrue AlexPosn | TokenFalse AlexPosn | TokenNull AlexPosn | TokenString AlexPosn String | TokenInt AlexPosn Int | TokenAnd AlexPosn | TokenOr AlexPosn | TokenFor AlexPosn | TokenIn AlexPosn | TokenIf AlexPosn | TokenElse AlexPosn | TokenLCurly AlexPosn | TokenRCurly AlexPosn | TokenDot AlexPosn | TokenSemi AlexPosn | TokenEq AlexPosn | TokenPlus AlexPosn | TokenEqq AlexPosn | TokenNot AlexPosn | TokenLParen AlexPosn | TokenRParen AlexPosn | TokenSquareL AlexPosn | TokenSquareR AlexPosn | TokenComma AlexPosn | TokenLess AlexPosn | TokenGreater AlexPosn | TokenVar AlexPosn String deriving (Eq,Show) tokenPosn :: Token -> String tokenPosn (TokenInt p _) = posnToString p tokenPosn (TokenTrue p) = posnToString p tokenPosn (TokenFalse p) = posnToString p tokenPosn (TokenNull p) = posnToString p tokenPosn (TokenString p _) = posnToString p tokenPosn (TokenFor p) = posnToString p tokenPosn (TokenIn p) = posnToString p tokenPosn (TokenIf p) = posnToString p tokenPosn (TokenElse p) = posnToString p tokenPosn (TokenLCurly p) = posnToString p tokenPosn (TokenRCurly p) = posnToString p tokenPosn (TokenDot p) = posnToString p tokenPosn (TokenSemi p) = posnToString p tokenPosn (TokenEq p) = posnToString p tokenPosn (TokenPlus p) = posnToString p tokenPosn (TokenEqq p) = posnToString p tokenPosn (TokenNot p) = posnToString p tokenPosn (TokenLParen p) = posnToString p tokenPosn (TokenRParen p) = posnToString p tokenPosn (TokenSquareL p) = posnToString p tokenPosn (TokenSquareR p) = posnToString p tokenPosn (TokenComma p) = posnToString p tokenPosn (TokenVar p _) = posnToString p tokenPosn (TokenAnd p ) = posnToString p tokenPosn (TokenOr p ) = posnToString p tokenPosn (TokenGreater p ) = posnToString p tokenPosn (TokenLess p ) = posnToString p posnToString :: AlexPosn -> String posnToString (AlexPn x y z) = show y ++ ":" ++ show z }