5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("pascal", function() {
16
var obj = {}, words = str.split(" ");
17
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
21
"absolute and array asm begin case const constructor destructor div do " +
22
"downto else end file for function goto if implementation in inherited " +
23
"inline interface label mod nil not object of operator or packed procedure " +
24
"program record reintroduce repeat self set shl shr string then to type " +
25
"unit until uses var while with xor as class dispinterface except exports " +
26
"finalization finally initialization inline is library on out packed " +
27
"property raise resourcestring threadvar try absolute abstract alias " +
28
"assembler bitpacked break cdecl continue cppdecl cvar default deprecated " +
29
"dynamic enumerator experimental export external far far16 forward generic " +
30
"helper implements index interrupt iocheck local message name near " +
31
"nodefault noreturn nostackframe oldfpccall otherwise overload override " +
32
"pascal platform private protected public published read register " +
33
"reintroduce result safecall saveregisters softfloat specialize static " +
34
"stdcall stored strict unaligned unimplemented varargs virtual write");
35
var atoms = {"null": true};
37
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
39
function tokenBase(stream, state) {
40
var ch = stream.next();
41
if (ch == "#" && state.startOfLine) {
45
if (ch == '"' || ch == "'") {
46
state.tokenize = tokenString(ch);
47
return state.tokenize(stream, state);
49
if (ch == "(" && stream.eat("*")) {
50
state.tokenize = tokenComment;
51
return tokenComment(stream, state);
54
state.tokenize = tokenCommentBraces;
55
return tokenCommentBraces(stream, state);
57
if (/[\[\]\(\),;\:\.]/.test(ch)) {
61
stream.eatWhile(/[\w\.]/);
65
if (stream.eat("/")) {
70
if (isOperatorChar.test(ch)) {
71
stream.eatWhile(isOperatorChar);
74
stream.eatWhile(/[\w\$_]/);
75
var cur = stream.current();
76
if (keywords.propertyIsEnumerable(cur)) return "keyword";
77
if (atoms.propertyIsEnumerable(cur)) return "atom";
81
function tokenString(quote) {
82
return function(stream, state) {
83
var escaped = false, next, end = false;
84
while ((next = stream.next()) != null) {
85
if (next == quote && !escaped) {end = true; break;}
86
escaped = !escaped && next == "\\";
88
if (end || !escaped) state.tokenize = null;
93
function tokenComment(stream, state) {
94
var maybeEnd = false, ch;
95
while (ch = stream.next()) {
96
if (ch == ")" && maybeEnd) {
97
state.tokenize = null;
100
maybeEnd = (ch == "*");
105
function tokenCommentBraces(stream, state) {
107
while (ch = stream.next()) {
109
state.tokenize = null;
119
startState: function() {
120
return {tokenize: null};
123
token: function(stream, state) {
124
if (stream.eatSpace()) return null;
125
var style = (state.tokenize || tokenBase)(stream, state);
126
if (style == "comment" || style == "meta") return style;
134
CodeMirror.defineMIME("text/x-pascal", "pascal");