1
CodeMirror.defineMode("plsql", function(config, parserConfig) {
2
var indentUnit = config.indentUnit,
3
keywords = parserConfig.keywords,
4
functions = parserConfig.functions,
5
types = parserConfig.types,
6
sqlplus = parserConfig.sqlplus,
7
multiLineStrings = parserConfig.multiLineStrings;
8
var isOperatorChar = /[+\-*&%=<>!?:\/|]/;
9
function chain(stream, state, f) {
11
return f(stream, state);
15
function ret(tp, style) {
20
function tokenBase(stream, state) {
21
var ch = stream.next();
23
if (ch == '"' || ch == "'")
24
return chain(stream, state, tokenString(ch));
25
// is it one of the special signs []{}().,;? Seperator?
26
else if (/[\[\]{}\(\),;\.]/.test(ch))
28
// start of a number value?
29
else if (/\d/.test(ch)) {
30
stream.eatWhile(/[\w\.]/);
31
return ret("number", "number");
33
// multi line comment or simple operator?
35
if (stream.eat("*")) {
36
return chain(stream, state, tokenComment);
39
stream.eatWhile(isOperatorChar);
40
return ret("operator", "operator");
43
// single line comment or simple operator?
45
if (stream.eat("-")) {
47
return ret("comment", "comment");
50
stream.eatWhile(isOperatorChar);
51
return ret("operator", "operator");
55
else if (ch == "@" || ch == "$") {
56
stream.eatWhile(/[\w\d\$_]/);
57
return ret("word", "variable");
60
else if (isOperatorChar.test(ch)) {
61
stream.eatWhile(isOperatorChar);
62
return ret("operator", "operator");
66
stream.eatWhile(/[\w\$_]/);
67
// is it one of the listed keywords?
68
if (keywords && keywords.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "keyword");
69
// is it one of the listed functions?
70
if (functions && functions.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "builtin");
71
// is it one of the listed types?
72
if (types && types.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "variable-2");
73
// is it one of the listed sqlplus keywords?
74
if (sqlplus && sqlplus.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "variable-3");
75
// default: just a "word"
76
return ret("word", "plsql-word");
80
function tokenString(quote) {
81
return function(stream, state) {
82
var escaped = false, next, end = false;
83
while ((next = stream.next()) != null) {
84
if (next == quote && !escaped) {end = true; break;}
85
escaped = !escaped && next == "\\";
87
if (end || !(escaped || multiLineStrings))
88
state.tokenize = tokenBase;
89
return ret("string", "plsql-string");
93
function tokenComment(stream, state) {
94
var maybeEnd = false, ch;
95
while (ch = stream.next()) {
96
if (ch == "/" && maybeEnd) {
97
state.tokenize = tokenBase;
100
maybeEnd = (ch == "*");
102
return ret("comment", "plsql-comment");
108
startState: function(basecolumn) {
115
token: function(stream, state) {
116
if (stream.eatSpace()) return null;
117
var style = state.tokenize(stream, state);
124
function keywords(str) {
125
var obj = {}, words = str.split(" ");
126
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
129
var cKeywords = "abort accept access add all alter and any array arraylen as asc assert assign at attributes audit " +
130
"authorization avg " +
131
"base_table begin between binary_integer body boolean by " +
132
"case cast char char_base check close cluster clusters colauth column comment commit compress connect " +
133
"connected constant constraint crash create current currval cursor " +
134
"data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete " +
135
"desc digits dispose distinct do drop " +
136
"else elsif enable end entry escape exception exception_init exchange exclusive exists exit external " +
137
"fast fetch file for force form from function " +
138
"generic goto grant group " +
140
"identified if immediate in increment index indexes indicator initial initrans insert interface intersect " +
143
"level library like limited local lock log logging long loop " +
144
"master maxextents maxtrans member minextents minus mislabel mode modify multiset " +
145
"new next no noaudit nocompress nologging noparallel not nowait number_base " +
146
"object of off offline on online only open option or order out " +
147
"package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior " +
148
"private privileges procedure public " +
149
"raise range raw read rebuild record ref references refresh release rename replace resource restrict return " +
150
"returning reverse revoke rollback row rowid rowlabel rownum rows run " +
151
"savepoint schema segment select separate session set share snapshot some space split sql start statement " +
152
"storage subtype successful synonym " +
153
"tabauth table tables tablespace task terminate then to trigger truncate type " +
154
"union unique unlimited unrecoverable unusable update use using " +
155
"validate value values variable view views " +
156
"when whenever where while with work";
158
var cFunctions = "abs acos add_months ascii asin atan atan2 average " +
160
"ceil chartorowid chr concat convert cos cosh count " +
161
"decode deref dual dump dup_val_on_index " +
163
"false floor found " +
166
"initcap instr instrb isopen " +
167
"last_day least lenght lenghtb ln lower lpad ltrim lub " +
168
"make_ref max min mod months_between " +
169
"new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower " +
170
"nls_sort nls_upper nlssort no_data_found notfound null nvl " +
173
"rawtohex reftohex round rowcount rowidtochar rpad rtrim " +
174
"sign sin sinh soundex sqlcode sqlerrm sqrt stddev substr substrb sum sysdate " +
175
"tan tanh to_char to_date to_label to_multi_byte to_number to_single_byte translate true trunc " +
176
"uid upper user userenv " +
179
var cTypes = "bfile blob " +
185
"natural naturaln nchar nclob number numeric nvarchar2 " +
187
"signtype smallint string " +
190
var cSqlplus = "appinfo arraysize autocommit autoprint autorecovery autotrace " +
191
"blockterminator break btitle " +
192
"cmdsep colsep compatibility compute concat copycommit copytypecheck " +
194
"echo editfile embedded escape exec execute " +
195
"feedback flagger flush " +
198
"linesize lno loboffset logsource long longchunksize " +
200
"native newpage numformat numwidth " +
201
"pagesize pause pno " +
202
"recsep recsepchar release repfooter repheader " +
203
"serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber " +
204
"sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix " +
205
"tab term termout time timing trimout trimspool ttitle " +
210
CodeMirror.defineMIME("text/x-plsql", {
212
keywords: keywords(cKeywords),
213
functions: keywords(cFunctions),
214
types: keywords(cTypes),
215
sqlplus: keywords(cSqlplus)