recode heuristic to use existing style. add additional sample

This commit is contained in:
David Pyke Le Brun
2015-02-09 14:16:25 +00:00
parent f570260dfe
commit e969172543
3 changed files with 29 additions and 27 deletions

View File

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

View File

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

9
samples/SQLPL/sleep.sql Normal file
View File

@@ -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!