2
0

plsql.js 8.2 KB

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