diff options
author | Nivesh Rajbhandari | 2012-02-20 11:14:44 -0800 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-02-20 11:14:44 -0800 |
commit | abf78e2d7a97d295ce5a1c425fd359d47379137e (patch) | |
tree | d08c91bd2aef31e6325e0b499b2ffc390018bec6 /imports/codemirror/mode/plsql | |
parent | e80a79bff57fecf3aa9b869d8ed2de5fd815287c (diff) | |
parent | e23708721a71ca4c71365f5f8e8ac7d6113926db (diff) | |
download | ninja-abf78e2d7a97d295ce5a1c425fd359d47379137e.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'imports/codemirror/mode/plsql')
-rwxr-xr-x | imports/codemirror/mode/plsql/index.html | 62 | ||||
-rwxr-xr-x | imports/codemirror/mode/plsql/plsql.js | 217 |
2 files changed, 279 insertions, 0 deletions
diff --git a/imports/codemirror/mode/plsql/index.html b/imports/codemirror/mode/plsql/index.html new file mode 100755 index 00000000..be603d99 --- /dev/null +++ b/imports/codemirror/mode/plsql/index.html | |||
@@ -0,0 +1,62 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: 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="../../doc/docs.css"> | ||
9 | <style>.CodeMirror {border: 2px inset #dee;}</style> | ||
10 | </head> | ||
11 | <body> | ||
12 | <h1>CodeMirror: Oracle PL/SQL mode</h1> | ||
13 | |||
14 | <form><textarea id="code" name="code"> | ||
15 | -- Oracle PL/SQL Code Demo | ||
16 | /* | ||
17 | based on c-like mode, adapted to PL/SQL by Peter Raganitsch ( http://www.oracle-and-apex.com/ ) | ||
18 | April 2011 | ||
19 | */ | ||
20 | DECLARE | ||
21 | vIdx NUMBER; | ||
22 | vString VARCHAR2(100); | ||
23 | cText CONSTANT VARCHAR2(100) := 'That''s it! Have fun with CodeMirror 2'; | ||
24 | BEGIN | ||
25 | vIdx := 0; | ||
26 | -- | ||
27 | FOR rDATA IN | ||
28 | ( SELECT * | ||
29 | FROM EMP | ||
30 | ORDER BY EMPNO | ||
31 | ) | ||
32 | LOOP | ||
33 | vIdx := vIdx + 1; | ||
34 | vString := rDATA.EMPNO || ' - ' || rDATA.ENAME; | ||
35 | -- | ||
36 | UPDATE EMP | ||
37 | SET SAL = SAL * 101/100 | ||
38 | WHERE EMPNO = rDATA.EMPNO | ||
39 | ; | ||
40 | END LOOP; | ||
41 | -- | ||
42 | SYS.DBMS_OUTPUT.Put_Line (cText); | ||
43 | END; | ||
44 | -- | ||
45 | </textarea></form> | ||
46 | |||
47 | <script> | ||
48 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
49 | lineNumbers: true, | ||
50 | matchBrackets: true, | ||
51 | indentUnit: 4, | ||
52 | mode: "text/x-plsql" | ||
53 | }); | ||
54 | </script> | ||
55 | |||
56 | <p> | ||
57 | Simple mode that handles Oracle PL/SQL language (and Oracle SQL, of course). | ||
58 | </p> | ||
59 | |||
60 | <p><strong>MIME type defined:</strong> <code>text/x-plsql</code> | ||
61 | (PLSQL code) | ||
62 | </html> | ||
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 @@ | |||
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) { | ||
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 |