-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtsparser.c
2607 lines (2341 loc) · 75.5 KB
/
tsparser.c
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
/*-------------------------------------------------------------------------
*
* tsparser.c
* Text search parser as extension
*
* Portions Copyright (c) 2015-2016, Postgres Professional
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include <limits.h>
#include <wctype.h>
#include "catalog/pg_collation.h"
#include "commands/defrem.h"
#include "mb/pg_wchar.h"
#include "tsearch/ts_public.h"
#include "tsearch/ts_type.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/pg_locale.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(tsparser_start);
PG_FUNCTION_INFO_V1(tsparser_nexttoken);
PG_FUNCTION_INFO_V1(tsparser_end);
PG_FUNCTION_INFO_V1(tsparser_lextype);
PG_FUNCTION_INFO_V1(tsparser_headline);
/* Define me to enable tracing of parser behavior */
/* #define WPARSER_TRACE */
/* Output token categories */
#define ASCIIWORD 1
#define WORD_T 2
#define NUMWORD 3
#define EMAIL 4
#define URL_T 5
#define HOST 6
#define SCIENTIFIC 7
#define VERSIONNUMBER 8
#define NUMPARTHWORD 9
#define PARTHWORD 10
#define ASCIIPARTHWORD 11
#define SPACE 12
#define TAG_T 13
#define PROTOCOL 14
#define NUMHWORD 15
#define ASCIIHWORD 16
#define HWORD 17
#define URLPATH 18
#define FILEPATH 19
#define DECIMAL_T 20
#define SIGNEDINT 21
#define UNSIGNEDINT 22
#define XMLENTITY 23
#define LASTNUM 23
static const char *const tok_alias[] = {
"",
"asciiword",
"word",
"numword",
"email",
"url",
"host",
"sfloat",
"version",
"hword_numpart",
"hword_part",
"hword_asciipart",
"blank",
"tag",
"protocol",
"numhword",
"asciihword",
"hword",
"url_path",
"file",
"float",
"int",
"uint",
"entity"
};
static const char *const lex_descr[] = {
"",
"Word, all ASCII",
"Word, all letters",
"Word, letters and digits",
"Email address",
"URL",
"Host",
"Scientific notation",
"Version number",
"Hyphenated word part, letters and digits",
"Hyphenated word part, all letters",
"Hyphenated word part, all ASCII",
"Space symbols",
"XML tag",
"Protocol head",
"Hyphenated word, letters and digits",
"Hyphenated word, all ASCII",
"Hyphenated word, all letters",
"URL path",
"File or path name",
"Decimal notation",
"Signed integer",
"Unsigned integer",
"XML entity"
};
/* Parser states */
typedef enum
{
TPS_Base = 0,
TPS_InNumWord,
TPS_InAsciiWord,
TPS_InWord,
TPS_InUnsignedInt,
TPS_InSignedIntFirst,
TPS_InSignedInt,
TPS_InSpace,
TPS_InUDecimalFirst,
TPS_InUDecimal,
TPS_InDecimalFirst,
TPS_InDecimal,
TPS_InVerVersion,
TPS_InSVerVersion,
TPS_InVersionFirst,
TPS_InVersion,
TPS_InMantissaFirst,
TPS_InMantissaSign,
TPS_InMantissa,
TPS_InXMLEntityFirst,
TPS_InXMLEntity,
TPS_InXMLEntityNumFirst,
TPS_InXMLEntityNum,
TPS_InXMLEntityHexNumFirst,
TPS_InXMLEntityHexNum,
TPS_InXMLEntityEnd,
TPS_InTagFirst,
TPS_InXMLBegin,
TPS_InTagCloseFirst,
TPS_InTagName,
TPS_InTagBeginEnd,
TPS_InTag,
TPS_InTagEscapeK,
TPS_InTagEscapeKK,
TPS_InTagBackSleshed,
TPS_InTagEnd,
TPS_InCommentFirst,
TPS_InCommentLast,
TPS_InComment,
TPS_InCloseCommentFirst,
TPS_InCloseCommentLast,
TPS_InCommentEnd,
TPS_InHostFirstDomain,
TPS_InHostDomainSecond,
TPS_InHostDomain,
TPS_InPortFirst,
TPS_InPort,
TPS_InHostFirstAN,
TPS_InHost,
TPS_InHostAsciiWord,
TPS_InHostNumWord,
TPS_InEmail,
TPS_InFileFirst,
TPS_InFileTwiddle,
TPS_InPathFirst,
TPS_InPathFirstFirst,
TPS_InPathSecond,
TPS_InFile,
TPS_InFileNext,
TPS_InURLPathFirst,
TPS_InURLPathStart,
TPS_InURLPath,
TPS_InFURL,
TPS_InProtocolFirst,
TPS_InProtocolSecond,
TPS_InProtocolEnd,
TPS_InHyphenAsciiWordFirst,
TPS_InHyphenAsciiWord,
TPS_InHyphenWordFirst,
TPS_InHyphenWord,
TPS_InHyphenNumWordFirst,
TPS_InHyphenNumWord,
TPS_InHyphenDigitLookahead,
TPS_InParseHyphen,
TPS_InParseHyphenHyphen,
TPS_InHyphenWordPart,
TPS_InHyphenAsciiWordPart,
TPS_InHyphenNumWordPart,
TPS_InHyphenUnsignedInt,
TPS_Null /* last state (fake value) */
} TParserState;
/* forward declaration */
struct TParser;
typedef int (*TParserCharTest) (struct TParser *); /* any p_is* functions
* except p_iseq */
typedef void (*TParserSpecial) (struct TParser *); /* special handler for
* special cases... */
typedef struct
{
TParserCharTest isclass;
char c;
uint16 flags;
TParserState tostate;
int type;
TParserSpecial special;
} TParserStateActionItem;
/* Flag bits in TParserStateActionItem.flags */
#define A_NEXT 0x0000
#define A_BINGO 0x0001
#define A_POP 0x0002
#define A_PUSH 0x0004
#define A_RERUN 0x0008
#define A_CLEAR 0x0010
#define A_MERGE 0x0020
#define A_CLRALL 0x0040
typedef struct TParserPosition
{
int posbyte; /* position of parser in bytes */
int poschar; /* position of parser in characters */
int charlen; /* length of current char */
int lenbytetoken; /* length of token-so-far in bytes */
int lenchartoken; /* and in chars */
TParserState state;
struct TParserPosition *prev;
const TParserStateActionItem *pushedAtAction;
} TParserPosition;
typedef struct TParser
{
/* string and position information */
char *str; /* multibyte string */
int lenstr; /* length of mbstring */
wchar_t *wstr; /* wide character string */
pg_wchar *pgwstr; /* wide character string for C-locale */
bool usewide;
/* State of parse */
int charmaxlen;
TParserPosition *state;
bool ignore;
bool wanthost;
/* silly char */
char c;
/* out */
char *token;
int lenbytetoken;
int lenchartoken;
int type;
} TParser;
#if PG_VERSION_NUM < 120000
#define pg_strtoint32(value) pg_atoi((value), sizeof(int32), 0)
#endif
/* forward decls here */
static bool TParserGet(TParser *prs);
static TParserPosition *
newTParserPosition(TParserPosition *prev)
{
TParserPosition *res = (TParserPosition *) palloc(sizeof(TParserPosition));
if (prev)
memcpy(res, prev, sizeof(TParserPosition));
else
memset(res, 0, sizeof(TParserPosition));
res->prev = prev;
res->pushedAtAction = NULL;
return res;
}
static TParser *
TParserInit(char *str, int len)
{
TParser *prs = (TParser *) palloc0(sizeof(TParser));
prs->charmaxlen = pg_database_encoding_max_length();
prs->str = str;
prs->lenstr = len;
/*
* Use wide char code only when max encoding length > 1.
*/
if (prs->charmaxlen > 1)
{
pg_locale_t mylocale = 0; /* TODO */
prs->usewide = true;
#if PG_VERSION_NUM >= 150000 || (defined(PGPRO_STD) && PG_VERSION_NUM >= 120000)
if (database_ctype_is_c)
#else
if (lc_ctype_is_c(DEFAULT_COLLATION_OID))
#endif
{
/*
* char2wchar doesn't work for C-locale and sizeof(pg_wchar) could
* be different from sizeof(wchar_t)
*/
prs->pgwstr = (pg_wchar *) palloc(sizeof(pg_wchar) * (prs->lenstr + 1));
pg_mb2wchar_with_len(prs->str, prs->pgwstr, prs->lenstr);
}
else
{
prs->wstr = (wchar_t *) palloc(sizeof(wchar_t) * (prs->lenstr + 1));
char2wchar(prs->wstr, prs->lenstr + 1, prs->str, prs->lenstr,
mylocale);
}
}
else
prs->usewide = false;
prs->state = newTParserPosition(NULL);
prs->state->state = TPS_Base;
#ifdef WPARSER_TRACE
/*
* Use of %.*s here is a bit risky since it can misbehave if the data is
* not in what libc thinks is the prevailing encoding. However, since
* this is just a debugging aid, we choose to live with that.
*/
fprintf(stderr, "parsing \"%.*s\"\n", len, str);
#endif
return prs;
}
/*
* As an alternative to a full TParserInit one can create a
* TParserCopy which basically is a regular TParser without a private
* copy of the string - instead it uses the one from another TParser.
* This is useful because at some places TParsers are created
* recursively and the repeated copying around of the strings can
* cause major inefficiency if the source string is long.
* The new parser starts parsing at the original's current position.
*
* Obviously one must not close the original TParser before the copy.
*/
static TParser *
TParserCopyInit(const TParser *orig)
{
TParser *prs = (TParser *) palloc0(sizeof(TParser));
prs->charmaxlen = orig->charmaxlen;
prs->str = orig->str + orig->state->posbyte;
prs->lenstr = orig->lenstr - orig->state->posbyte;
prs->usewide = orig->usewide;
if (orig->pgwstr)
prs->pgwstr = orig->pgwstr + orig->state->poschar;
if (orig->wstr)
prs->wstr = orig->wstr + orig->state->poschar;
prs->state = newTParserPosition(NULL);
prs->state->state = TPS_Base;
#ifdef WPARSER_TRACE
/* See note above about %.*s */
fprintf(stderr, "parsing copy of \"%.*s\"\n", prs->lenstr, prs->str);
#endif
return prs;
}
static void
TParserClose(TParser *prs)
{
while (prs->state)
{
TParserPosition *ptr = prs->state->prev;
pfree(prs->state);
prs->state = ptr;
}
if (prs->wstr)
pfree(prs->wstr);
if (prs->pgwstr)
pfree(prs->pgwstr);
#ifdef WPARSER_TRACE
fprintf(stderr, "closing parser\n");
#endif
pfree(prs);
}
/*
* Close a parser created with TParserCopyInit
*/
static void
TParserCopyClose(TParser *prs)
{
while (prs->state)
{
TParserPosition *ptr = prs->state->prev;
pfree(prs->state);
prs->state = ptr;
}
#ifdef WPARSER_TRACE
fprintf(stderr, "closing parser copy\n");
#endif
pfree(prs);
}
/*
* Character-type support functions, equivalent to is* macros, but
* working with any possible encodings and locales. Notes:
* - with multibyte encoding and C-locale isw* function may fail
* or give wrong result.
* - multibyte encoding and C-locale often are used for
* Asian languages.
* - if locale is C then we use pgwstr instead of wstr.
*/
#define p_iswhat(type, nonascii) \
\
static int \
p_is##type(TParser *prs) \
{ \
Assert(prs->state); \
if (prs->usewide) \
{ \
if (prs->pgwstr) \
{ \
unsigned int c = *(prs->pgwstr + prs->state->poschar); \
if (c > 0x7f) \
return nonascii; \
return is##type(c); \
} \
return isw##type(*(prs->wstr + prs->state->poschar)); \
} \
return is##type(*(unsigned char *) (prs->str + prs->state->posbyte)); \
} \
\
static int \
p_isnot##type(TParser *prs) \
{ \
return !p_is##type(prs); \
}
/*
* In C locale with a multibyte encoding, any non-ASCII symbol is considered
* an alpha character, but not a member of other char classes.
*/
p_iswhat(alnum, 1)
p_iswhat(alpha, 1)
p_iswhat(digit, 0)
p_iswhat(lower, 0)
p_iswhat(print, 0)
p_iswhat(punct, 0)
p_iswhat(space, 0)
p_iswhat(upper, 0)
p_iswhat(xdigit, 0)
/* p_iseq should be used only for ascii symbols */
static int
p_iseq(TParser *prs, char c)
{
Assert(prs->state);
return ((prs->state->charlen == 1 && *(prs->str + prs->state->posbyte) == c)) ? 1 : 0;
}
static int
p_isEOF(TParser *prs)
{
Assert(prs->state);
return (prs->state->posbyte == prs->lenstr || prs->state->charlen == 0) ? 1 : 0;
}
static int
p_iseqC(TParser *prs)
{
return p_iseq(prs, prs->c);
}
static int
p_isneC(TParser *prs)
{
return !p_iseq(prs, prs->c);
}
static int
p_isascii(TParser *prs)
{
return (prs->state->charlen == 1 && isascii((unsigned char) *(prs->str + prs->state->posbyte))) ? 1 : 0;
}
static int
p_isasclet(TParser *prs)
{
return (p_isascii(prs) && p_isalpha(prs)) ? 1 : 0;
}
static int
p_isurlchar(TParser *prs)
{
char ch;
/* no non-ASCII need apply */
if (prs->state->charlen != 1)
return 0;
ch = *(prs->str + prs->state->posbyte);
/* no spaces or control characters */
if (ch <= 0x20 || ch >= 0x7F)
return 0;
/* reject characters disallowed by RFC 3986 */
switch (ch)
{
case '"':
case '<':
case '>':
case '\\':
case '^':
case '`':
case '{':
case '|':
case '}':
return 0;
}
return 1;
}
/* deliberately suppress unused-function complaints for the above */
void _make_compiler_happy(void);
void
_make_compiler_happy(void)
{
p_isalnum(NULL);
p_isnotalnum(NULL);
p_isalpha(NULL);
p_isnotalpha(NULL);
p_isdigit(NULL);
p_isnotdigit(NULL);
p_islower(NULL);
p_isnotlower(NULL);
p_isprint(NULL);
p_isnotprint(NULL);
p_ispunct(NULL);
p_isnotpunct(NULL);
p_isspace(NULL);
p_isnotspace(NULL);
p_isupper(NULL);
p_isnotupper(NULL);
p_isxdigit(NULL);
p_isnotxdigit(NULL);
p_isEOF(NULL);
p_iseqC(NULL);
p_isneC(NULL);
}
static void
SpecialTags(TParser *prs)
{
switch (prs->state->lenchartoken)
{
case 8: /* </script */
if (pg_strncasecmp(prs->token, "</script", 8) == 0)
prs->ignore = false;
break;
case 7: /* <script || </style */
if (pg_strncasecmp(prs->token, "</style", 7) == 0)
prs->ignore = false;
else if (pg_strncasecmp(prs->token, "<script", 7) == 0)
prs->ignore = true;
break;
case 6: /* <style */
if (pg_strncasecmp(prs->token, "<style", 6) == 0)
prs->ignore = true;
break;
default:
break;
}
}
static void
SpecialFURL(TParser *prs)
{
prs->wanthost = true;
prs->state->posbyte -= prs->state->lenbytetoken;
prs->state->poschar -= prs->state->lenchartoken;
}
static void
SpecialHyphen(TParser *prs)
{
prs->state->posbyte -= prs->state->lenbytetoken;
prs->state->poschar -= prs->state->lenchartoken;
}
static void
SpecialVerVersion(TParser *prs)
{
prs->state->posbyte -= prs->state->lenbytetoken;
prs->state->poschar -= prs->state->lenchartoken;
prs->state->lenbytetoken = 0;
prs->state->lenchartoken = 0;
}
static int
p_isstophost(TParser *prs)
{
if (prs->wanthost)
{
prs->wanthost = false;
return 1;
}
return 0;
}
static int
p_isignore(TParser *prs)
{
return (prs->ignore) ? 1 : 0;
}
static int
p_ishost(TParser *prs)
{
TParser *tmpprs = TParserCopyInit(prs);
int res = 0;
tmpprs->wanthost = true;
if (TParserGet(tmpprs) && tmpprs->type == HOST)
{
prs->state->posbyte += tmpprs->lenbytetoken;
prs->state->poschar += tmpprs->lenchartoken;
prs->state->lenbytetoken += tmpprs->lenbytetoken;
prs->state->lenchartoken += tmpprs->lenchartoken;
prs->state->charlen = tmpprs->state->charlen;
res = 1;
}
TParserCopyClose(tmpprs);
return res;
}
static int
p_isURLPath(TParser *prs)
{
TParser *tmpprs = TParserCopyInit(prs);
int res = 0;
tmpprs->state = newTParserPosition(tmpprs->state);
tmpprs->state->state = TPS_InURLPathFirst;
if (TParserGet(tmpprs) && tmpprs->type == URLPATH)
{
prs->state->posbyte += tmpprs->lenbytetoken;
prs->state->poschar += tmpprs->lenchartoken;
prs->state->lenbytetoken += tmpprs->lenbytetoken;
prs->state->lenchartoken += tmpprs->lenchartoken;
prs->state->charlen = tmpprs->state->charlen;
res = 1;
}
TParserCopyClose(tmpprs);
return res;
}
/*
* returns true if current character has zero display length or
* it's a special sign in several languages. Such characters
* aren't a word-breaker although they aren't an isalpha.
* In beginning of word they aren't a part of it.
*/
static int
p_isspecial(TParser *prs)
{
/*
* pg_dsplen could return -1 which means error or control character
*/
if (pg_dsplen(prs->str + prs->state->posbyte) == 0)
return 1;
/*
* Unicode Characters in the 'Mark, Spacing Combining' Category That
* characters are not alpha although they are not breakers of word too.
* Check that only in utf encoding, because other encodings aren't
* supported by postgres or even exists.
*/
if (GetDatabaseEncoding() == PG_UTF8 && prs->usewide)
{
static const pg_wchar strange_letter[] = {
/*
* use binary search, so elements should be ordered
*/
0x0903, /* DEVANAGARI SIGN VISARGA */
0x093E, /* DEVANAGARI VOWEL SIGN AA */
0x093F, /* DEVANAGARI VOWEL SIGN I */
0x0940, /* DEVANAGARI VOWEL SIGN II */
0x0949, /* DEVANAGARI VOWEL SIGN CANDRA O */
0x094A, /* DEVANAGARI VOWEL SIGN SHORT O */
0x094B, /* DEVANAGARI VOWEL SIGN O */
0x094C, /* DEVANAGARI VOWEL SIGN AU */
0x0982, /* BENGALI SIGN ANUSVARA */
0x0983, /* BENGALI SIGN VISARGA */
0x09BE, /* BENGALI VOWEL SIGN AA */
0x09BF, /* BENGALI VOWEL SIGN I */
0x09C0, /* BENGALI VOWEL SIGN II */
0x09C7, /* BENGALI VOWEL SIGN E */
0x09C8, /* BENGALI VOWEL SIGN AI */
0x09CB, /* BENGALI VOWEL SIGN O */
0x09CC, /* BENGALI VOWEL SIGN AU */
0x09D7, /* BENGALI AU LENGTH MARK */
0x0A03, /* GURMUKHI SIGN VISARGA */
0x0A3E, /* GURMUKHI VOWEL SIGN AA */
0x0A3F, /* GURMUKHI VOWEL SIGN I */
0x0A40, /* GURMUKHI VOWEL SIGN II */
0x0A83, /* GUJARATI SIGN VISARGA */
0x0ABE, /* GUJARATI VOWEL SIGN AA */
0x0ABF, /* GUJARATI VOWEL SIGN I */
0x0AC0, /* GUJARATI VOWEL SIGN II */
0x0AC9, /* GUJARATI VOWEL SIGN CANDRA O */
0x0ACB, /* GUJARATI VOWEL SIGN O */
0x0ACC, /* GUJARATI VOWEL SIGN AU */
0x0B02, /* ORIYA SIGN ANUSVARA */
0x0B03, /* ORIYA SIGN VISARGA */
0x0B3E, /* ORIYA VOWEL SIGN AA */
0x0B40, /* ORIYA VOWEL SIGN II */
0x0B47, /* ORIYA VOWEL SIGN E */
0x0B48, /* ORIYA VOWEL SIGN AI */
0x0B4B, /* ORIYA VOWEL SIGN O */
0x0B4C, /* ORIYA VOWEL SIGN AU */
0x0B57, /* ORIYA AU LENGTH MARK */
0x0BBE, /* TAMIL VOWEL SIGN AA */
0x0BBF, /* TAMIL VOWEL SIGN I */
0x0BC1, /* TAMIL VOWEL SIGN U */
0x0BC2, /* TAMIL VOWEL SIGN UU */
0x0BC6, /* TAMIL VOWEL SIGN E */
0x0BC7, /* TAMIL VOWEL SIGN EE */
0x0BC8, /* TAMIL VOWEL SIGN AI */
0x0BCA, /* TAMIL VOWEL SIGN O */
0x0BCB, /* TAMIL VOWEL SIGN OO */
0x0BCC, /* TAMIL VOWEL SIGN AU */
0x0BD7, /* TAMIL AU LENGTH MARK */
0x0C01, /* TELUGU SIGN CANDRABINDU */
0x0C02, /* TELUGU SIGN ANUSVARA */
0x0C03, /* TELUGU SIGN VISARGA */
0x0C41, /* TELUGU VOWEL SIGN U */
0x0C42, /* TELUGU VOWEL SIGN UU */
0x0C43, /* TELUGU VOWEL SIGN VOCALIC R */
0x0C44, /* TELUGU VOWEL SIGN VOCALIC RR */
0x0C82, /* KANNADA SIGN ANUSVARA */
0x0C83, /* KANNADA SIGN VISARGA */
0x0CBE, /* KANNADA VOWEL SIGN AA */
0x0CC0, /* KANNADA VOWEL SIGN II */
0x0CC1, /* KANNADA VOWEL SIGN U */
0x0CC2, /* KANNADA VOWEL SIGN UU */
0x0CC3, /* KANNADA VOWEL SIGN VOCALIC R */
0x0CC4, /* KANNADA VOWEL SIGN VOCALIC RR */
0x0CC7, /* KANNADA VOWEL SIGN EE */
0x0CC8, /* KANNADA VOWEL SIGN AI */
0x0CCA, /* KANNADA VOWEL SIGN O */
0x0CCB, /* KANNADA VOWEL SIGN OO */
0x0CD5, /* KANNADA LENGTH MARK */
0x0CD6, /* KANNADA AI LENGTH MARK */
0x0D02, /* MALAYALAM SIGN ANUSVARA */
0x0D03, /* MALAYALAM SIGN VISARGA */
0x0D3E, /* MALAYALAM VOWEL SIGN AA */
0x0D3F, /* MALAYALAM VOWEL SIGN I */
0x0D40, /* MALAYALAM VOWEL SIGN II */
0x0D46, /* MALAYALAM VOWEL SIGN E */
0x0D47, /* MALAYALAM VOWEL SIGN EE */
0x0D48, /* MALAYALAM VOWEL SIGN AI */
0x0D4A, /* MALAYALAM VOWEL SIGN O */
0x0D4B, /* MALAYALAM VOWEL SIGN OO */
0x0D4C, /* MALAYALAM VOWEL SIGN AU */
0x0D57, /* MALAYALAM AU LENGTH MARK */
0x0D82, /* SINHALA SIGN ANUSVARAYA */
0x0D83, /* SINHALA SIGN VISARGAYA */
0x0DCF, /* SINHALA VOWEL SIGN AELA-PILLA */
0x0DD0, /* SINHALA VOWEL SIGN KETTI AEDA-PILLA */
0x0DD1, /* SINHALA VOWEL SIGN DIGA AEDA-PILLA */
0x0DD8, /* SINHALA VOWEL SIGN GAETTA-PILLA */
0x0DD9, /* SINHALA VOWEL SIGN KOMBUVA */
0x0DDA, /* SINHALA VOWEL SIGN DIGA KOMBUVA */
0x0DDB, /* SINHALA VOWEL SIGN KOMBU DEKA */
0x0DDC, /* SINHALA VOWEL SIGN KOMBUVA HAA AELA-PILLA */
0x0DDD, /* SINHALA VOWEL SIGN KOMBUVA HAA DIGA
* AELA-PILLA */
0x0DDE, /* SINHALA VOWEL SIGN KOMBUVA HAA GAYANUKITTA */
0x0DDF, /* SINHALA VOWEL SIGN GAYANUKITTA */
0x0DF2, /* SINHALA VOWEL SIGN DIGA GAETTA-PILLA */
0x0DF3, /* SINHALA VOWEL SIGN DIGA GAYANUKITTA */
0x0F3E, /* TIBETAN SIGN YAR TSHES */
0x0F3F, /* TIBETAN SIGN MAR TSHES */
0x0F7F, /* TIBETAN SIGN RNAM BCAD */
0x102B, /* MYANMAR VOWEL SIGN TALL AA */
0x102C, /* MYANMAR VOWEL SIGN AA */
0x1031, /* MYANMAR VOWEL SIGN E */
0x1038, /* MYANMAR SIGN VISARGA */
0x103B, /* MYANMAR CONSONANT SIGN MEDIAL YA */
0x103C, /* MYANMAR CONSONANT SIGN MEDIAL RA */
0x1056, /* MYANMAR VOWEL SIGN VOCALIC R */
0x1057, /* MYANMAR VOWEL SIGN VOCALIC RR */
0x1062, /* MYANMAR VOWEL SIGN SGAW KAREN EU */
0x1063, /* MYANMAR TONE MARK SGAW KAREN HATHI */
0x1064, /* MYANMAR TONE MARK SGAW KAREN KE PHO */
0x1067, /* MYANMAR VOWEL SIGN WESTERN PWO KAREN EU */
0x1068, /* MYANMAR VOWEL SIGN WESTERN PWO KAREN UE */
0x1069, /* MYANMAR SIGN WESTERN PWO KAREN TONE-1 */
0x106A, /* MYANMAR SIGN WESTERN PWO KAREN TONE-2 */
0x106B, /* MYANMAR SIGN WESTERN PWO KAREN TONE-3 */
0x106C, /* MYANMAR SIGN WESTERN PWO KAREN TONE-4 */
0x106D, /* MYANMAR SIGN WESTERN PWO KAREN TONE-5 */
0x1083, /* MYANMAR VOWEL SIGN SHAN AA */
0x1084, /* MYANMAR VOWEL SIGN SHAN E */
0x1087, /* MYANMAR SIGN SHAN TONE-2 */
0x1088, /* MYANMAR SIGN SHAN TONE-3 */
0x1089, /* MYANMAR SIGN SHAN TONE-5 */
0x108A, /* MYANMAR SIGN SHAN TONE-6 */
0x108B, /* MYANMAR SIGN SHAN COUNCIL TONE-2 */
0x108C, /* MYANMAR SIGN SHAN COUNCIL TONE-3 */
0x108F, /* MYANMAR SIGN RUMAI PALAUNG TONE-5 */
0x17B6, /* KHMER VOWEL SIGN AA */
0x17BE, /* KHMER VOWEL SIGN OE */
0x17BF, /* KHMER VOWEL SIGN YA */
0x17C0, /* KHMER VOWEL SIGN IE */
0x17C1, /* KHMER VOWEL SIGN E */
0x17C2, /* KHMER VOWEL SIGN AE */
0x17C3, /* KHMER VOWEL SIGN AI */
0x17C4, /* KHMER VOWEL SIGN OO */
0x17C5, /* KHMER VOWEL SIGN AU */
0x17C7, /* KHMER SIGN REAHMUK */
0x17C8, /* KHMER SIGN YUUKALEAPINTU */
0x1923, /* LIMBU VOWEL SIGN EE */
0x1924, /* LIMBU VOWEL SIGN AI */
0x1925, /* LIMBU VOWEL SIGN OO */
0x1926, /* LIMBU VOWEL SIGN AU */
0x1929, /* LIMBU SUBJOINED LETTER YA */
0x192A, /* LIMBU SUBJOINED LETTER RA */
0x192B, /* LIMBU SUBJOINED LETTER WA */
0x1930, /* LIMBU SMALL LETTER KA */
0x1931, /* LIMBU SMALL LETTER NGA */
0x1933, /* LIMBU SMALL LETTER TA */
0x1934, /* LIMBU SMALL LETTER NA */
0x1935, /* LIMBU SMALL LETTER PA */
0x1936, /* LIMBU SMALL LETTER MA */
0x1937, /* LIMBU SMALL LETTER RA */
0x1938, /* LIMBU SMALL LETTER LA */
0x19B0, /* NEW TAI LUE VOWEL SIGN VOWEL SHORTENER */
0x19B1, /* NEW TAI LUE VOWEL SIGN AA */
0x19B2, /* NEW TAI LUE VOWEL SIGN II */
0x19B3, /* NEW TAI LUE VOWEL SIGN U */
0x19B4, /* NEW TAI LUE VOWEL SIGN UU */
0x19B5, /* NEW TAI LUE VOWEL SIGN E */
0x19B6, /* NEW TAI LUE VOWEL SIGN AE */
0x19B7, /* NEW TAI LUE VOWEL SIGN O */
0x19B8, /* NEW TAI LUE VOWEL SIGN OA */
0x19B9, /* NEW TAI LUE VOWEL SIGN UE */
0x19BA, /* NEW TAI LUE VOWEL SIGN AY */
0x19BB, /* NEW TAI LUE VOWEL SIGN AAY */
0x19BC, /* NEW TAI LUE VOWEL SIGN UY */
0x19BD, /* NEW TAI LUE VOWEL SIGN OY */
0x19BE, /* NEW TAI LUE VOWEL SIGN OAY */
0x19BF, /* NEW TAI LUE VOWEL SIGN UEY */
0x19C0, /* NEW TAI LUE VOWEL SIGN IY */
0x19C8, /* NEW TAI LUE TONE MARK-1 */
0x19C9, /* NEW TAI LUE TONE MARK-2 */
0x1A19, /* BUGINESE VOWEL SIGN E */
0x1A1A, /* BUGINESE VOWEL SIGN O */
0x1A1B, /* BUGINESE VOWEL SIGN AE */
0x1B04, /* BALINESE SIGN BISAH */
0x1B35, /* BALINESE VOWEL SIGN TEDUNG */
0x1B3B, /* BALINESE VOWEL SIGN RA REPA TEDUNG */
0x1B3D, /* BALINESE VOWEL SIGN LA LENGA TEDUNG */
0x1B3E, /* BALINESE VOWEL SIGN TALING */
0x1B3F, /* BALINESE VOWEL SIGN TALING REPA */
0x1B40, /* BALINESE VOWEL SIGN TALING TEDUNG */
0x1B41, /* BALINESE VOWEL SIGN TALING REPA TEDUNG */
0x1B43, /* BALINESE VOWEL SIGN PEPET TEDUNG */
0x1B44, /* BALINESE ADEG ADEG */
0x1B82, /* SUNDANESE SIGN PANGWISAD */
0x1BA1, /* SUNDANESE CONSONANT SIGN PAMINGKAL */
0x1BA6, /* SUNDANESE VOWEL SIGN PANAELAENG */
0x1BA7, /* SUNDANESE VOWEL SIGN PANOLONG */
0x1BAA, /* SUNDANESE SIGN PAMAAEH */
0x1C24, /* LEPCHA SUBJOINED LETTER YA */
0x1C25, /* LEPCHA SUBJOINED LETTER RA */
0x1C26, /* LEPCHA VOWEL SIGN AA */
0x1C27, /* LEPCHA VOWEL SIGN I */
0x1C28, /* LEPCHA VOWEL SIGN O */
0x1C29, /* LEPCHA VOWEL SIGN OO */
0x1C2A, /* LEPCHA VOWEL SIGN U */
0x1C2B, /* LEPCHA VOWEL SIGN UU */
0x1C34, /* LEPCHA CONSONANT SIGN NYIN-DO */
0x1C35, /* LEPCHA CONSONANT SIGN KANG */
0xA823, /* SYLOTI NAGRI VOWEL SIGN A */
0xA824, /* SYLOTI NAGRI VOWEL SIGN I */
0xA827, /* SYLOTI NAGRI VOWEL SIGN OO */
0xA880, /* SAURASHTRA SIGN ANUSVARA */
0xA881, /* SAURASHTRA SIGN VISARGA */
0xA8B4, /* SAURASHTRA CONSONANT SIGN HAARU */
0xA8B5, /* SAURASHTRA VOWEL SIGN AA */
0xA8B6, /* SAURASHTRA VOWEL SIGN I */
0xA8B7, /* SAURASHTRA VOWEL SIGN II */
0xA8B8, /* SAURASHTRA VOWEL SIGN U */
0xA8B9, /* SAURASHTRA VOWEL SIGN UU */
0xA8BA, /* SAURASHTRA VOWEL SIGN VOCALIC R */
0xA8BB, /* SAURASHTRA VOWEL SIGN VOCALIC RR */
0xA8BC, /* SAURASHTRA VOWEL SIGN VOCALIC L */
0xA8BD, /* SAURASHTRA VOWEL SIGN VOCALIC LL */
0xA8BE, /* SAURASHTRA VOWEL SIGN E */
0xA8BF, /* SAURASHTRA VOWEL SIGN EE */
0xA8C0, /* SAURASHTRA VOWEL SIGN AI */
0xA8C1, /* SAURASHTRA VOWEL SIGN O */
0xA8C2, /* SAURASHTRA VOWEL SIGN OO */
0xA8C3, /* SAURASHTRA VOWEL SIGN AU */
0xA952, /* REJANG CONSONANT SIGN H */
0xA953, /* REJANG VIRAMA */
0xAA2F, /* CHAM VOWEL SIGN O */
0xAA30, /* CHAM VOWEL SIGN AI */
0xAA33, /* CHAM CONSONANT SIGN YA */
0xAA34, /* CHAM CONSONANT SIGN RA */
0xAA4D /* CHAM CONSONANT SIGN FINAL H */
};
const pg_wchar *StopLow = strange_letter,
*StopHigh = strange_letter + lengthof(strange_letter),
*StopMiddle;
pg_wchar c;
if (prs->pgwstr)
c = *(prs->pgwstr + prs->state->poschar);
else
c = (pg_wchar) *(prs->wstr + prs->state->poschar);
while (StopLow < StopHigh)
{
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
if (*StopMiddle == c)
return 1;
else if (*StopMiddle < c)
StopLow = StopMiddle + 1;
else
StopHigh = StopMiddle;
}
}
return 0;
}
/*
* Table of state/action of parser
*/
static const TParserStateActionItem actionTPS_Base[] = {
{p_isEOF, 0, A_NEXT, TPS_Null, 0, NULL},
{p_iseqC, '<', A_PUSH, TPS_InTagFirst, 0, NULL},
{p_isignore, 0, A_NEXT, TPS_InSpace, 0, NULL},
{p_isasclet, 0, A_NEXT, TPS_InAsciiWord, 0, NULL},
{p_isalpha, 0, A_NEXT, TPS_InWord, 0, NULL},
{p_isdigit, 0, A_NEXT, TPS_InUnsignedInt, 0, NULL},
{p_iseqC, '-', A_PUSH, TPS_InSignedIntFirst, 0, NULL},
{p_iseqC, '+', A_PUSH, TPS_InSignedIntFirst, 0, NULL},
{p_iseqC, '&', A_PUSH, TPS_InXMLEntityFirst, 0, NULL},
{p_iseqC, '~', A_PUSH, TPS_InFileTwiddle, 0, NULL},
{p_iseqC, '/', A_PUSH, TPS_InFileFirst, 0, NULL},
{p_iseqC, '.', A_PUSH, TPS_InPathFirstFirst, 0, NULL},
{NULL, 0, A_NEXT, TPS_InSpace, 0, NULL}
};
static const TParserStateActionItem actionTPS_InNumWord[] = {
{p_isEOF, 0, A_BINGO, TPS_Base, NUMWORD, NULL},
{p_isalnum, 0, A_NEXT, TPS_InNumWord, 0, NULL},
{p_isspecial, 0, A_NEXT, TPS_InNumWord, 0, NULL},