aboutsummaryrefslogtreecommitdiff
path: root/js/codemirror/mode/plsql
diff options
context:
space:
mode:
Diffstat (limited to 'js/codemirror/mode/plsql')
-rw-r--r--js/codemirror/mode/plsql/index.html63
-rw-r--r--js/codemirror/mode/plsql/plsql.js217
2 files changed, 280 insertions, 0 deletions
diff --git a/js/codemirror/mode/plsql/index.html b/js/codemirror/mode/plsql/index.html
new file mode 100644
index 00000000..8c7bf7ca
--- /dev/null
+++ b/js/codemirror/mode/plsql/index.html
@@ -0,0 +1,63 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror 2: Oracle PL/SQL mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="plsql.js"></script>
8 <link rel="stylesheet" href="../../theme/default.css">
9 <link rel="stylesheet" href="../../css/docs.css">
10 <style>.CodeMirror {border: 2px inset #dee;}</style>
11 </head>
12 <body>
13 <h1>CodeMirror 2: Oracle PL/SQL mode</h1>
14
15<form><textarea id="code" name="code">
16-- Oracle PL/SQL Code Demo
17/*
18 based on c-like mode, adapted to PL/SQL by Peter Raganitsch ( http://www.oracle-and-apex.com/ )
19 April 2011
20*/
21DECLARE
22 vIdx NUMBER;
23 vString VARCHAR2(100);
24 cText CONSTANT VARCHAR2(100) := 'That''s it! Have fun with CodeMirror 2';
25BEGIN
26 vIdx := 0;
27 --
28 FOR rDATA IN
29 ( SELECT *
30 FROM EMP
31 ORDER BY EMPNO
32 )
33 LOOP
34 vIdx := vIdx + 1;
35 vString := rDATA.EMPNO || ' - ' || rDATA.ENAME;
36 --
37 UPDATE EMP
38 SET SAL = SAL * 101/100
39 WHERE EMPNO = rDATA.EMPNO
40 ;
41 END LOOP;
42 --
43 SYS.DBMS_OUTPUT.Put_Line (cText);
44END;
45--
46</textarea></form>
47
48 <script>
49 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
50 lineNumbers: true,
51 matchBrackets: true,
52 indentUnit: 4,
53 mode: "text/x-plsql"
54 });
55 </script>
56
57 <p>
58 Simple mode that handles Oracle PL/SQL language (and Oracle SQL, of course).
59 </p>
60
61 <p><strong>MIME type defined:</strong> <code>text/x-plsql</code>
62 (PLSQL code)
63</html>
diff --git a/js/codemirror/mode/plsql/plsql.js b/js/codemirror/mode/plsql/plsql.js
new file mode 100644
index 00000000..a2ac2e8d
--- /dev/null
+++ b/js/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 " +