summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/common/keywords.h25
-rw-r--r--src/include/common/kwlookup.h40
-rw-r--r--src/include/parser/kwlist.h2
-rw-r--r--src/include/parser/scanner.h13
4 files changed, 56 insertions, 24 deletions
diff --git a/src/include/common/keywords.h b/src/include/common/keywords.h
index 8f22f32548c..fb18858a53e 100644
--- a/src/include/common/keywords.h
+++ b/src/include/common/keywords.h
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------
*
* keywords.h
- * lexical token lookup for key words in PostgreSQL
+ * PostgreSQL's list of SQL keywords
*
*
* Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
@@ -14,31 +14,20 @@
#ifndef KEYWORDS_H
#define KEYWORDS_H
+#include "common/kwlookup.h"
+
/* Keyword categories --- should match lists in gram.y */
#define UNRESERVED_KEYWORD 0
#define COL_NAME_KEYWORD 1
#define TYPE_FUNC_NAME_KEYWORD 2
#define RESERVED_KEYWORD 3
-
-typedef struct ScanKeyword
-{
- const char *name; /* in lower case */
- int16 value; /* grammar's token code */
- int16 category; /* see codes above */
-} ScanKeyword;
-
#ifndef FRONTEND
-extern PGDLLIMPORT const ScanKeyword ScanKeywords[];
-extern PGDLLIMPORT const int NumScanKeywords;
+extern PGDLLIMPORT const ScanKeywordList ScanKeywords;
+extern PGDLLIMPORT const uint8 ScanKeywordCategories[];
#else
-extern const ScanKeyword ScanKeywords[];
-extern const int NumScanKeywords;
+extern const ScanKeywordList ScanKeywords;
+extern const uint8 ScanKeywordCategories[];
#endif
-
-extern const ScanKeyword *ScanKeywordLookup(const char *text,
- const ScanKeyword *keywords,
- int num_keywords);
-
#endif /* KEYWORDS_H */
diff --git a/src/include/common/kwlookup.h b/src/include/common/kwlookup.h
new file mode 100644
index 00000000000..39efb3503fc
--- /dev/null
+++ b/src/include/common/kwlookup.h
@@ -0,0 +1,40 @@
+/*-------------------------------------------------------------------------
+ *
+ * kwlookup.h
+ * Key word lookup for PostgreSQL
+ *
+ *
+ * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/common/kwlookup.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef KWLOOKUP_H
+#define KWLOOKUP_H
+
+/*
+ * This struct contains the data needed by ScanKeywordLookup to perform a
+ * search within a set of keywords. The contents are typically generated by
+ * src/tools/gen_keywordlist.pl from a header containing PG_KEYWORD macros.
+ */
+typedef struct ScanKeywordList
+{
+ const char *kw_string; /* all keywords in order, separated by \0 */
+ const uint16 *kw_offsets; /* offsets to the start of each keyword */
+ int num_keywords; /* number of keywords */
+ int max_kw_len; /* length of longest keyword */
+} ScanKeywordList;
+
+
+extern int ScanKeywordLookup(const char *text, const ScanKeywordList *keywords);
+
+/* Code that wants to retrieve the text of the N'th keyword should use this. */
+static inline const char *
+GetScanKeyword(int n, const ScanKeywordList *keywords)
+{
+ return keywords->kw_string + keywords->kw_offsets[n];
+}
+
+#endif /* KWLOOKUP_H */
diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h
index 0256d539981..b8902d34030 100644
--- a/src/include/parser/kwlist.h
+++ b/src/include/parser/kwlist.h
@@ -2,7 +2,7 @@
*
* kwlist.h
*
- * The keyword list is kept in its own source file for possible use by
+ * The keyword lists are kept in their own source files for use by
* automatic tools. The exact representation of a keyword is determined
* by the PG_KEYWORD macro, which is not defined in this file; it can
* be defined by the caller for special purposes.
diff --git a/src/include/parser/scanner.h b/src/include/parser/scanner.h
index 009550f4246..91e1c836d22 100644
--- a/src/include/parser/scanner.h
+++ b/src/include/parser/scanner.h
@@ -73,10 +73,10 @@ typedef struct core_yy_extra_type
Size scanbuflen;
/*
- * The keyword list to use.
+ * The keyword list to use, and the associated grammar token codes.
*/
- const ScanKeyword *keywords;
- int num_keywords;
+ const ScanKeywordList *keywordlist;
+ const uint16 *keyword_tokens;
/*
* Scanner settings to use. These are initialized from the corresponding
@@ -116,11 +116,14 @@ typedef struct core_yy_extra_type
typedef void *core_yyscan_t;
+/* Constant data exported from parser/scan.l */
+extern PGDLLIMPORT const uint16 ScanKeywordTokens[];
+
/* Entry points in parser/scan.l */
extern core_yyscan_t scanner_init(const char *str,
core_yy_extra_type *yyext,
- const ScanKeyword *keywords,
- int num_keywords);
+ const ScanKeywordList *keywordlist,
+ const uint16 *keyword_tokens);
extern void scanner_finish(core_yyscan_t yyscanner);
extern int core_yylex(core_YYSTYPE *lvalp, YYLTYPE *llocp,
core_yyscan_t yyscanner);