Lexer.x 2.05 KB
Newer Older
mnay1u19's avatar
mnay1u19 committed
1
2
3
{
module Lexer where
}
4

mnay1u19's avatar
mnay1u19 committed
5
6
7
%wrapper "basic"
$digit = 0-9
$alpha = [a-zA-Z]
pm3g19's avatar
pm3g19 committed
8
9
$lower = [a-z]
$upper = [A-Z]
mnay1u19's avatar
mnay1u19 committed
10
11

tokens :-
pm3g19's avatar
pm3g19 committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    $white+                         ;
    "--".*                          ;
    filter                          {\s -> TokenFilter }
    $upper[$alpha]*                 {\s -> TokenSetName s }
    Func                            {\s -> TokenFunc }
    $digit+                         {\s -> TokenNat (read s) }
    $lower [$lower $digit \_ \']*   {\s -> TokenVarName s }
    Record                          {\s -> TokenRecord }
    true                            {\s -> TokenTrue }
    false                           {\s -> TokenFalse }
    $[$alpha $digit]*               {\s -> TokenString s }
    '['                             {\s -> TokenLeftSqBracket }
    ']'                             {\s -> TokenRightSqBracket }
    "->"                            {\s -> TokenArrow }
    "=="                            {\s -> TokenisEqual }
    "/="                            {\s -> TokenisNotEqual }
    '('                             {\s -> TokenLeftBracket }
    ')'                             {\s -> TokenRightBracket }
    ';'                             {\s -> TokenApp }
    '\\'                            {\s -> TokenLambda }
    ','                             {\s -> TokenComma }
    '.'                             {\s -> TokenFullstop }
    in                              {\s -> TokenInSet }
    out                             {\s -> TokenOutSet }
mnay1u19's avatar
mnay1u19 committed
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
{
--token type:
data Token =
    TokenFilter         |
    TokenSetName String |
    TokenFunc           |
    TokenNat Int        |
    TokenVarName String |
    TokenRecord         |
    TokenTrue           |
    TokenFalse          |
    TokenString String  |
    TokenLeftSqBracket  |
    TokenRightSqBracket |
    TokenArrow          |
    TokenisEqual        |
    TokenisNotEqual     |
    TokenLeftBracket    |
    TokenRightBracket   |
    TokenApp            |
    TokenLambda         |
    TokenComma          |
    TokenFullStop       |
    TokenInSet          |
    TokenOutSet
    deriving  (Eq, Show)
}