1 CodeMirror.defineMode("pascal", function() {
3 var obj = {}, words = str.split(" ");
4 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
7 var keywords = words("and array begin case const div do downto else end file for forward integer " +
8 "boolean char function goto if in label mod nil not of or packed procedure " +
9 "program record repeat set string then to type until var while with");
10 var atoms = {"null": true};
12 var isOperatorChar = /[+\-*&%=<>!?|\/]/;
14 function tokenBase(stream, state) {
15 var ch = stream.next();
16 if (ch == "#" && state.startOfLine) {
20 if (ch == '"' || ch == "'") {
21 state.tokenize = tokenString(ch);
22 return state.tokenize(stream, state);
24 if (ch == "(" && stream.eat("*")) {
25 state.tokenize = tokenComment;
26 return tokenComment(stream, state);
28 if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
32 stream.eatWhile(/[\w\.]/);
36 if (stream.eat("/")) {
41 if (isOperatorChar.test(ch)) {
42 stream.eatWhile(isOperatorChar);
45 stream.eatWhile(/[\w\$_]/);
46 var cur = stream.current();
47 if (keywords.propertyIsEnumerable(cur)) return "keyword";
48 if (atoms.propertyIsEnumerable(cur)) return "atom";
52 function tokenString(quote) {
53 return function(stream, state) {
54 var escaped = false, next, end = false;
55 while ((next = stream.next()) != null) {
56 if (next == quote && !escaped) {end = true; break;}
57 escaped = !escaped && next == "\\";
59 if (end || !escaped) state.tokenize = null;
64 function tokenComment(stream, state) {
65 var maybeEnd = false, ch;
66 while (ch = stream.next()) {
67 if (ch == ")" && maybeEnd) {
68 state.tokenize = null;
71 maybeEnd = (ch == "*");
79 startState: function() {
80 return {tokenize: null};
83 token: function(stream, state) {
84 if (stream.eatSpace()) return null;
85 var style = (state.tokenize || tokenBase)(stream, state);
86 if (style == "comment" || style == "meta") return style;
94 CodeMirror.defineMIME("text/x-pascal", "pascal");