From 1aaf39bd20122984bafa30bf4ec8ba357b59e955 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 27 Oct 2007 17:53:15 +0000 Subject: [PATCH] Add some rudimentary tracing code to the default text search parser, to help in debugging its state-machine rules. Const-ify all the constant tables. Minor other code cleanup, including using "token" rather than "lexeme" to describe the output strings. --- src/backend/tsearch/wparser_def.c | 496 ++++++++++++++++-------------- 1 file changed, 272 insertions(+), 224 deletions(-) diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c index 5f8643a61b..7fa0f435b2 100644 --- a/src/backend/tsearch/wparser_def.c +++ b/src/backend/tsearch/wparser_def.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tsearch/wparser_def.c,v 1.5 2007/10/27 16:01:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tsearch/wparser_def.c,v 1.6 2007/10/27 17:53:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -22,6 +22,10 @@ #include "utils/builtins.h" +/* Define me to enable tracing of parser behavior */ +/* #define WPARSER_TRACE */ + + /* Output token categories */ #define ASCIIWORD 1 @@ -221,23 +225,16 @@ typedef struct #define A_MERGE 0x0020 #define A_CLRALL 0x0040 -typedef struct -{ - TParserState state; - TParserStateActionItem *action; -} TParserStateAction; - typedef struct TParserPosition { int posbyte; /* position of parser in bytes */ - int poschar; /* osition of parser in characters */ + int poschar; /* position of parser in characters */ int charlen; /* length of current char */ - int lenbytelexeme; - int lencharlexeme; + int lenbytetoken; /* length of token-so-far in bytes */ + int lenchartoken; /* and in chars */ TParserState state; struct TParserPosition *prev; - int flags; - TParserStateActionItem *pushedAtAction; + const TParserStateActionItem *pushedAtAction; } TParserPosition; typedef struct TParser @@ -261,11 +258,10 @@ typedef struct TParser char c; /* out */ - char *lexeme; - int lenbytelexeme; - int lencharlexeme; + char *token; + int lenbytetoken; + int lenchartoken; int type; - } TParser; @@ -318,6 +314,10 @@ TParserInit(char *str, int len) prs->state = newTParserPosition(NULL); prs->state->state = TPS_Base; +#ifdef WPARSER_TRACE + fprintf(stderr, "parsing \"%.*s\"\n", len, str); +#endif + return prs; } @@ -541,20 +541,20 @@ _make_compiler_happy(void) static void SpecialTags(TParser * prs) { - switch (prs->state->lencharlexeme) + switch (prs->state->lenchartoken) { case 8: /* lexeme, "token, "ignore = false; break; case 7: /*