summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/preproc/ecpg_keywords.c
blob: a2db06fadad94ca611be11d42debb3029e16cc83 (plain)
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
/*-------------------------------------------------------------------------
 *
 * ecpg_keywords.c
 *	  lexical token lookup for reserved words in postgres embedded SQL
 *
 * IDENTIFICATION
 *	  src/interfaces/ecpg/preproc/ecpg_keywords.c
 *
 *-------------------------------------------------------------------------
 */

#include "postgres_fe.h"

#include <ctype.h>

/* ScanKeywordList lookup data for ECPG keywords */
#include "ecpg_kwlist_d.h"
#include "preproc_extern.h"
#include "preproc.h"

/* Token codes for ECPG keywords */
#define PG_KEYWORD(kwname, value) value,

static const uint16 ECPGScanKeywordTokens[] = {
#include "ecpg_kwlist.h"
};

#undef PG_KEYWORD


/*
 * ScanECPGKeywordLookup - see if a given word is a keyword
 *
 * Returns the token value of the keyword, or -1 if no match.
 *
 * Keywords are matched using the same case-folding rules as in the backend.
 */
int
ScanECPGKeywordLookup(const char *text)
{
	int			kwnum;

	/* First check SQL symbols defined by the backend. */
	kwnum = ScanKeywordLookup(text, &ScanKeywords);
	if (kwnum >= 0)
		return SQLScanKeywordTokens[kwnum];

	/* Try ECPG-specific keywords. */
	kwnum = ScanKeywordLookup(text, &ScanECPGKeywords);
	if (kwnum >= 0)
		return ECPGScanKeywordTokens[kwnum];

	return -1;
}