Commits

Daniele Varrazzo  committed f9abff7

Parse the language of a PostgreSQL function also when prefix

This is the way pg_dump saves it.

  • Participants
  • Parent commits 9a1a9f6

Comments (0)

Files changed (2)

File pygments/lexers/postgres.py

     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))

File tests/examplefiles/postgresql_test.txt

 $$
 LANGUAGE plpgsql;
 
+-- As returned by pg_dump
+CREATE FUNCTION test_function() RETURNS integer
+    LANGUAGE plpgsql STABLE STRICT
+    AS $$
+begin
+    return 42;
+end
+$$;
+
+