aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/plsql/plsql.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-02-20 11:14:44 -0800
committerNivesh Rajbhandari2012-02-20 11:14:44 -0800
commitabf78e2d7a97d295ce5a1c425fd359d47379137e (patch)
treed08c91bd2aef31e6325e0b499b2ffc390018bec6 /imports/codemirror/mode/plsql/plsql.js
parente80a79bff57fecf3aa9b869d8ed2de5fd815287c (diff)
parente23708721a71ca4c71365f5f8e8ac7d6113926db (diff)
downloadninja-abf78e2d7a97d295ce5a1c425fd359d47379137e.tar.gz
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'imports/codemirror/mode/plsql/plsql.js')
-rwxr-xr-ximports/codemirror/mode/plsql/plsql.js217
1 files changed, 217 insertions, 0 deletions
diff --git a/imports/codemirror/mode/plsql/plsql.js b/imports/codemirror/mode/plsql/plsql.js
new file mode 100755
index 00000000..a2ac2e8d
--- /dev/null
+++ b/imports/codemirror/mode/plsql/plsql.js
@@ -0,0 +1,217 @@
1CodeMirror.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) {
10 state.tokenize = f;
11 return f(stream, state);
12 }
13
14 var type;
15 function ret(tp, style) {
16 type = tp;
17 return style;
18 }
19
20 function tokenBase(stream, state) {
21 var ch = stream.next();
22 // start of string?
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))
27 return ret(ch);
28 // start of a number value?
29 else if (/\d/.test(ch)) {
30 stream.eatWhile(/[\w\.]/);
31 return ret("number", "number");
32 }
33 // multi line comment or simple operator?
34 else if (ch == "/") {
35 if (stream.eat("*")) {
36 return chain(stream, state, tokenComment);
37 }
38 else {
39 stream.eatWhile(isOperatorChar);
40 return ret("operator", "operator");
41 }
42 }
43 // single line comment or simple operator?
44 else if (ch == "-") {
45 if (stream.eat("-")) {
46 stream.skipToEnd();
47 return ret("comment", "comment");
48 }
49 else {
50 stream.eatWhile(isOperatorChar);
51 return ret("operator", "operator");
52 }
53 }
54 // pl/sql variable?
55 else if (ch == "@" || ch == "$") {
56 stream.eatWhile(/[\w\d\$_]/);
57 return ret("word", "variable");
58 }
59 // is it a operator?
60 else if (isOperatorChar.test(ch)) {
61 stream.eatWhile(isOperatorChar);
62 return ret("operator", "operator");
63 }
64 else {
65 // get the whole word
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");
77 }
78 }
79
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 == "\\";
86 }
87 if (end || !(escaped || multiLineStrings))
88 state.tokenize = tokenBase;
89 return ret("string", "plsql-string");
90 };
91 }
92
93 function tokenComment(stream, state) {
94 var maybeEnd = false, ch;
95 while (ch = stream.next()) {
96 if (ch == "/" && maybeEnd) {
97 state.tokenize = tokenBase;
98 break;
99 }
100 maybeEnd = (ch == "*");
101 }
102 return ret("comment", "plsql-comment");
103 }
104
105 // Interface
106
107 return {
108 startState: function(basecolumn) {
109 return {
110 tokenize: tokenBase,
111 startOfLine: true
112 };
113 },
114
115 token: function(stream, state) {
116 if (stream.eatSpace()) return null;
117 var style = state.tokenize(stream, state);
118 return style;
119 }
120 };
121});
122
123(function() {
124 function keywords(str) {
125 var obj = {}, words = str.split(" ");
126 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
127 return obj;
128 }
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 " +
139 "having " +
140 "identified if immediate in increment index indexes indicator initial initrans insert interface intersect " +
141 "into is " +
142 "key " +
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";
157
158 var cFunctions = "abs acos add_months ascii asin atan atan2 average " +
159 "bfilename " +
160 "ceil chartorowid chr concat convert cos cosh count " +
161 "decode deref dual dump dup_val_on_index " +
162 "empty error exp " +
163 "false floor found " +
164 "glb greatest " +
165 "hextoraw " +
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 " +
171 "others " +
172 "power " +
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 " +
177 "variance vsize";
178
179 var cTypes = "bfile blob " +
180 "character clob " +
181 "dec " +
182 "float " +
183 "int integer " +
184 "mlslabel " +
185 "natural naturaln nchar nclob number numeric nvarchar2 " +
186 "real rowtype " +
187 "signtype smallint string " +
188 "varchar varchar2";
189
190 var cSqlplus = "appinfo arraysize autocommit autoprint autorecovery autotrace " +
191 "blockterminator break btitle " +
192 "cmdsep colsep compatibility compute concat copycommit copytypecheck " +
193 "define describe " +
194 "echo editfile embedded escape exec execute " +
195 "feedback flagger flush " +
196 "heading headsep " +
197 "instance " +
198 "linesize lno loboffset logsource long longchunksize " +
199 "markup " +
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 " +
206 "underline " +
207 "verify version " +
208 "wrap";
209
210 CodeMirror.defineMIME("text/x-plsql", {
211 name: "plsql",
212 keywords: keywords(cKeywords),
213 functions: keywords(cFunctions),
214 types: keywords(cTypes),
215 sqlplus: keywords(cSqlplus)
216 });
217}());