diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-04-14 21:41:13 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-04-14 21:41:13 +0100 |
commit | b0d1f5926432a2ecd424ef3a55a9cc71b41f8779 (patch) | |
tree | 643212f41a8f88f59fd70640f22306862d6dd39b | |
parent | 01f3ba1b89485902663652b894454bd7d0097d6d (diff) | |
download | pygments-b0d1f5926432a2ecd424ef3a55a9cc71b41f8779.tar.gz |
Parse the language of a PostgreSQL function also when prefix
This is the way pg_dump saves it.
-rw-r--r-- | pygments/lexers/postgres.py | 8 | ||||
-rw-r--r-- | tests/examplefiles/postgresql_test.txt | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/pygments/lexers/postgres.py b/pygments/lexers/postgres.py index fe9a8a22..36717d4f 100644 --- a/pygments/lexers/postgres.py +++ b/pygments/lexers/postgres.py @@ -67,10 +67,14 @@ def language_callback(lexer, match): rules deepcopy fails in this case. """ l = None - # TODO: the language can also be before the string - m = language_re.match(lexer.text[match.end():]) + m = language_re.match(lexer.text[match.end():match.end()+100]) if m is not None: l = lexer._get_lexer(m.group(1)) + else: + m = list(language_re.finditer( + lexer.text[max(0, match.start()-100):match.start()])) + if m: + l = lexer._get_lexer(m[-1].group(1)) if l: yield (match.start(1), String, match.group(1)) diff --git a/tests/examplefiles/postgresql_test.txt b/tests/examplefiles/postgresql_test.txt index 23bb6d03..fa0914e3 100644 --- a/tests/examplefiles/postgresql_test.txt +++ b/tests/examplefiles/postgresql_test.txt @@ -32,3 +32,13 @@ END; $$ LANGUAGE plpgsql; +-- As returned by pg_dump +CREATE FUNCTION test_function() RETURNS integer + LANGUAGE plpgsql STABLE STRICT + AS $$ +begin + return 42; +end +$$; + + |