forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathat_match.re
195 lines (163 loc) · 4.06 KB
/
at_match.re
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
/* at_match.c generated by re2c 3.0-1
*
* Generated with:
* re2c at_match.re -o generated/at_match.c -W --tags --no-debug-info --no-generation-date \
* --no-version
*/
#include "../at_match.h"
struct at_token at_match_cmd(const char *at, const char **remainder)
{
const char *cursor = at;
const char *marker = NULL;
/*!local:re2c
re2c:define:YYCTYPE = "unsigned char";
re2c:define:YYCURSOR = cursor;
re2c:define:YYMARKER = marker;
re2c:yyfill:enable = 0;
AT_CASE_INS = [Aa][Tt];
CMD = [#%+][A-Za-z0-9]+;
cmd_test = AT_CASE_INS CMD "=?";
cmd_read = AT_CASE_INS CMD "?";
cmd_set = AT_CASE_INS CMD "=";
cmd_set_no_subparams = AT_CASE_INS CMD?;
notif = CMD ":";
* { return (struct at_token){ .type = AT_TOKEN_TYPE_INVALID }; }
cmd_test
{
if (remainder) *remainder = cursor;
return (struct at_token){
.start = at, .len = cursor - at - 2,
.type = AT_TOKEN_TYPE_CMD_TEST
};
}
cmd_read
{
if (remainder) *remainder = cursor;
return (struct at_token){
.start = at, .len = cursor - at - 1,
.type = AT_TOKEN_TYPE_CMD_READ
};
}
cmd_set
{
if (remainder) *remainder = cursor;
return (struct at_token){
.start = at, .len = cursor - at - 1,
.type = AT_TOKEN_TYPE_CMD_SET
};
}
cmd_set_no_subparams
{
if (remainder) *remainder = cursor;
return (struct at_token){
.start = at, .len = cursor - at,
.type = AT_TOKEN_TYPE_CMD_SET
};
}
notif
{
if (remainder) *remainder = cursor;
return (struct at_token){
.start = at, .len = cursor - at - 1,
.type = AT_TOKEN_TYPE_NOTIF
};
}
*/
}
struct at_token at_match_subparam(const char *at, const char **remainder)
{
const char *cursor = at;
const char *marker = NULL;
const char *t1;
const char *t2;
/*!stags:re2c format = 'const char *@@;'; */
/*!local:re2c
re2c:define:YYCTYPE = "unsigned char";
re2c:define:YYCURSOR = cursor;
re2c:define:YYMARKER = marker;
re2c:yyfill:enable = 0;
SPACE = " ";
INT = "0"|[+\-]?[1-9][0-9]*;
COMMA = ",";
QUOTE = "\"";
QUOTED_STR = QUOTE @t1 [^"\x00]* @t2 QUOTE;
OPEN_PAR = "(";
CLOSE_PAR = ")";
ARRAY = OPEN_PAR [^()\x00]+ CLOSE_PAR;
int = SPACE? @t1 INT @t2 COMMA?;
quoted_str = SPACE? QUOTED_STR COMMA?;
array = SPACE? @t1 ARRAY @t2 COMMA?;
empty = SPACE? @t1 @t2 COMMA;
* { return (struct at_token){ .type = AT_TOKEN_TYPE_INVALID }; }
int
{
char last = *(cursor - 1);
if (remainder) *remainder = cursor;
return (struct at_token){
.start = t1, .len = t2 - t1,
.type = AT_TOKEN_TYPE_INT,
.var = last == ',' ? AT_TOKEN_VAR_COMMA : AT_TOKEN_VAR_NO_COMMA
};
}
quoted_str
{
char last = *(cursor - 1);
if (remainder) *remainder = cursor;
return (struct at_token){
.start = t1, .len = t2 - t1,
.type = AT_TOKEN_TYPE_QUOTED_STRING,
.var = last == ',' ? AT_TOKEN_VAR_COMMA : AT_TOKEN_VAR_NO_COMMA
};
}
array
{
char last = *(cursor - 1);
if (remainder) *remainder = cursor;
return (struct at_token){
.start = t1, .len = t2 - t1,
.type = AT_TOKEN_TYPE_ARRAY,
.var = last == ',' ? AT_TOKEN_VAR_COMMA : AT_TOKEN_VAR_NO_COMMA
};
}
empty
{
if (remainder) *remainder = cursor;
return (struct at_token){
.start = t1, .len = t2 - t1,
.type = AT_TOKEN_TYPE_EMPTY, .var = AT_TOKEN_VAR_COMMA
};
}
*/
}
struct at_token at_match_str(const char *at, const char **remainder)
{
const char *cursor = at;
const char *marker = NULL;
const char *t1;
const char *t2;
/*!stags:re2c format = 'const char *@@;'; */
/*!local:re2c
re2c:define:YYCTYPE = "unsigned char";
re2c:define:YYCURSOR = cursor;
re2c:define:YYMARKER = marker;
re2c:yyfill:enable = 0;
SPACE = " ";
CRLF = "\r\n";
STR = [A-Za-z0-9][A-Za-z_\-.0-9 ]*;
str = SPACE? @t1 STR @t2 CRLF?;
* { return (struct at_token){ .type = AT_TOKEN_TYPE_INVALID }; }
str
{
if (remainder) *remainder = t2;
return (struct at_token){
.start = t1, .len = t2 - t1,
.type = AT_TOKEN_TYPE_STRING,
};
}
*/
}