Libpg_query is a C library that serves as the parser for PostgreSQL, converting SQL queries into abstract syntax trees (ASTs). It offers almost perfect compatibility with PostgreSQL, but lacks the ability to provide expression end locations, which can complicate tasks like syntax highlighting. A technique involving the PostgreSQL lexer can address this limitation by retrieving start and end locations of expressions through tokenization. The text demonstrates this process using TypeScript and Node.js with a library called @pg-nano/pg-parser, highlighting how to extract and visualize start and end locations of SQL expressions. The method involves creating functions that annotate each expression with its left- and right-most tokens, enabling accurate expression highlighting. The post also discusses potential improvements for handling specific SQL constructs, such as aliases and parentheses, and offers a practical way to execute the embedded TypeScript code.