The parser of PL/pgSQL (commons lang-sql 0006-sql-routinesFR-005 to FR-008): the body of a PostgreSQL routine, read as blocks, declarations and statements, with the SQL it holds read by the core parser at its place in the whole text. It works on the tokens of the body, finds where each construct ends, and hands the expressions and queries to parseFragment; a statement it cannot read is a node pl-unparsed and an error value, and the statements after it are read.
Every offset is an offset of the whole text, so a node of a body and a node of the script around it are in one coordinate system, and the comments of the body are attached by the rule of the core.
constp=parse("CREATE FUNCTION f() RETURNS int AS $$ BEGIN RETURN 1; END $$ LANGUAGE plpgsql", postgres);
constr=parsePlpgsql(p, postgres, p.script.statements[0]!);
r.block?.statements[0]?.kind; // "pl-return"