This repository was archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToken.x
More file actions
69 lines (61 loc) · 1.87 KB
/
Token.x
File metadata and controls
69 lines (61 loc) · 1.87 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
module Token where
}
%wrapper "posn"
$digit = 0-9
$alpha = [a-zA-Z]
tokens :-
$white+ ;
"--".* ;
select { tok (\p s -> TokenSelect p) }
where { tok (\p s -> TokenWhere p) }
and { tok (\p s -> TokenAnd p) }
\= { tok (\p s -> TokenEq p) }
\( { tok (\p s -> TokenLParen p) }
\) { tok (\p s -> TokenRParen p) }
exists { tok (\p s -> TokenExists p) }
in { tok (\p s -> TokenIn p) }
\_ [$digit] [$digit]* { tok (\p s -> TokenVarSkip p (read (tail s) :: Int)) }
[$alpha $digit] [$alpha $digit \_ \’]* { tok (\p s -> TokenVarRelation p s) }
{
-- Each action has type :: AlexPosn -> String -> Token
tok f p s = f p s
data Token =
TokenSelect AlexPosn |
TokenWhere AlexPosn |
TokenAnd AlexPosn |
TokenEq AlexPosn |
TokenLParen AlexPosn |
TokenRParen AlexPosn |
TokenExists AlexPosn |
TokenIn AlexPosn |
TokenVarSkip AlexPosn Int |
TokenVarRelation AlexPosn String
deriving (Eq,Show)
tokenPosn :: Token -> AlexPosn
tokenPosn (TokenSelect p) = p
tokenPosn (TokenWhere p) = p
tokenPosn (TokenAnd p) = p
tokenPosn (TokenEq p) = p
tokenPosn (TokenLParen p) = p
tokenPosn (TokenRParen p) = p
tokenPosn (TokenExists p) = p
tokenPosn (TokenIn p) = p
tokenPosn (TokenVarSkip p _) = p
tokenPosn (TokenVarRelation p _) = p
lineNum :: AlexPosn -> Int
lineNum (AlexPn _ n _) = n
colNum :: AlexPosn -> Int
colNum (AlexPn _ _ n) = n
tokenString :: Token -> String
tokenString (TokenSelect _) = "\"select\""
tokenString (TokenWhere _) = "\"where\""
tokenString (TokenAnd _) = "\"and\""
tokenString (TokenEq _) = "\"=\""
tokenString (TokenLParen _) = "\"(\""
tokenString (TokenRParen _) = "\")\""
tokenString (TokenExists _) = "\"exists\""
tokenString (TokenIn _) = "\"in\""
tokenString (TokenVarSkip _ s) = "\"_" ++ show s ++ "\""
tokenString (TokenVarRelation _ s) = "\"" ++ s ++ "\""
}