diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 3d1899ec..85b013eb 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -224,29 +224,22 @@ module Linguist end end disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data| - match = nil - #unique keywords for each language - plpgsqlkeywords = [/^\\i\b/i, /begin ?(work|transaction)?;/i , /AS \$\$/i, /RAISE EXCEPTION/i, /LANGUAGE plpgsql\b/i ] - plsqlkeywords = [ /pragma\b/i , /constructor\W+function\b/i] - #sqlplkeywords = [ ] + #only return value if a definite positive - #common keywords that are not SQL - plkeywords = [/begin\b/i,/boolean\b/i, /package\b/i,/exception\b/i, /^end;\b/i ] - - re = Regexp.union(plpgsqlkeywords) - if data.match(re) - match = Language["PLpgSQL"] - else - re = Regexp.union(plsqlkeywords) - if data.match(re) - match= Language["PLSQL"] - else - re = Regexp.union(plkeywords) - match= Language["SQL"] if ! data.match(re) - end + if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN (WORK|TRANSACTION)+;/i.match(data) + #postgres + Language["PLpgSQL"] + elsif /(alter module)|(language sql)|(begin( NOT)+ atomic)/i.match(data) || /signal SQLSTATE '[0-9]+'/i.match(data) + #ibm db2 + Language["SQLPL"] + elsif /pragma|\$\$PLSQL_|XMLTYPE|sysdate|systimestamp|\.nextval|connect by|AUTHID (DEFINER|CURRENT_USER)/i.match(data) || /constructor\W+function/i.match(data) + #oraclestuff + Language["PLSQL"] + elsif ! /begin|boolean|package|exception/i.match(data) + #generic sql + Language["SQL"] end - match end end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 2ea132d5..c26884b4 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2696,13 +2696,13 @@ SQL: - .viw #IBM DB2 -#SQLPL: - #type: programming - #ace_mode: sql - #tm_scope: source.sql - #extensions: - #- .sql - #- .db2 +SQLPL: + type: programming + ace_mode: sql + tm_scope: source.sql + extensions: + - .sql + - .db2 STON: type: data diff --git a/samples/SQLPL/sleep.sql b/samples/SQLPL/sleep.sql new file mode 100644 index 00000000..18f72055 --- /dev/null +++ b/samples/SQLPL/sleep.sql @@ -0,0 +1,9 @@ +create procedure sleep (in sleeptime integer) +begin + declare wait_until timestamp; + + set wait_until = (current timestamp + sleeptime seconds); + while (wait_until > current timestamp) + do + end while; +end!