| From: | "Tristan Partin" <tristan(at)partin(dot)io> |
|---|---|
| To: | "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | "Andrew Dunstan" <andrew(at)dunslane(dot)net> |
| Subject: | Improve readability of json_lex() |
| Date: | 2026-07-13 22:09:10 |
| Message-ID: | DJXSBQVKCQU2.SIQVXEH2P0AM@partin.io |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
I've been working in json_lex() for a little bit to add support for
JSONC[0] (patches to come later). In my endeavors to do so, I found
json_lex() to be quite beefy. Part of that is due to it being the entry
point for lexing when using both the incremental and non-incremental
JSON parsers. This leads to large sections of branching that seem to
hurt readability.
I've separated each refactor into its own commit such that we could take
some, all, or none of them. I know refactoring can be very opinionated.
Based on my experience with the upcoming JSONC patches, I have found
these changes to allow my future changes to be much more reviewable.
Ideally, these changes also make it easier for future readers to
understand and contribute in the JSON lexing code. History points to
this code being pretty static with the largest change coming when Andrew
added the non-recursive (incremental) parser.
Maybe others have thought of other ways to make this function a bit more
approachable.
[0]: https://jsonc.org
--
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Pull-some-json_lex-incremental-code-into-separate.patch | text/x-patch | 14.0 KB |
| v1-0002-Extract-whitespace-skip-code-in-json_lex.patch | text/x-patch | 2.0 KB |
| v1-0003-Extract-code-for-determining-token-type-into-a-se.patch | text/x-patch | 9.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2026-07-13 22:09:19 | Re: hashjoins vs. Bloom filters (yet again) |
| Previous Message | Peter Smith | 2026-07-13 22:07:47 | Re: PSQL - prevent describe listing tables that are already in listed schemas |