added any2unistr predefined function (artf724008)
[deliverable/titan.core.git] / compiler2 / ttcn3 / pstring_la.l
CommitLineData
970ed795 1/******************************************************************************
d44e3c4f 2 * Copyright (c) 2000-2016 Ericsson Telecom AB
970ed795
EL
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
d44e3c4f 7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Delic, Adam
11 * Forstner, Matyas
12 * Pandi, Krisztian
13 * Raduly, Csaba
14 * Szabados, Kristof
19700695 15 * Szabo, Bence Janos
d44e3c4f 16 * Szabo, Janos Zoltan – initial implementation
17 *
970ed795
EL
18 ******************************************************************************/
19%option nostack
20%option noyylineno
21%option noyywrap
22%option nounput
23%option never-interactive
24%option prefix="pstring_yy"
25
26%{ /* ****************** C declarations ***************** */
27
28#include <stdio.h>
29#include <ctype.h>
30#include "../error.h"
31#include "../Identifier.hh"
32#include "../Int.hh"
33#include "PatternString.hh"
34
35using namespace Ttcn;
36using namespace Common;
37
38/** Adjust location information.
39 *
40 * \c start_index and \c end_index index into \c yytext.
41 * \c current_line and \c current_column index into the actual source line
42 * (only a part of which is in \c yytext).
43 *
44 * UPDATE_LOCATION should be called to "cover" all of yytext.
45 *
46 * @param [in] start_index index into yytext (the first character to consider)
47 * @param [in] end_index index into yytext (one-past)
48 * @param [in,out] current_line
49 * @param [in,out] current_column
50 * */
3abe9331 51static void update_location(size_t start_index, size_t end_index,
52 size_t& current_line, size_t& current_column)
970ed795 53{
3abe9331 54 for (size_t i = start_index; i < yyleng && i < end_index; i++) {
970ed795
EL
55 // count CR, count LF, but count CR + LF as one
56 switch (yytext[i]) {
57 case '\r':
58 current_line++;
59 current_column = 0;
60 break;
61 case '\n':
62 if (i == 0 || yytext[i - 1] != '\r') {
63 current_line++;
64 current_column = 0;
65 }
66 break;
67 default:
68 current_column++;
69 }
70 }
71}
72
73// This must be side-effect-free !
74#define UPDATE_LOCATION(start_index, end_index) \
75 update_location(start_index, end_index, current_line, current_column)
76
77#define YY_DECL static PatternString *yylex(const char *current_file, \
3abe9331 78 size_t current_line, size_t current_column)
970ed795
EL
79
80%} /* ***************** definitions ***************** */
81
82IDENTIFIER [A-Za-z][A-Za-z0-9_]*
83NUMBER 0|([1-9][0-9]*)
84WS [ \t\r\n\v\f]*
85NEWLINE \r|\n|\r\n
19700695 86UID [uU][+]?[0-9A-Fa-f]{1,8}
970ed795
EL
87
88%% /* ***************** rules ************************* */
89
90 bool in_set = false; /* inside a [] */
91 PatternString* ps = new PatternString();
92
93"{"{WS}{IDENTIFIER}(({WS}\.{WS}{IDENTIFIER})|({WS}\[{WS}({IDENTIFIER}|{NUMBER}){WS}\]))*{WS}"}" {
94if (in_set) {
95 // in a set a reference (without the \N at start) is just simple text,
96 // the matched token does not contain characters that are special in a set
97 ps->addString(yytext);
98 UPDATE_LOCATION(0, yyleng);
99} else {
100 vector<string> identifiers;
101 vector<int> beginnings;
102
103 const char * beg = yytext;
104 const char * end = 0;
105 int id_begin = 0; // the first alphanumeric character of an identifier
106 for (;;) {
107 while (isspace(*++beg) || (*beg=='[') ) ; // skip whitespace and [
108 int *current_begin = new int(beg - yytext);
109 if (!id_begin) id_begin = *current_begin;
110 end = beg;
111 while (isalnum(*++end) || *end=='_') ; // scan for the end of identifier
112
113 string* identifier = new string(end-beg, beg);
114 identifiers.add(identifier);
115 beginnings .add(current_begin);
116
117 beg = end; // end remembers the position before the whitespace
118 while (isspace(*beg) || (*beg==']') ) ++beg; // skip whitespace and ]
119 if (*beg=='}') break;
120 }
121
122 size_t num_id = identifiers.size();
123 bool error = false;
124 Ttcn::Reference *ref = 0;
3abe9331 125 size_t last = 0; // last "consumed" index into yytext
970ed795
EL
126 int old_column = 0, old_line = 0; // the beginning of the entire reference
127
128 for (size_t i = 0; i < num_id; ++i) {
129 const string & id_str = *identifiers[i];
3abe9331 130 const size_t & id_beg = *beginnings [i];
970ed795
EL
131 if (Identifier::is_reserved_word(id_str, Identifier::ID_TTCN)) {
132 UPDATE_LOCATION(last, id_beg); // consume before identifier
133 int first_line = current_line, first_column = current_column;
134 UPDATE_LOCATION(id_beg, id_beg+id_str.size()); // consume identifier
135 Location loc(current_file, first_line, first_column, current_line,
136 current_column); // location covers the identifier
137 UPDATE_LOCATION(id_beg+id_str.size(), yyleng); // consume to end
138 loc.error("Invalid reference expression: `%s' is a reserved word in TTCN-3",
139 id_str.c_str());
140 error = true;
141 break;
142 } else if (in_set) {
143 UPDATE_LOCATION(last, id_beg); // consume before identifier
144 break;
145 } else {
146 if (i==0) {
147 UPDATE_LOCATION(0, id_begin); // consume before identifier
148 old_column = current_column; old_line = current_line;
149 ref = new Ttcn::Reference(new Identifier(Identifier::ID_TTCN, id_str));
150 UPDATE_LOCATION(id_begin, last = id_begin + id_str.size());
151 } else {
152 UPDATE_LOCATION(last, id_beg);
153 Location loc(current_file, current_line, current_column, current_line,
154 current_column + id_str.size());
155 UPDATE_LOCATION(id_beg, last = id_beg + id_str.size());
156
157 int temp_i;
158 FieldOrArrayRef *fieldref = 0;
159
160 if(1 != sscanf( (id_str.c_str()), "%d", &temp_i)){
161 fieldref = new FieldOrArrayRef(new Identifier(Identifier::ID_TTCN, id_str));
162 }
163 else {
164 int_val_t* temp_intvalt = new int_val_t(temp_i);
165 Value* temp_value = new Value(Value::V_INT, temp_intvalt);
166 fieldref = new FieldOrArrayRef(temp_value);
167 }
168 if (ref) {
169 ref->set_location(loc);
170 ref->add(fieldref);
171 } else {
172 loc.error("Invalid reference expression");
173 }
174 }
175 }
176 } // next i
177
178 if (error) {
179 delete ref; // safe even if NULL
180 } else {
181 UPDATE_LOCATION(last, yyleng); // consume to the end
182 Location loc(current_file, old_line, old_column, current_line, current_column);
183 if (ref) {
184 ref->set_location(loc);
185 ps->addRef(ref);
186 } else {
187 loc.error("Invalid reference expression");
188 }
189 }
190
191 // cleanup (can't be done in the second loop because it may end early)
192 for (size_t i = 0; i < num_id; ++i) {
193 delete identifiers[i];
194 delete beginnings [i];
195 }
196 identifiers.clear();
197 beginnings .clear();
198} //else
199}
200
201"{"[^}]*"}" {
202 int first_line = current_line, first_column = current_column;
203 UPDATE_LOCATION(0, yyleng);
204 Location loc(current_file, first_line, first_column, current_line,
205 current_column);
206 loc.error("Invalid reference expression: `%s'", yytext);
207}
208
209"\\N"{WS}"{"{WS}{IDENTIFIER}{WS}"}" {
210 int id_begin = 3;
211 while (!isalpha(yytext[id_begin])) id_begin++;
212 int id_len = 1;
213 while (isalnum(yytext[id_begin + id_len]) || yytext[id_begin + id_len] == '_')
214 id_len++;
215 string id_str(id_len, yytext + id_begin);
216 /*
217 Ttcn::Reference *ref = new Ttcn::Reference(new Identifier(
218 Identifier::ID_TTCN, id_str));
219 ref->set_location(loc);
220 ps->addRefdCharSet(ref);
221 */
222 int first_line = current_line, first_column = current_column;
223 UPDATE_LOCATION(0, yyleng);
224 Location loc(current_file, first_line, first_column, current_line,
225 current_column);
226 if (Identifier::is_reserved_word(id_str, Identifier::ID_TTCN)) {
227 loc.error("Invalid character set reference: `%s' is a reserved word in "
228 "TTCN-3", id_str.c_str());
229 } else if (in_set) {
230 loc.warning("Character set reference `\\N{%s}' is not supported, "
231 "dropped out from the set", id_str.c_str());
232 } else {
233 loc.warning("Character set reference `\\N{%s}' is not supported, "
234 "substituted with `?'", id_str.c_str());
235 ps->addChar('?');
236 }
237}
238
239"\\N"{WS}"{"[^}]*"}" {
240 int first_line = current_line, first_column = current_column;
241 UPDATE_LOCATION(0, yyleng);
242 Location loc(current_file, first_line, first_column, current_line,
243 current_column);
244 loc.error("Invalid character set reference: `%s'", yytext);
245}
246
247"\\q"{WS}"{"{WS}{NUMBER}{WS}","{WS}{NUMBER}{WS}","{WS}{NUMBER}{WS}","{WS}{NUMBER}{WS}"}" {
3abe9331 248 size_t group_begin = 3;
970ed795
EL
249 while (!isdigit(yytext[group_begin])) group_begin++;
250 UPDATE_LOCATION(0, group_begin);
3abe9331 251 size_t group_len = 1;
970ed795
EL
252 while (isdigit(yytext[group_begin + group_len])) group_len++;
253 string group_str(group_len, yytext + group_begin);
254 Location group_loc(current_file, current_line, current_column, current_line,
255 current_column + group_len);
256 Int group = string2Int(group_str, group_loc);
257 if (group < 0 || group > 127) {
258 group_loc.error("The first number of quadruple (group) must be within "
259 "the range 0 .. 127 instead of %s", Int2string(group).c_str());
260 group = group < 0 ? 0 : 127;
261 }
3abe9331 262 size_t plane_begin = group_begin + group_len + 1;
970ed795
EL
263 while (!isdigit(yytext[plane_begin])) plane_begin++;
264 UPDATE_LOCATION(group_begin, plane_begin);
265 int plane_len = 1;
266 while (isdigit(yytext[plane_begin + plane_len])) plane_len++;
267 string plane_str(plane_len, yytext + plane_begin);
268 Location plane_loc(current_file, current_line, current_column, current_line,
269 current_column + plane_len);
270 Int plane = string2Int(plane_str, plane_loc);
271 if (plane < 0 || plane > 255) {
272 plane_loc.error("The second number of quadruple (plane) must be within "
273 "the range 0 .. 255 instead of %s", Int2string(plane).c_str());
274 plane = plane < 0 ? 0 : 255;
275 }
3abe9331 276 size_t row_begin = plane_begin + plane_len + 1;
970ed795
EL
277 while (!isdigit(yytext[row_begin])) row_begin++;
278 UPDATE_LOCATION(plane_begin, row_begin);
3abe9331 279 size_t row_len = 1;
970ed795
EL
280 while (isdigit(yytext[row_begin + row_len])) row_len++;
281 string row_str(row_len, yytext + row_begin);
282 Location row_loc(current_file, current_line, current_column, current_line,
283 current_column + row_len);
284 Int row = string2Int(row_str, row_loc);
285 if (row < 0 || row > 255) {
286 row_loc.error("The third number of quadruple (row) must be within "
287 "the range 0 .. 255 instead of %s", Int2string(row).c_str());
288 row = row < 0 ? 0 : 255;
289 }
3abe9331 290 size_t cell_begin = row_begin + row_len + 1;
970ed795
EL
291 while (!isdigit(yytext[cell_begin])) cell_begin++;
292 UPDATE_LOCATION(row_begin, cell_begin);
3abe9331 293 size_t cell_len = 1;
970ed795
EL
294 while (isdigit(yytext[cell_begin + cell_len])) cell_len++;
295 string cell_str(cell_len, yytext + cell_begin);
296 Location cell_loc(current_file, current_line, current_column, current_line,
297 current_column + cell_len);
298 Int cell = string2Int(cell_str, cell_loc);
299 if (cell < 0 || cell > 255) {
300 cell_loc.error("The fourth number of quadruple (cell) must be within "
301 "the range 0 .. 255 instead of %s", Int2string(cell).c_str());
302 cell = cell < 0 ? 0 : 255;
303 }
304 bool add_quadruple = true;
305 if (group == 0 && plane == 0 && row == 0) {
306 if (isprint(cell)) {
307 switch (cell) {
308 case '-':
309 case '^':
310 if (!in_set) break;
311 case '?':
312 case '*':
313 case '\\':
314 case '[':
315 case ']':
316 case '{':
317 case '}':
318 case '"':
319 case '|':
320 case '(':
321 case ')':
322 case '#':
323 case '+':
324 ps->addChar('\\');
325 default:
326 break;
327 }
328 ps->addChar(cell);
329 add_quadruple = false;
330 } else {
331 switch (cell) {
332 case '\t':
333 ps->addString("\\t");
334 add_quadruple = false;
335 break;
336 case '\r':
337 ps->addString("\\r");
338 add_quadruple = false;
339 }
340 }
341 }
342 if (add_quadruple) {
343 ps->addString("\\q{" + Int2string(group) + "," + Int2string(plane) + "," +
344 Int2string(row) + "," + Int2string(cell) + "}");
345 }
346 UPDATE_LOCATION(cell_begin, yyleng);
347}
348
19700695 349"\\q"({WS}"{"{WS}({UID}{WS}","{WS})*{UID}{WS}"}") {
350 //Split UID-s. For example: \q{ U23423 , U+001 } -> [U23423, U+001]
351 size_t begin = 3;
352 size_t size = 0;
353 char ** uids = (char **)Malloc(sizeof(char*));
354 while(yytext[begin] != '}'){
355 //Find first digit
356 while(yytext[begin] != 'U' && yytext[begin] != 'u') begin++;
357 size_t end = begin + 2;
358 //Find last digit
359 while(isxdigit(yytext[end])) end++;
360 size++;
361 uids = (char**)Realloc(uids, size * sizeof(char*));
362 uids[size-1] = mcopystrn(yytext + begin, end-begin);
363 //Skip whitespaces until the next UID or the end
364 while(!isxdigit(yytext[end]) && yytext[end] != 'U' && yytext[end] != 'u' && yytext[end] != '}') end++;
365 UPDATE_LOCATION(begin, end);
366 begin = end;
367 }
368 ps->addStringUSI(uids, size);
369 //Free
370 for (size_t i = 0; i < size; ++i) {
371 Free(uids[i]);
372 }
373 Free(uids);
374}
375
970ed795
EL
376"\\q"({WS}"{"[^}]*"}")? {
377 int first_line = current_line, first_column = current_column;
378 UPDATE_LOCATION(0, yyleng);
379 Location loc(current_file, first_line, first_column, current_line,
380 current_column);
19700695 381 loc.error("Invalid quadruple or UID-like notation: `%s'", yytext);
970ed795
EL
382}
383
384"[]" {
385 if(in_set) {
386 ps->addString("\\[]");
387 in_set = false;
388 } else {
389 ps->addString("[\\]");
390 in_set = true;
391 }
392 current_column += 2;
393}
394
395"[^]" {
396 if(in_set) {
397 ps->addString("\\[\\^]");
398 in_set = false;
399 } else {
400 ps->addString("[^\\]");
401 in_set = true;
402 }
403 current_column += 3;
404}
405
406"[" {
407 if(in_set) {
408 ps->addString("\\[");
409 } else {
410 ps->addChar('[');
411 in_set = true;
412 }
413 current_column++;
414}
415
416"]" {
417 if (in_set) {
418 ps->addChar(']');
419 in_set = false;
420 } else {
421 Location loc(current_file, current_line, current_column, current_line,
422 current_column + 1);
423 loc.error("Unmatched `]'. Did you mean `\\]'?");
424 ps->addString("\\]");
425 }
426 current_column++;
427}
428
429"{"|"}" {
430 Location loc(current_file, current_line, current_column, current_line,
431 current_column + 1);
432 loc.warning("Unmatched `%c' was treated literally", yytext[0]);
433 ps->addChar('\\');
434 ps->addChar(yytext[0]);
435 current_column++;
436}
437
438"\\\""|"\"\"" {
439 ps->addChar('"');
440 current_column += 2;
441}
442 /* \metachars and escaped metachars */
443\\[dwtnrsb?*\\\[\]\-\^|()#+] {
444 ps->addString(yytext);
445 current_column += 2;
446}
447
448"\\"(.|{NEWLINE}) {
449 int first_line = current_line, first_column = current_column;
450 UPDATE_LOCATION(0, yyleng);
451 Location loc(current_file, first_line, first_column, current_line,
452 current_column);
453 if (isprint((unsigned char)yytext[1]))
454 loc.warning("Use of unrecognized escape sequence `\\%c' is deprecated",
455 yytext[1]);
456 else loc.warning("Use of unrecognized escape sequence is deprecated");
457 ps->addString(yytext + 1);
458}
459
460"#"{WS}[0-9] {
461 int first_line = current_line, first_column = current_column;
462 UPDATE_LOCATION(0, yyleng);
463 if (in_set) {
464 Location loc(current_file, first_line, first_column, current_line,
465 current_column);
466 loc.error("Number of repetitions `#n' cannot be given inside a set "
467 "expression");
468 } else if (yytext[yyleng - 1] != '1') {
469 ps->addChar('#');
470 ps->addChar(yytext[yyleng - 1]);
471 }
472}
473
474"#"{WS}"("{WS}{NUMBER}{WS}")" {
475 if (in_set) {
476 int first_line = current_line, first_column = current_column;
477 UPDATE_LOCATION(0, yyleng);
478 Location loc(current_file, first_line, first_column, current_line,
479 current_column);
480 loc.error("Number of repetitions `#(n)' cannot be given inside a set "
481 "expression");
482 } else {
3abe9331 483 size_t number_begin = 2;
970ed795
EL
484 while (!isdigit(yytext[number_begin])) number_begin++;
485 UPDATE_LOCATION(0, number_begin);
486 int number_len = 1;
487 while (isdigit(yytext[number_begin + number_len])) number_len++;
488 string number_str(number_len, yytext + number_begin);
489 Location number_loc(current_file, current_line, current_column,
490 current_line, current_column + number_len);
491 UPDATE_LOCATION(number_begin, yyleng);
492 Int number = string2Int(number_str, number_loc);
493 if (number < 0) {
494 number_loc.error("A non-negative integer value was expected as the "
495 "number of repetitions instead of %s", Int2string(number).c_str());
496 } else if (number != 1) ps->addString("#(" + Int2string(number) + ")");
497 }
498}
499
500"#"{WS}"("{WS}{NUMBER}{WS}","{WS}{NUMBER}{WS}")" {
501 int first_line = current_line, first_column = current_column;
502 if (in_set) {
503 UPDATE_LOCATION(0, yyleng);
504 Location loc(current_file, first_line, first_column, current_line,
505 current_column);
506 loc.error("Number of repetitions `#(n,m)' cannot be given inside a set "
507 "expression");
508 } else {
3abe9331 509 size_t lower_begin = 2;
970ed795
EL
510 while (!isdigit(yytext[lower_begin])) lower_begin++;
511 UPDATE_LOCATION(0, lower_begin);
512 int lower_len = 1;
513 while (isdigit(yytext[lower_begin + lower_len])) lower_len++;
514 string lower_str(lower_len, yytext + lower_begin);
515 Location lower_loc(current_file, current_line, current_column,
516 current_line, current_column + lower_len);
517 Int lower = string2Int(lower_str, lower_loc);
518 if (lower < 0) {
519 lower_loc.error("A non-negative integer value was expected as the "
520 "minimum number of repetitions instead of %s",
521 Int2string(lower).c_str());
522 lower = 0;
523 }
3abe9331 524 size_t upper_begin = lower_begin + lower_len + 1;
970ed795
EL
525 while (!isdigit(yytext[upper_begin])) upper_begin++;
526 UPDATE_LOCATION(lower_begin, upper_begin);
527 int upper_len = 1;
528 while (isdigit(yytext[upper_begin + upper_len])) upper_len++;
529 string upper_str(upper_len, yytext + upper_begin);
530 Location upper_loc(current_file, current_line, current_column,
531 current_line, current_column + upper_len);
532 UPDATE_LOCATION(upper_begin, yyleng);
533 Int upper = string2Int(upper_str, upper_loc);
534 if (upper < 0) {
535 upper_loc.error("A non-negative integer value was expected as the "
536 "maximum number of repetitions instead of %s",
537 Int2string(upper).c_str());
538 } else if (lower > upper) {
539 Location loc(current_file, first_line, first_column, current_line,
540 current_column);
541 loc.error("The lower bound is higher than the upper bound in the number "
542 "of repetitions: `#(%s,%s)'", Int2string(lower).c_str(),
543 Int2string(upper).c_str());
544 } else if (lower == upper) {
545 if (lower != 1) ps->addString("#(" + Int2string(lower) + ")");
546 } else {
547 if (lower == 0) ps->addString("#(," + Int2string(upper) + ")");
548 else ps->addString("#(" + Int2string(lower) + "," + Int2string(upper) +
549 ")");
550 }
551 }
552}
553
554"#"{WS}"("{WS}{NUMBER}{WS}","{WS}")" {
555 if (in_set) {
556 int first_line = current_line, first_column = current_column;
557 UPDATE_LOCATION(0, yyleng);
558 Location loc(current_file, first_line, first_column, current_line,
559 current_column);
560 loc.error("Number of repetitions `#(n,)' cannot be given inside a set "
561 "expression");
562 } else {
3abe9331 563 size_t lower_begin = 2;
970ed795
EL
564 while (!isdigit(yytext[lower_begin])) lower_begin++;
565 UPDATE_LOCATION(0, lower_begin);
566 int lower_len = 1;
567 while (isdigit(yytext[lower_begin + lower_len])) lower_len++;
568 string lower_str(lower_len, yytext + lower_begin);
569 Location lower_loc(current_file, current_line, current_column,
570 current_line, current_column + lower_len);
571 UPDATE_LOCATION(lower_begin, yyleng);
572 Int lower = string2Int(lower_str, lower_loc);
573 if (lower < 0) {
574 lower_loc.error("A non-negative integer value was expected as the "
575 "minimum number of repetitions instead of %s",
576 Int2string(lower).c_str());
577 } else if (lower == 1) ps->addChar('+');
578 else ps->addString("#(" + Int2string(lower) + ",)");
579 }
580}
581
582"#"{WS}"("{WS}","{WS}{NUMBER}{WS}")" {
583 if (in_set) {
584 int first_line = current_line, first_column = current_column;
585 UPDATE_LOCATION(0, yyleng);
586 Location loc(current_file, first_line, first_column, current_line,
587 current_column);
588 loc.error("Number of repetitions `#(,m)' cannot be given inside a set "
589 "expression");
590 } else {
3abe9331 591 size_t upper_begin = 3;
970ed795
EL
592 while (!isdigit(yytext[upper_begin])) upper_begin++;
593 UPDATE_LOCATION(0, upper_begin);
594 int upper_len = 1;
595 while (isdigit(yytext[upper_begin + upper_len])) upper_len++;
596 string upper_str(upper_len, yytext + upper_begin);
597 Location upper_loc(current_file, current_line, current_column,
598 current_line, current_column + upper_len);
599 UPDATE_LOCATION(upper_begin, yyleng);
600 Int upper = string2Int(upper_str, upper_loc);
601 if (upper < 0) {
602 upper_loc.error("A non-negative integer value was expected as the "
603 "maximum number of repetitions instead of %s",
604 Int2string(upper).c_str());
605 } else ps->addString("#(," + Int2string(upper) + ")");
606 }
607}
608
609"#"{WS}"("{WS}","{WS}")" {
610 int first_line = current_line, first_column = current_column;
611 UPDATE_LOCATION(0, yyleng);
612 if (in_set) {
613 Location loc(current_file, first_line, first_column, current_line,
614 current_column);
615 loc.error("Number of repetitions `#(,)' cannot be given inside a set "
616 "expression");
617 } else ps->addString("#(,)");
618}
619
620"#"{WS}"("[^)]*")" {
621 int first_line = current_line, first_column = current_column;
622 UPDATE_LOCATION(0, yyleng);
623 Location loc(current_file, first_line, first_column, current_line,
624 current_column);
625 loc.error("Invalid notation for the number of repetitions: `%s'", yytext);
626}
627
628"#" {
629 Location loc(current_file, current_line, current_column, current_line,
630 current_column + 1);
631 if (in_set) {
632 loc.warning("Unescaped `#' inside character set was treated literally");
633 ps->addChar('\\');
634 ps->addChar('#');
635 } else {
636 loc.error("Syntax error in the number of repetitions `#...'");
637 }
638 current_column++;
639}
640
641"+" {
642 if (in_set) {
643 Location loc(current_file, current_line, current_column, current_line,
644 current_column + 1);
645 loc.warning("Unescaped `+' inside character set was treated literally");
646 ps->addChar('\\');
647 }
648 ps->addChar('+');
649 current_column++;
650}
651
652.|{NEWLINE} {
653 ps->addString(yytext);
654 UPDATE_LOCATION(0, yyleng);
655}
656
657<<EOF>> {
658 if (in_set) {
659 Location loc(current_file, current_line, current_column, current_line,
660 current_column + 1);
661 loc.error("Missing `]' at the end of the string");
662 ps->addChar(']');
663 }
664 return ps;
665}
666
667%%
668
669PatternString* parse_pattern(const char *str, const Location& p_loc)
670{
671 Error_Context cntxt(&p_loc, "In character string pattern");
672 struct yy_buffer_state *flex_buffer=pstring_yy_scan_string(str);
673 if (!flex_buffer) {
674 FATAL_ERROR("parse_pattern(): flex buffer creation failed");
675 return 0;
676 }
677
678 PatternString *ps = yylex(p_loc.get_filename(), p_loc.get_first_line(),
679 p_loc.get_first_column() + 1);
680 pstring_yylex_destroy();
681
682 return ps;
683}
This page took 0.050511 seconds and 5 git commands to generate.