/* * pg_keyword_lookup.h * * Keyword-to-token mapping for the PostgreSQL Lime parser. * Generated from PostgreSQL gram.y keyword declarations. * * Each keyword entry maps a string to a token ID and its reservation * category. The categories determine which identifier productions a * keyword can appear in: * * UNRESERVED - Can be used as any kind of name * COL_NAME - Can be column/table names, but not type/function names * TYPE_FUNC - Can be type or function names * RESERVED - Only usable as ColLabel (after AS) * * Additionally, each keyword is marked as BARE_LABEL or AS_LABEL: * BARE_LABEL - Can be used as column label without AS * AS_LABEL - Requires AS before use as column label */ #ifndef PG_KEYWORD_LOOKUP_H #define PG_KEYWORD_LOOKUP_H typedef enum { KW_UNRESERVED, KW_COL_NAME, KW_TYPE_FUNC, KW_RESERVED } PgKeywordCategory; typedef enum { KW_BARE_LABEL, KW_AS_LABEL } PgKeywordLabelType; typedef struct { const char *name; int token_id; PgKeywordCategory category; PgKeywordLabelType label_type; } PgKeyword; /* * Keyword lookup function. Returns the token ID for the given string, * or 0 if the string is not a keyword (in which case it should be * treated as IDENT). * * The lookup should be case-insensitive (SQL keywords are case-insensitive). */ int pg_keyword_lookup(const char *str, int len, PgKeywordCategory *cat_out); /* * Number of keywords. Useful for hash table sizing. */ #define PG_NUM_KEYWORDS 510 /* * Keyword table. Sorted alphabetically for binary search. * Token IDs reference the enum values generated by Lime in the .h output. * * This table should be populated after Lime generates the token ID header. * For now, it serves as a template showing the structure. * * Example entries: * * {"abort", TK_ABORT_P, KW_UNRESERVED, KW_BARE_LABEL}, * {"absent", TK_ABSENT, KW_UNRESERVED, KW_BARE_LABEL}, * {"absolute", TK_ABSOLUTE_P, KW_UNRESERVED, KW_BARE_LABEL}, * ... * {"all", TK_ALL, KW_RESERVED, KW_BARE_LABEL}, * ... * {"between", TK_BETWEEN, KW_COL_NAME, KW_BARE_LABEL}, * ... * {"authorization", TK_AUTHORIZATION, KW_TYPE_FUNC, KW_BARE_LABEL}, * ... * * NOTE: The _P suffix on token names (e.g., ABORT_P) is stripped in the * keyword string (e.g., "abort"). The suffix exists only to avoid C * reserved word conflicts. */ #endif /* PG_KEYWORD_LOOKUP_H */