* parser_errposition * Report a parse-analysis-time cursor position, if possible. * * This is expected to be used within an ereport() call. The return value * is a dummy (always 0, in fact). * * The locations stored in raw parsetrees are byte offsets into the source * string. We have to convert them to 1-based character indexes for reporting * to clients. (We do things this way to avoi
| 108 | * expensive than storing token offsets.) |
| 109 | */ |
| 110 | void |
| 111 | parser_errposition(ParseState *pstate, int location) |
| 112 | { |
| 113 | int pos; |
| 114 | |
| 115 | /* No-op if location was not provided */ |
| 116 | if (location < 0) |
| 117 | return; |
| 118 | /* Can't do anything if source text is not available */ |
| 119 | if (pstate == NULL || pstate->p_sourcetext == NULL) |
| 120 | return; |
| 121 | /* Convert offset to character number */ |
| 122 | pos = pg_mbstrlen_with_len(pstate->p_sourcetext, location) + 1; |
| 123 | /* And pass it to the ereport mechanism */ |
| 124 | errposition(pos); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /* |
no test coverage detected