Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land PL/SQL mode by Peter Raganitsch
- Loading branch information
Showing
5 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>CodeMirror 2: Oracle PL/SQL mode</title> | ||
<link rel="stylesheet" href="../../lib/codemirror.css"> | ||
<script src="../../lib/codemirror.js"></script> | ||
<script src="plsql.js"></script> | ||
<link rel="stylesheet" href="plsql.css"> | ||
<link rel="stylesheet" href="../../css/docs.css"> | ||
<style>.CodeMirror {border: 2px inset #dee;}</style> | ||
</head> | ||
<body> | ||
<h1>CodeMirror 2: Oracle PL/SQL mode</h1> | ||
|
||
<form><textarea id="code" name="code"> | ||
-- Oracle PL/SQL Code Demo | ||
/* | ||
based on c-like mode, adapted to PL/SQL by Peter Raganitsch ( http://www.oracle-and-apex.com/ ) | ||
April 2011 | ||
*/ | ||
DECLARE | ||
vIdx NUMBER; | ||
vString VARCHAR2(100); | ||
cText CONSTANT VARCHAR2(100) := 'That''s it! Have fun with CodeMirror 2'; | ||
BEGIN | ||
vIdx := 0; | ||
-- | ||
FOR rDATA IN | ||
( SELECT * | ||
FROM EMP | ||
ORDER BY EMPNO | ||
) | ||
LOOP | ||
vIdx := vIdx + 1; | ||
vString := rDATA.EMPNO || ' - ' || rDATA.ENAME; | ||
-- | ||
UPDATE EMP | ||
SET SAL = SAL * 101/100 | ||
WHERE EMPNO = rDATA.EMPNO | ||
; | ||
END LOOP; | ||
-- | ||
SYS.DBMS_OUTPUT.Put_Line (cText); | ||
END; | ||
-- | ||
</textarea></form> | ||
|
||
<script> | ||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
lineNumbers: true, | ||
matchBrackets: true, | ||
indentUnit: 4, | ||
mode: "text/x-plsql" | ||
}); | ||
</script> | ||
|
||
<p> | ||
Simple mode that handles Oracle PL/SQL language (and Oracle SQL, of course). | ||
</p> | ||
|
||
<p><strong>MIME type defined:</strong> <code>text/x-plsql</code> | ||
(PLSQL code) | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
span.plsql-keyword { | ||
color: blue; | ||
} | ||
span.plsql-var { | ||
color: red; | ||
} | ||
span.plsql-comment { | ||
color: #AA7700; | ||
} | ||
span.plsql-string { | ||
color: green; | ||
} | ||
span.plsql-operator { | ||
color: blue; | ||
} | ||
span.plsql-word { | ||
color: black; | ||
} | ||
span.plsql-function { | ||
color: darkorange; | ||
} | ||
span.plsql-sqlplus { | ||
color: darkorange; | ||
} | ||
span.plsql-type { | ||
color: purple; | ||
} | ||
span.plsql-separator { | ||
color: #666666; | ||
} | ||
span.plsql-number { | ||
color: darkcyan; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
CodeMirror.defineMode("plsql", function(config, parserConfig) { | ||
var indentUnit = config.indentUnit, | ||
keywords = parserConfig.keywords, | ||
functions = parserConfig.functions, | ||
types = parserConfig.types, | ||
sqlplus = parserConfig.sqlplus, | ||
multiLineStrings = parserConfig.multiLineStrings; | ||
var isOperatorChar = /[+\-*&%=<>!?:\/|]/; | ||
function chain(stream, state, f) { | ||
state.tokenize = f; | ||
return f(stream, state); | ||
} | ||
|
||
var type; | ||
function ret(tp, style) { | ||
type = tp; | ||
return style; | ||
} | ||
|
||
function tokenBase(stream, state) { | ||
var ch = stream.next(); | ||
// start of string? | ||
if (ch == '"' || ch == "'") | ||
return chain(stream, state, tokenString(ch)); | ||
// is it one of the special signs []{}().,;? Seperator? | ||
else if (/[\[\]{}\(\),;\.]/.test(ch)) | ||
return ret(ch); | ||
// start of a number value? | ||
else if (/\d/.test(ch)) { | ||
stream.eatWhile(/[\w\.]/) | ||
return ret("number", "plsql-number"); | ||
} | ||
// multi line comment or simple operator? | ||
else if (ch == "/") { | ||
if (stream.eat("*")) { | ||
return chain(stream, state, tokenComment); | ||
} | ||
else { | ||
stream.eatWhile(isOperatorChar); | ||
return ret("operator", "plsql-operator"); | ||
} | ||
} | ||
// single line comment or simple operator? | ||
else if (ch == "-") { | ||
if (stream.eat("-")) { | ||
stream.skipToEnd(); | ||
return ret("comment", "plsql-comment"); | ||
} | ||
else { | ||
stream.eatWhile(isOperatorChar); | ||
return ret("operator", "plsql-operator"); | ||
} | ||
} | ||
// pl/sql variable? | ||
else if (ch == "@" || ch == "$") { | ||
stream.eatWhile(/[\w\d\$_]/); | ||
return ret("word", "plsql-var"); | ||
} | ||
// is it a operator? | ||
else if (isOperatorChar.test(ch)) { | ||
stream.eatWhile(isOperatorChar); | ||
return ret("operator", "plsql-operator"); | ||
} | ||
else { | ||
// get the whole word | ||
stream.eatWhile(/[\w\$_]/); | ||
// is it one of the listed keywords? | ||
if (keywords && keywords.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "plsql-keyword"); | ||
// is it one of the listed functions? | ||
if (functions && functions.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "plsql-function"); | ||
// is it one of the listed types? | ||
if (types && types.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "plsql-type"); | ||
// is it one of the listed sqlplus keywords? | ||
if (sqlplus && sqlplus.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "plsql-sqlplus"); | ||
// default: just a "word" | ||
return ret("word", "plsql-word"); | ||
} | ||
} | ||
|
||
function tokenString(quote) { | ||
return function(stream, state) { | ||
var escaped = false, next, end = false; | ||
while ((next = stream.next()) != null) { | ||
if (next == quote && !escaped) {end = true; break;} | ||
escaped = !escaped && next == "\\"; | ||
} | ||
if (end || !(escaped || multiLineStrings)) | ||
state.tokenize = tokenBase; | ||
return ret("string", "plsql-string"); | ||
}; | ||
} | ||
|
||
function tokenComment(stream, state) { | ||
var maybeEnd = false, ch; | ||
while (ch = stream.next()) { | ||
if (ch == "/" && maybeEnd) { | ||
state.tokenize = tokenBase; | ||
break; | ||
} | ||
maybeEnd = (ch == "*"); | ||
} | ||
return ret("comment", "plsql-comment"); | ||
} | ||
|
||
// Interface | ||
|
||
return { | ||
startState: function(basecolumn) { | ||
return { | ||
tokenize: tokenBase, | ||
indented: 0, | ||
startOfLine: true | ||
}; | ||
}, | ||
|
||
token: function(stream, state) { | ||
if (stream.eatSpace()) return null; | ||
var style = state.tokenize(stream, state); | ||
return style; | ||
} | ||
}; | ||
}); | ||
|
||
(function() { | ||
function keywords(str) { | ||
var obj = {}, words = str.split(" "); | ||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | ||
return obj; | ||
} | ||
var cKeywords = "abort accept access add all alter and any array arraylen as asc assert assign at attributes audit " + | ||
"authorization avg " + | ||
"base_table begin between binary_integer body boolean by " + | ||
"case cast char char_base check close cluster clusters colauth column comment commit compress connect " + | ||
"connected constant constraint crash create current currval cursor " + | ||
"data_base database date dba deallocate debugoff debugon decimal declare default definition delay delete " + | ||
"desc digits dispose distinct do drop " + | ||
"else elsif enable end entry escape exception exception_init exchange exclusive exists exit external " + | ||
"fast fetch file for force form from function " + | ||
"generic goto grant group " + | ||
"having " + | ||
"identified if immediate in increment index indexes indicator initial initrans insert interface intersect " + | ||
"into is " + | ||
"key " + | ||
"level library like limited local lock log logging long loop " + | ||
"master maxextents maxtrans member minextents minus mislabel mode modify multiset " + | ||
"new next no noaudit nocompress nologging noparallel not nowait number_base " + | ||
"object of off offline on online only open option or order out " + | ||
"package parallel partition pctfree pctincrease pctused pls_integer positive positiven pragma primary prior " + | ||
"private privileges procedure public " + | ||
"raise range raw read rebuild record ref references refresh release rename replace resource restrict return " + | ||
"returning reverse revoke rollback row rowid rowlabel rownum rows run " + | ||
"savepoint schema segment select separate session set share snapshot some space split sql start statement " + | ||
"storage subtype successful synonym " + | ||
"tabauth table tables tablespace task terminate then to trigger truncate type " + | ||
"union unique unlimited unrecoverable unusable update use using " + | ||
"validate value values variable view views " + | ||
"when whenever where while with work"; | ||
|
||
var cFunctions = "abs acos add_months ascii asin atan atan2 average " + | ||
"bfilename " + | ||
"ceil chartorowid chr concat convert cos cosh count " + | ||
"decode deref dual dump dup_val_on_index " + | ||
"empty error exp " + | ||
"false floor found " + | ||
"glb greatest " + | ||
"hextoraw " + | ||
"initcap instr instrb isopen " + | ||
"last_day least lenght lenghtb ln lower lpad ltrim lub " + | ||
"make_ref max min mod months_between " + | ||
"new_time next_day nextval nls_charset_decl_len nls_charset_id nls_charset_name nls_initcap nls_lower " + | ||
"nls_sort nls_upper nlssort no_data_found notfound null nvl " + | ||
"others " + | ||
"power " + | ||
"rawtohex reftohex round rowcount rowidtochar rpad rtrim " + | ||
"sign sin sinh soundex sqlcode sqlerrm sqrt stddev substr substrb sum sysdate " + | ||
"tan tanh to_char to_date to_label to_multi_byte to_number to_single_byte translate true trunc " + | ||
"uid upper user userenv " + | ||
"variance vsize"; | ||
|
||
var cTypes = "bfile blob " + | ||
"character clob " + | ||
"dec " + | ||
"float " + | ||
"int integer " + | ||
"mlslabel " + | ||
"natural naturaln nchar nclob number numeric nvarchar2 " + | ||
"real rowtype " + | ||
"signtype smallint string " + | ||
"varchar varchar2"; | ||
|
||
var cSqlplus = "appinfo arraysize autocommit autoprint autorecovery autotrace " + | ||
"blockterminator break btitle " + | ||
"cmdsep colsep compatibility compute concat copycommit copytypecheck " + | ||
"define describe " + | ||
"echo editfile embedded escape exec execute " + | ||
"feedback flagger flush " + | ||
"heading headsep " + | ||
"instance " + | ||
"linesize lno loboffset logsource long longchunksize " + | ||
"markup " + | ||
"native newpage numformat numwidth " + | ||
"pagesize pause pno " + | ||
"recsep recsepchar release repfooter repheader " + | ||
"serveroutput shiftinout show showmode size spool sqlblanklines sqlcase sqlcode sqlcontinue sqlnumber " + | ||
"sqlpluscompatibility sqlprefix sqlprompt sqlterminator suffix " + | ||
"tab term termout time timing trimout trimspool ttitle " + | ||
"underline " + | ||
"verify version " + | ||
"wrap"; | ||
|
||
CodeMirror.defineMIME("text/x-plsql", { | ||
name: "plsql", | ||
keywords: keywords(cKeywords), | ||
functions: keywords(cFunctions), | ||
types: keywords(cTypes), | ||
sqlplus: keywords(cSqlplus) | ||
}); | ||
}()); |