exu / pgsql.vim

Postgresql syntax from Devrim GUNDUZ
http://www.gunduz.org/postgresql/pgsql.vim
80 stars 27 forks source link

Dollar quoting problem from different angle :) #5

Closed ghost closed 8 years ago

ghost commented 10 years ago

I have postgresql functions, which are defined as standard

CREATE OR REPLACE FUNCTION substract_lunch() RETURNS TRIGGER AS $no_lunch$ DECLARE o_lunch interval; BEGIN SELECT object_lunch INTO o_lunch FROM attendance_control WHERE attendance_ct_id = NEW.object_id;

NEW.offsite := NEW.offsite - o_lunch;

RETURN NEW; END;--Trigger $no_lunch$ LANGUAGE plpgsql;

What the dollar quoting does, is rendering the whole body as string, with no highlighting.

Vim - 7.4.135 pgsql.vim - 424cd518e6e250c3cfcd6f1c534832f8da07c098

If I remove or comment out the line (line 57 in syntax/pgsql.vim) syn region pgsqlString start=+\$\z(\w*)\$+ end=+\$\z1\$+ I get the highlighting back. I have a feeling the regexp is too greedy, but I cannot read vim's regexp yet.

exu commented 10 years ago

feel free to make pull request, I'm not able to repair this now.

Phone911 commented 9 years ago

I think changing "syn region pgsqlString start=+\$\z(\w*)\$+ end=+\$\z1\$+" to:

syn match pgsqlString "\$\w*\$"

seems to solve this problem. Not knowing vimscript or syntax highlighting well enough, i am not certain that it does not cause other issues.

chrisbouchard commented 9 years ago

@Phone911, if I understand your change correctly, then all dollar-sign-quoted strings would only have their quotes highlighted. That feels a bit like throwing the baby out with the bathwater. It might be possible to only highlight strings that way if they're in the AS position of a CREATE FUNCTION statement.

We could create a new region like:

syn region pgsqlFunctionBody start=+[aA][sS]\s*\$\z(\w*\)\$+ end=+\$\z1\$+

But I'm not sure yet where to go from there. If I come up with anything, I'll make a pull request.

chrisbouchard commented 9 years ago

After some playing around, I don't think my suggestion is very feasible. It seems like @Phone911's suggestion is the right solution.