forked from uncrustify/uncrustify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenize.cpp
More file actions
1732 lines (1559 loc) · 38.4 KB
/
tokenize.cpp
File metadata and controls
1732 lines (1559 loc) · 38.4 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file tokenize.cpp
* This file breaks up the text stream into tokens or chunks.
*
* Each routine needs to set pc.len and pc.type.
*
* @author Ben Gardner
* @license GPL v2+
*/
#include "uncrustify_types.h"
#include "char_table.h"
#include "prototypes.h"
#include "chunk_list.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include "unc_ctype.h"
struct tok_info
{
tok_info() : last_ch(0), idx(0), row(1), col(1)
{
}
int last_ch;
int idx;
int row;
int col;
};
struct tok_ctx
{
tok_ctx(const deque<int>& d) : data(d)
{
}
/* save before trying to parse something that may fail */
void save()
{
save(s);
}
void save(tok_info& info)
{
info = c;
}
/* restore previous saved state */
void restore()
{
restore(s);
}
void restore(const tok_info& info)
{
c = info;
}
bool more()
{
return(c.idx < (int)data.size());
}
int peek()
{
return(more() ? data[c.idx] : -1);
}
int peek(int idx)
{
idx += c.idx;
return((idx < (int)data.size()) ? data[idx] : -1);
}
int get()
{
if (more())
{
int ch = data[c.idx++];
switch (ch)
{
case '\t':
c.col = calc_next_tab_column(c.col, cpd.settings[UO_input_tab_size].n);
break;
case '\n':
if (c.last_ch != '\r')
{
c.row++;
c.col = 1;
}
break;
case '\r':
c.row++;
c.col = 1;
break;
default:
c.col++;
break;
}
c.last_ch = ch;
return ch;
}
return -1;
}
bool expect(int ch)
{
if (peek() == ch)
{
get();
return true;
}
return false;
}
const deque<int>& data;
tok_info c; /* current */
tok_info s; /* saved */
};
static bool parse_string(tok_ctx& ctx, chunk_t& pc, int quote_idx, bool allow_escape);
/**
* Parses all legal D string constants.
*
* Quoted strings:
* r"Wysiwyg" # WYSIWYG string
* x"hexstring" # Hexadecimal array
* `Wysiwyg` # WYSIWYG string
* 'char' # single character
* "reg_string" # regular string
*
* Non-quoted strings:
* \x12 # 1-byte hex constant
* \u1234 # 2-byte hex constant
* \U12345678 # 4-byte hex constant
* \123 # octal constant
* \& # named entity
* \n # single character
*
* @param pc The structure to update, str is an input.
* @return Whether a string was parsed
*/
static bool d_parse_string(tok_ctx& ctx, chunk_t& pc)
{
int ch = ctx.peek();
if ((ch == '"') || (ch == '\'') || (ch == '`'))
{
return(parse_string(ctx, pc, 0, true));
}
else if (ch == '\\')
{
ctx.save();
int cnt;
pc.str.clear();
while (ctx.peek() == '\\')
{
pc.str.append(ctx.get());
/* Check for end of file */
switch (ctx.peek())
{
case 'x':
/* \x HexDigit HexDigit */
cnt = 3;
while (cnt--)
{
pc.str.append(ctx.get());
}
break;
case 'u':
/* \u HexDigit HexDigit HexDigit HexDigit */
cnt = 5;
while (cnt--)
{
pc.str.append(ctx.get());
}
break;
case 'U':
/* \U HexDigit (x8) */
cnt = 9;
while (cnt--)
{
pc.str.append(ctx.get());
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
/* handle up to 3 octal digits */
pc.str.append(ctx.get());
ch = ctx.peek();
if ((ch >= '0') && (ch <= '7'))
{
pc.str.append(ctx.get());
ch = ctx.peek();
if ((ch >= '0') && (ch <= '7'))
{
pc.str.append(ctx.get());
}
}
break;
case '&':
/* \& NamedCharacterEntity ; */
pc.str.append(ctx.get());
while (unc_isalpha(ctx.peek()))
{
pc.str.append(ctx.get());
}
if (ctx.peek() == ';')
{
pc.str.append(ctx.get());
}
break;
default:
/* Everything else is a single character */
pc.str.append(ctx.get());
break;
}
}
if (pc.str.size() > 1)
{
pc.type = CT_STRING;
return(true);
}
ctx.restore();
}
else if (((ch == 'r') || (ch == 'x')) && (ctx.peek(1) == '"'))
{
return(parse_string(ctx, pc, 1, false));
}
return(false);
}
// /**
// * A string-in-string search. Like strstr() with a haystack length.
// */
// static const char *str_search(const char *needle, const char *haystack, int haystack_len)
// {
// int needle_len = strlen(needle);
//
// while (haystack_len-- >= needle_len)
// {
// if (memcmp(needle, haystack, needle_len) == 0)
// {
// return(haystack);
// }
// haystack++;
// }
// return(NULL);
// }
/**
* Figure of the length of the comment at text.
* The next bit of text starts with a '/', so it might be a comment.
* There are three types of comments:
* - C comments that start with '/ *' and end with '* /'
* - C++ comments that start with //
* - D nestable comments '/+' '+/'
*
* @param pc The structure to update, str is an input.
* @return Whether a comment was parsed
*/
static bool parse_comment(tok_ctx& ctx, chunk_t& pc)
{
int ch;
bool is_d = (cpd.lang_flags & LANG_D) != 0;
int d_level = 0;
int bs_cnt;
/* does this start with '/ /' or '/ *' or '/ +' (d) */
if ((ctx.peek() != '/') ||
((ctx.peek(1) != '*') && (ctx.peek(1) != '/') &&
((ctx.peek(1) != '+') || !is_d)))
{
return(false);
}
ctx.save();
/* account for opening two chars */
pc.str = ctx.get(); /* opening '/' */
ch = ctx.get();
pc.str.append(ch); /* second char */
if (ch == '/')
{
pc.type = CT_COMMENT_CPP;
while (true)
{
bs_cnt = 0;
while (ctx.more())
{
ch = ctx.peek();
if ((ch == '\r') || (ch == '\n'))
{
break;
}
if (ch == '\\')
{
bs_cnt++;
}
else
{
bs_cnt = 0;
}
pc.str.append(ctx.get());
}
/* If we hit an odd number of backslashes right before the newline,
* then we keep going.
*/
if (((bs_cnt & 1) == 0) || !ctx.more())
{
break;
}
if (ctx.peek() == '\r')
{
pc.str.append(ctx.get());
}
if (ctx.peek() == '\n')
{
pc.str.append(ctx.get());
}
pc.nl_count++;
cpd.did_newline = true;
}
}
else if (!ctx.more())
{
/* unexpected end of file */
ctx.restore();
return(false);
}
else if (ch == '+')
{
pc.type = CT_COMMENT;
d_level++;
while ((d_level > 0) && ctx.more())
{
if ((ctx.peek() == '+') && (ctx.peek(1) == '/'))
{
pc.str.append(ctx.get()); /* store the '+' */
pc.str.append(ctx.get()); /* store the '/' */
d_level--;
continue;
}
if ((ctx.peek() == '/') && (ctx.peek(1) == '+'))
{
pc.str.append(ctx.get()); /* store the '/' */
pc.str.append(ctx.get()); /* store the '+' */
d_level++;
continue;
}
ch = ctx.get();
pc.str.append(ch);
if ((ch == '\n') || (ch == '\r'))
{
pc.type = CT_COMMENT_MULTI;
pc.nl_count++;
if (ch == '\r')
{
if (ctx.peek() == '\n')
{
cpd.le_counts[LE_CRLF]++;
pc.str.append(ctx.get()); /* store the '\n' */
}
else
{
cpd.le_counts[LE_CR]++;
}
}
else
{
cpd.le_counts[LE_LF]++;
}
}
}
}
else /* must be '/ *' */
{
pc.type = CT_COMMENT;
while (ctx.more())
{
if ((ctx.peek() == '*') && (ctx.peek(1) == '/'))
{
pc.str.append(ctx.get()); /* store the '*' */
pc.str.append(ctx.get()); /* store the '/' */
tok_info ss;
ctx.save(ss);
int oldsize = pc.str.size();
/* If there is another C comment right after this one, combine them */
while ((ctx.peek() == ' ') || (ctx.peek() == '\t'))
{
pc.str.append(ctx.get());
}
if ((ctx.peek() != '/') || (ctx.peek(1) != '*'))
{
/* undo the attempt to join */
ctx.restore(ss);
pc.str.resize(oldsize);
break;
}
}
ch = ctx.get();
pc.str.append(ch);
if ((ch == '\n') || (ch == '\r'))
{
pc.type = CT_COMMENT_MULTI;
pc.nl_count++;
if (ch == '\r')
{
if (ctx.peek() == '\n')
{
cpd.le_counts[LE_CRLF]++;
pc.str.append(ctx.get()); /* store the '\n' */
}
else
{
cpd.le_counts[LE_CR]++;
}
}
else
{
cpd.le_counts[LE_LF]++;
}
}
}
}
if (cpd.unc_off)
{
if (pc.str.find(UNCRUSTIFY_ON_TEXT) >= 0)
{
LOG_FMT(LBCTRL, "Found '%s' on line %d\n", UNCRUSTIFY_ON_TEXT, pc.orig_line);
cpd.unc_off = false;
}
}
else
{
if (pc.str.find(UNCRUSTIFY_OFF_TEXT) >= 0)
{
LOG_FMT(LBCTRL, "Found '%s' on line %d\n", UNCRUSTIFY_OFF_TEXT, pc.orig_line);
cpd.unc_off = true;
}
}
return(true);
}
/**
* Figure of the length of the code placeholder at text, if present.
* This is only for Xcode which sometimes inserts temporary code placeholder chunks, which in plaintext <#look like this#>.
*
* @param pc The structure to update, str is an input.
* @return Whether a placeholder was parsed.
*/
static bool parse_code_placeholder(tok_ctx& ctx, chunk_t& pc)
{
int last2 = 0, last1 = 0;
if ((ctx.peek() != '<') || (ctx.peek(1) != '#'))
{
return(false);
}
ctx.save();
/* account for opening two chars '<#' */
pc.str = ctx.get();
pc.str.append(ctx.get());
/* grab everything until '#>', fail if not found. */
while (ctx.more())
{
last2 = last1;
last1 = ctx.get();
pc.str.append(last1);
if ((last2 == '#') && (last1 == '>'))
{
pc.type = CT_WORD;
return(true);
}
}
ctx.restore();
return(false);
}
/**
* Parse any attached suffix, which may be a user-defined literal suffix.
* If for a string, explicitly exclude common format and scan specifiers, ie,
* PRIx32 and SCNx64.
*/
static void parse_suffix(tok_ctx& ctx, chunk_t& pc, bool forstring = false)
{
if (CharTable::IsKw1(ctx.peek()))
{
int slen = 0;
int oldsize = pc.str.size();
tok_info ss;
/* don't add the suffix if we see L" or L' or S" */
int p1 = ctx.peek();
int p2 = ctx.peek(1);
if (forstring &&
(((p1 == 'L') && ((p2 == '"') || (p2 == '\''))) ||
((p1 == 'S') && (p2 == '"'))))
{
return;
}
ctx.save(ss);
while (ctx.more() && CharTable::IsKw2(ctx.peek()))
{
slen++;
pc.str.append(ctx.get());
}
if (forstring && (slen >= 4) &&
(pc.str.startswith("PRI", oldsize) ||
pc.str.startswith("SCN", oldsize)))
{
ctx.restore(ss);
pc.str.resize(oldsize);
}
}
}
static bool is_bin(int ch)
{
return((ch == '0') || (ch == '1'));
}
static bool is_bin_(int ch)
{
return(is_bin(ch) || (ch == '_'));
}
static bool is_oct(int ch)
{
return((ch >= '0') && (ch <= '7'));
}
static bool is_oct_(int ch)
{
return(is_oct(ch) || (ch == '_'));
}
static bool is_dec(int ch)
{
return((ch >= '0') && (ch <= '9'));
}
static bool is_dec_(int ch)
{
return(is_dec(ch) || (ch == '_'));
}
static bool is_hex(int ch)
{
return(((ch >= '0') && (ch <= '9')) ||
((ch >= 'a') && (ch <= 'f')) ||
((ch >= 'A') && (ch <= 'F')));
}
static bool is_hex_(int ch)
{
return(is_hex(ch) || (ch == '_'));
}
/**
* Count the number of characters in the number.
* The next bit of text starts with a number (0-9 or '.'), so it is a number.
* Count the number of characters in the number.
*
* This should cover all number formats for all languages.
* Note that this is not a strict parser. It will happily parse numbers in
* an invalid format.
*
* For example, only D allows underscores in the numbers, but they are
* allowed in all formats.
*
* @param pc The structure to update, str is an input.
* @return Whether a number was parsed
*/
static bool parse_number(tok_ctx& ctx, chunk_t& pc)
{
int tmp;
bool is_float;
bool did_hex = false;
/* A number must start with a digit or a dot, followed by a digit */
if (!is_dec(ctx.peek()) &&
((ctx.peek() != '.') || !is_dec(ctx.peek(1))))
{
return(false);
}
is_float = (ctx.peek() == '.');
if (is_float && (ctx.peek(1) == '.'))
{
return(false);
}
/* Check for Hex, Octal, or Binary
* Note that only D and Pawn support binary, but who cares?
*/
if (ctx.peek() == '0')
{
pc.str.append(ctx.get()); /* store the '0' */
switch (unc_toupper(ctx.peek()))
{
case 'X': /* hex */
did_hex = true;
do
{
pc.str.append(ctx.get()); /* store the 'x' and then the rest */
} while (is_hex_(ctx.peek()));
break;
case 'B': /* binary */
do
{
pc.str.append(ctx.get()); /* store the 'b' and then the rest */
} while (is_bin_(ctx.peek()));
break;
case '0': /* octal or decimal */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
do
{
pc.str.append(ctx.get());
} while (is_oct_(ctx.peek()));
break;
default:
/* either just 0 or 0.1 or 0UL, etc */
break;
}
}
else
{
/* Regular int or float */
while (is_dec_(ctx.peek()))
{
pc.str.append(ctx.get());
}
}
/* Check if we stopped on a decimal point & make sure it isn't '..' */
if ((ctx.peek() == '.') && (ctx.peek(1) != '.'))
{
pc.str.append(ctx.get());
is_float = true;
if (did_hex)
{
while (is_hex_(ctx.peek()))
{
pc.str.append(ctx.get());
}
}
else
{
while (is_dec_(ctx.peek()))
{
pc.str.append(ctx.get());
}
}
}
/* Check exponent
* Valid exponents per language (not that it matters):
* C/C++/D/Java: eEpP
* C#/Pawn: eE
*/
tmp = unc_toupper(ctx.peek());
if ((tmp == 'E') || (tmp == 'P'))
{
is_float = true;
pc.str.append(ctx.get());
if ((ctx.peek() == '+') || (ctx.peek() == '-'))
{
pc.str.append(ctx.get());
}
while (is_dec_(ctx.peek()))
{
pc.str.append(ctx.get());
}
}
/* Check the suffixes
* Valid suffixes per language (not that it matters):
* Integer Float
* C/C++: uUlL64 lLfF
* C#: uUlL fFdDMm
* D: uUL ifFL
* Java: lL fFdD
* Pawn: (none) (none)
*
* Note that i, f, d, and m only appear in floats.
*/
while (1)
{
tmp = unc_toupper(ctx.peek());
if ((tmp == 'I') || (tmp == 'F') || (tmp == 'D') || (tmp == 'M'))
{
is_float = true;
}
else if ((tmp != 'L') && (tmp != 'U'))
{
break;
}
pc.str.append(ctx.get());
}
/* skip the Microsoft-specific '64' suffix */
if ((ctx.peek() == '6') && (ctx.peek(1) == '4'))
{
pc.str.append(ctx.get());
pc.str.append(ctx.get());
}
pc.type = is_float ? CT_NUMBER_FP : CT_NUMBER;
/* If there is anything left, then we are probably dealing with garbage or
* some sick macro junk. Eat it.
*/
parse_suffix(ctx, pc);
return(true);
}
/**
* Count the number of characters in a quoted string.
* The next bit of text starts with a quote char " or ' or <.
* Count the number of characters until the matching character.
*
* @param pc The structure to update, str is an input.
* @return Whether a string was parsed
*/
static bool parse_string(tok_ctx& ctx, chunk_t& pc, int quote_idx, bool allow_escape)
{
bool escaped = 0;
int end_ch;
char escape_char = cpd.settings[UO_string_escape_char].n;
char escape_char2 = cpd.settings[UO_string_escape_char2].n;
pc.str.clear();
while (quote_idx-- > 0)
{
pc.str.append(ctx.get());
}
pc.type = CT_STRING;
end_ch = CharTable::Get(ctx.peek()) & 0xff;
pc.str.append(ctx.get()); /* store the " */
while (ctx.more())
{
int ch = ctx.get();
pc.str.append(ch);
if (ch == '\n')
{
pc.nl_count++;
pc.type = CT_STRING_MULTI;
escaped = 0;
continue;
}
if ((ch == '\r') && (ctx.peek() != '\n'))
{
pc.str.append(ctx.get());
pc.nl_count++;
pc.type = CT_STRING_MULTI;
escaped = 0;
continue;
}
if (!escaped)
{
if (ch == escape_char)
{
escaped = (escape_char != 0);
}
else if ((ch == escape_char2) && (ctx.peek() == end_ch))
{
escaped = allow_escape;
}
else if (ch == end_ch)
{
break;
}
}
else
{
escaped = false;
}
}
parse_suffix(ctx, pc, true);
return(true);
}
/**
* Literal string, ends with single "
* Two "" don't end the string.
*
* @param pc The structure to update, str is an input.
* @return Whether a string was parsed
*/
static bool parse_cs_string(tok_ctx& ctx, chunk_t& pc)
{
pc.str = ctx.get();
pc.str.append(ctx.get());
pc.type = CT_STRING;
/* go until we hit a zero (end of file) or a single " */
while (ctx.more())
{
int ch = ctx.get();
pc.str.append(ch);
if ((ch == '\n') || (ch == '\r'))
{
pc.type = CT_STRING_MULTI;
pc.nl_count++;
}
if (ch == '"')
{
if (ctx.peek() == '"')
{
pc.str.append(ctx.get());
}
else
{
break;
}
}
}
return(true);
}
/**
* VALA verbatim string, ends with three quotes (""")
*
* @param pc The structure to update, str is an input.
*/
static void parse_verbatim_string(tok_ctx& ctx, chunk_t& pc)
{
pc.type = CT_STRING;
// consume the initial """
pc.str = ctx.get();
pc.str.append(ctx.get());
pc.str.append(ctx.get());
/* go until we hit a zero (end of file) or a """ */
while (ctx.more())
{
int ch = ctx.get();
pc.str.append(ch);
if ((ch == '"') &&
(ctx.peek() == '"') &&
(ctx.peek(1) == '"'))
{
pc.str.append(ctx.get());
pc.str.append(ctx.get());
break;
}
if ((ch == '\n') || (ch == '\r'))
{
pc.type = CT_STRING_MULTI;
pc.nl_count++;
}
}
}
static bool tag_compare(const deque<int>& d, int a_idx, int b_idx, int len)
{
if (a_idx != b_idx)
{
while (len-- > 0)
{
if (d[a_idx] != d[b_idx])
{
return false;
}
}
}
return true;
}
/**
* Parses a C++0x 'R' string. R"( xxx )" R"tag( )tag" u8R"(x)" uR"(x)"
* Newlines may be in the string.
*/
static bool parse_cr_string(tok_ctx& ctx, chunk_t& pc, int q_idx)
{
int cnt;
int tag_idx = ctx.c.idx + q_idx + 1;
int tag_len = 0;
ctx.save();
/* Copy the prefix + " to the string */
pc.str.clear();
cnt = q_idx + 1;
while (cnt--)
{
pc.str.append(ctx.get());
}
/* Add the tag and get the length of the tag */
while (ctx.more() && (ctx.peek() != '('))
{
tag_len++;
pc.str.append(ctx.get());
}
if (ctx.peek() != '(')
{
ctx.restore();
return(false);
}
pc.type = CT_STRING;
while (ctx.more())
{
if ((ctx.peek() == ')') &&
(ctx.peek(tag_len + 1) == '"') &&
tag_compare(ctx.data, tag_idx, ctx.c.idx + 1, tag_len))
{
cnt = tag_len + 2; /* for the )" */
while (cnt--)
{
pc.str.append(ctx.get());
}
parse_suffix(ctx, pc);
return(true);
}
if (ctx.peek() == '\n')
{
pc.str.append(ctx.get());
pc.nl_count++;
pc.type = CT_STRING_MULTI;
}
else
{
pc.str.append(ctx.get());
}
}
ctx.restore();
return(false);
}
/**
* Count the number of characters in a word.
* The first character is already valid for a keyword
*
* @param pc The structure to update, str is an input.
* @return Whether a word was parsed (always true)
*/
bool parse_word(tok_ctx& ctx, chunk_t& pc, bool skipcheck)
{