summaryrefslogtreecommitdiffstats
path: root/src/cmd-scanner.l
blob: 6ad121a087a19d72f07ad4ad678cbf83b197c56a (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
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
%{

#include <stdint.h>
#include <cli.h>
#include "cmd-parser.h"

static void init_pos(struct parser_state *state)
{
	state->lineno		= 1;
	state->column		= 1;
	state->token_offset	= 0;
	state->line_offset	= 0;
}

static void update_pos(struct parser_state *state, struct location *loc,
		       int len)
{
	loc->first_line		= state->lineno;
	loc->first_column	= state->column;
	loc->last_column	= state->column + len - 1;
	state->column		+= len;
}

static void update_offset(struct parser_state *state, struct location *loc,
			  unsigned int len)
{
	state->token_offset	+= len;
	loc->token_offset	= state->token_offset;
	loc->line_offset	= state->line_offset;
}

static void reset_pos(struct parser_state *state, struct location *loc)
{
	state->line_offset	= state->token_offset;
	state->lineno		+= 1;
	state->column		= 1;
	loc->line_offset	= state->line_offset;
}

#define YY_USER_ACTION {					\
	update_pos(yyget_extra(yyscanner), yylloc, yyleng);	\
	update_offset(yyget_extra(yyscanner), yylloc, yyleng);	\
}

/* avoid warnings with -Wmissing-prototypes */
extern int	yyget_column(yyscan_t);
extern void	yyset_column(int, yyscan_t);

%}

%option reentrant
%option noyywrap
%option nounput
%option bison-bridge
%option bison-locations
%option debug
%option yylineno
%option nodefault
%option warn
%option case-insensitive

space		[ ]
tab		\t
newline		\n
digit		[0-9]
hexdigit	[0-9a-fA-F]
decstring	{digit}+
hexstring	0[xX]{hexdigit}+
range		({decstring}?:{decstring}?)
letter		[a-zA-Z]
string		({letter})({letter}|{digit}|[/\-_\.])*
quotedstring	\"[^"]*\"
comment		#.*$
slash		\/
%%

"("			{ return '('; }
")"			{ return ')'; }
"="			{ return '='; }
","			{ return ','; }

"debug"			{ return TOK_DEBUG; }
"cluster"		{ return CLUSTER; }
"portable"		{ return PORTABLE; }
"tbc"			{ return TBC; }

"show"			{ return SHOW; }
"set"			{ return SET; }

"on"			{ return ON; }
"off"			{ return OFF; }

"lce"			{ return LCE; }
"cc"			{ return CC; }
"ss"			{ return SS; }
"clms"			{ return CLMS; }
"mm"			{ return MM; }
"llme"			{ return LLME; }

"MNCC_SETUP-req"	{ return MNCC_SETUP_REQ; }
"MNCC_INFO-req"		{ return MNCC_INFO_REQ; }

"MNSS_FACILITY-req"	{ return MNSS_FACILITY_REQ; }

"portable-identity"	{ return PORTABLE_IDENTITY; }
"sending-complete"	{ return SENDING_COMPLETE; }
"keypad"		{ return KEYPAD; }
"basic-service"		{ return BASIC_SERVICE; }
"escape-to-proprietary"	{ return ESCAPE_TO_PROPRIETARY; }

"IPEI"			{ return IPEI; }

"info"			{ return INFO; }
"service"		{ return SERVICE; }
"class"			{ return CLASS; }

"LIA"			{ return LIA; }
"message"		{ return MESSAGE; }
"dect/isdn"		{ return DECT_ISDN; }
"normal"		{ return NORMAL; }
"internal"		{ return INTERNAL; }
"emergency"		{ return EMERGENCY; }
"external-handover"	{ return EXTERNAL_HO; }
"QA&M"			{ return QA_M; }

"basic-speech"		{ return BASIC_SPEECH; }
"GSM"			{ return GSM; }
"UMTS"			{ return UMTS; }
"LRMS"			{ return LRMS; }
"GSM-SMS"		{ return GSM_SMS; }
"wideband-speech"	{ return WIDEBAND_SPEECH; }
"SUOTA-class-4"		{ return SUOTA_CLASS_4; }
"SUOTA-class-3"		{ return SUOTA_CLASS_3; }
"other"			{ return OTHER; }

"EMC"			{ return EMC; }
"content"		{ return CONTENT; }

{string}		{
				yylval->string = strdup(yytext);
				return STRING;
			}

{quotedstring}		{
				yylval->string = strndup(yytext + 1, yyleng - 2);
				return STRING;
			}

{decstring}		{
				yylval->val = strtoul(yytext, NULL, 0);
				return NUMBER;
			}

\\{newline}		{
				reset_pos(yyget_extra(yyscanner), yylloc);
			}

{newline}		{
				reset_pos(yyget_extra(yyscanner), yylloc);
				return NEWLINE;
			}

{space}+

.			{ return JUNK; }

%%

void scanner_push_buffer(void *scanner, const char *buffer)
{
	struct parser_state *state = yyget_extra(scanner);
	YY_BUFFER_STATE b;

	b = yy_scan_string(buffer, scanner);
	init_pos(state);
}

void *scanner_init(struct parser_state *state)
{
	yyscan_t scanner;

	yylex_init(&scanner);
	yyset_extra(state, scanner);
	yyset_out(NULL, scanner);

	return scanner;
}

void scanner_destroy(struct parser_state *scanner)
{
	yylex_destroy(scanner);
}