-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindent.lex
112 lines (94 loc) · 3.86 KB
/
indent.lex
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
structure T = Sym
type pos = int
type lexresult = T.t
val pos = ref 0
fun eof () = T.Eof
fun error (errmsg, char, _) =
print (String.concat ["Char ", Int.toString char, ": ", errmsg, "\n"])
val commentLevel = ref 0
%%
%structure IndentLexer
%s STRING COMMENT;
ws=[\t\ \n];
lc=[a-z];
uc=[A-Z_];
num=[0-9];
idchars={lc}|{uc}|{num}|[.<>#=+*^?@!$|&/%`~'-];
id={idchars}+|\(\);
cstart=\(\*+;
cend=\*+\);
char=\#\"..?\";
%%
<INITIAL>";COMMENT;" => ( YYBEGIN COMMENT; lex () );
<INITIAL>";STRING;" => ( YYBEGIN STRING; lex () );
<INITIAL>{ws}+ => ( lex () );
<INITIAL>{char} => ( T.Char );
<INITIAL>"=" => ( T.Eq yypos );
<INITIAL>"{" => ( T.Lbrace yypos );
<INITIAL>"[" => ( T.Lbrack yypos );
<INITIAL>"(" => ( T.Lparen yypos );
<INITIAL>")" => ( T.Rparen );
<INITIAL>"()" => ( T.Id yypos );
<INITIAL>"}" => ( T.Rbrace );
<INITIAL>"]" => ( T.Rbrack );
<INITIAL>"\\" => ( T.Backslash );
<INITIAL>"," => ( T.Comma );
<INITIAL>":>" => ( T.Opaque );
<INITIAL>":" => ( T.Colon );
<INITIAL>";" => ( T.Semi );
<INITIAL>"|" => ( T.Bar );
<INITIAL>"=>" => ( T.Darr );
<INITIAL>"->" => ( T.Arr );
<INITIAL>"*" => ( T.Star );
<INITIAL>"fn"{ws}+{id}{ws}+"=>" => ( T.FnArr yypos );
<INITIAL>"where"{ws}+"type" => ( T.Wheretype yypos );
<INITIAL>"and"{ws}+"type" => ( T.Andtype );
<INITIAL>"withtype" => ( T.Withtype );
<INITIAL>"and" => ( T.And );
<INITIAL>"else"{ws}+"if" => ( T.ElseIf );
<INITIAL>"andalso" => ( T.Andalso );
<INITIAL>"case" => ( T.Case yypos );
<INITIAL>"datatype" => ( T.Datatype yypos );
<INITIAL>"else" => ( T.Else );
<INITIAL>"end" => ( T.End );
<INITIAL>"eqtype" => ( T.Type yypos );
<INITIAL>"exception" => ( T.Exception yypos );
<INITIAL>"fn" => ( T.Fn yypos );
<INITIAL>"fun" => ( T.Fun yypos );
<INITIAL>"functor" => ( T.Functor yypos );
<INITIAL>"handle" => ( T.Handle yypos );
<INITIAL>"before" => ( T.Handle yypos );
<INITIAL>"if" => ( T.If yypos );
<INITIAL>"in" => ( T.In );
<INITIAL>"include" => ( T.Include yypos );
<INITIAL>"infix"r? => ( T.Infix yypos );
<INITIAL>"let" => ( T.Let );
<INITIAL>"local" => ( T.Local yypos );
<INITIAL>"of" => ( T.Of );
<INITIAL>"open" => ( T.Open yypos );
<INITIAL>"orelse" => ( T.Orelse);
<INITIAL>"sig" => ( T.Sig );
<INITIAL>"signature" => ( T.Signature yypos );
<INITIAL>"struct" => ( T.Struct yypos );
<INITIAL>"structure" => ( T.Structure yypos );
<INITIAL>"then" => ( T.Then );
<INITIAL>"type" => ( T.Type yypos );
<INITIAL>"val" => ( T.Val yypos );
<INITIAL>"withtype" => ( T.Withtype );
<INITIAL>{id} => ( T.Id yypos );
<INITIAL>\" => ( YYBEGIN STRING; T.DoubleQuote yypos );
<STRING>\\\" => ( lex () );
<STRING>\" => ( YYBEGIN INITIAL; T.DoubleQuote yypos );
<STRING>. => ( lex () );
<INITIAL>{cstart} => ( Ref.incr commentLevel;
YYBEGIN COMMENT;
T.Cstart yypos );
<INITIAL>{cend} => ( T.Cend );
<COMMENT>{cstart} => ( Ref.incr commentLevel;
T.Cstart yypos );
<COMMENT>{cend} => ( Ref.decr commentLevel;
(if !commentLevel = 0 then YYBEGIN INITIAL else ());
T.Cend );
<COMMENT>. => ( lex () );
<INITIAL>. => ( error ("ignoring illegal character" ^ yytext,
yypos, yypos + size yytext); lex () );