Skip to content

Commit c6b602f

Browse files
h3n4lclaude
andcommitted
feat(postgresql): implement automated keyword management system
Implemented a keyword generator that fetches PostgreSQL keywords from the official kwlist.h file and automatically generates ANTLR grammar rules. Key features: - Fetches keywords from PostgreSQL REL_18_STABLE kwlist.h - Generates parser rules (reserved, unreserved, col_name, type_func_name) - Inserts lexer keyword rules directly into PostgreSQLLexer.g4 - Handles ANTLR reserved name conflicts (e.g., SKIP → SKIP_P) - Matches PostgreSQL's official gram.y structure Changes: - Add keyword-generator/ tool (Go program) - Add PostgreSQLKeywords.g4 (auto-generated parser rules) - Update PostgreSQLLexer.g4 with auto-generated keyword section - Update PostgreSQLParser.g4 to use kwlist.h token names - Update Makefile with generate-keywords target - Fix token references in postgresql_lexer_base.go The generator ensures keywords are placed before the Identifier rule in the lexer for correct matching precedence. Keywords are managed between marker comments for easy regeneration. Test results: 190/214 tests passing (88.8%) 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 635e973 commit c6b602f

15 files changed

+24541
-24108
lines changed

postgresql/Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
all: build test
22

3-
build:
3+
# Generate keyword definitions from PostgreSQL official source
4+
generate-keywords:
5+
@echo "Generating PostgreSQL keyword definitions from REL_18_STABLE..."
6+
cd keyword-generator && go run main.go
7+
@echo ""
8+
9+
# Build the parser (depends on keyword generation)
10+
build: generate-keywords
11+
@echo "Building PostgreSQL parser..."
412
antlr -Dlanguage=Go -package postgresql -visitor -o . PostgreSQLLexer.g4 PostgreSQLParser.g4
513

6-
test:
7-
go test -v -run TestPostgreSQLParser
14+
test:
15+
go test -v -run TestPostgreSQLParser
16+
17+
.PHONY: all build test generate-keywords

0 commit comments

Comments
 (0)