summaryrefslogtreecommitdiff
path: root/src/mangling/dex/type_tok.l
blob: 7e85d43103b6093cef6053819c13cb83e2724026 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

%{

#include "context.h"
#include "libmanglingdextype_la-type_gram.h"

/* See lemoda.net/c/reentrant-parser */

%}


%option noyywrap
%option yylineno
%option nounput
/*%option noinput*/
%option reentrant
%option bison-bridge

%x string

ASCII       [A-Za-z0-9]
SIMPLE      {ASCII}|"$"|"-"|"_"

%%

"V"                     { return V; }
"Z"                     { return Z; }
"B"                     { return B; }
"S"                     { return S; }
"C"                     { return C; }
"I"                     { return I; }
"J"                     { return J; }
"F"                     { return F; }
"D"                     { return D; }
"L"                     { BEGIN(string); return L; }
"["*                    { yylval->adeep = strlen(yytext); return ARRAY; }
<string>"/"             { return SLASH; }
<string>";"             { BEGIN(INITIAL); return SEMICOLON; }

<string>{SIMPLE}*       { yylval->text = yytext; return TEXT; }

<string>.               {
                            unsigned char next;
                            char mutf8[4];

                            switch ((unsigned char)yytext[0])
                            {
                                /* U+00a1 ... U+1fff */
                                case 0x00 ... 0x1f:

                                    next = input(yyscanner);

                                    if (yytext[0] == 0x00 && next < 0xa1)
                                    {
                                        REJECT;
                                    }

                                    else
                                    {
                                        mutf8[0] = yytext[0];
                                        mutf8[1] = next;
                                        mutf8[2] = '\0';

                                        strcpy(yylval->text, mutf8); return TEXT;

                                    }

                                    break;

                                /* U+2010 ... U+2027 / U+2030 ... U+d7ff */
                                case 0x20:

                                    next = input(yyscanner);

                                    switch (next)
                                    {
                                        case 0x10 ... 0x27:
                                        case 0x30 ... 0xff:

                                            mutf8[0] = yytext[0];
                                            mutf8[1] = next;
                                            mutf8[2] = '\0';

                                            strcpy(yylval->text, mutf8); return TEXT;
                                            break;

                                        default:
                                            REJECT;
                                            break;

                                    }

                                    break;

                                /* ~ U+2030 ... U+d7ff */
                                case 0x21 ... 0xd7:

                                    next = input(yyscanner);

                                    mutf8[0] = yytext[0];
                                    mutf8[1] = next;
                                    mutf8[2] = '\0';

                                    strcpy(yylval->text, mutf8); return TEXT;
                                    break;

                                /* U+e000 ... U+ffef */
                                case 0xe0 ... 0xff:

                                    next = input(yyscanner);

                                    if (yytext[0] == 0xff && next > 0xef)
                                    {
                                        REJECT;
                                    }

                                    else
                                    {
                                        mutf8[0] = yytext[0];
                                        mutf8[1] = next;
                                        mutf8[2] = '\0';

                                        strcpy(yylval->text, mutf8); return TEXT;

                                    }

                                    break;

                                /* U+10000 ... U+10ffff */
                                /*
                                case 0x10:

                                    mutf8[0] = yytext[0];
                                    mutf8[1] = input(yyscanner);
                                    mutf8[2] = input(yyscanner);
                                    mutf8[3] = '\0';

                                    strcpy(yylval->text, mutf8); return TEXT;
                                    break;
                                */

                                default:
                                    REJECT;
                                    break;

                            }

                        }

%%