aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/pascal/pascal.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-24 12:08:49 -0800
committerPushkar Joshi2012-02-24 12:08:49 -0800
commit03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch)
treec51112223ceb9121cd595a60335eb2795215590f /imports/codemirror/mode/pascal/pascal.js
parentfcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff)
parent053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff)
downloadninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz
Merge branch 'pentool' into brushtool
Conflicts: imports/codemirror/mode/scheme/scheme.js js/tools/BrushTool.js
Diffstat (limited to 'imports/codemirror/mode/pascal/pascal.js')
-rwxr-xr-ximports/codemirror/mode/pascal/pascal.js138
1 files changed, 138 insertions, 0 deletions
diff --git a/imports/codemirror/mode/pascal/pascal.js b/imports/codemirror/mode/pascal/pascal.js
new file mode 100755
index 00000000..86c6f71c
--- /dev/null
+++ b/imports/codemirror/mode/pascal/pascal.js
@@ -0,0 +1,138 @@
1CodeMirror.defineMode("pascal", function(config) {
2 function words(str) {
3 var obj = {}, words = str.split(" ");
4 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5 return obj;
6 }
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 blockKeywords = words("case do else for if switch while struct then of");
11 var atoms = {"null": true};
12
13 var isOperatorChar = /[+\-*&%=<>!?|\/]/;
14 var curPunc;
15
16 function tokenBase(stream, state) {
17 var ch = stream.next();
18 if (ch == "#" && state.startOfLine) {
19 stream.skipToEnd();
20 return "meta";
21 }
22 if (ch == '"' || ch == "'") {
23 state.tokenize = tokenString(ch);
24 return state.tokenize(stream, state);
25 }
26 if (ch == "(" && stream.eat("*")) {
27 state.tokenize = tokenComment;
28 return tokenComment(stream, state);
29 }
30 if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
31 curPunc = ch;
32 return null
33 }
34 if (/\d/.test(ch)) {
35 stream.eatWhile(/[\w\.]/);
36 return "number";
37 }
38 if (ch == "/") {
39 if (stream.eat("/")) {
40 stream.skipToEnd();
41 return "comment";
42 }
43 }
44 if (isOperatorChar.test(ch)) {
45 stream.eatWhile(isOperatorChar);
46 return "operator";
47 }
48 stream.eatWhile(/[\w\$_]/);
49 var cur = stream.current();
50 if (keywords.propertyIsEnumerable(cur)) {
51 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
52 return "keyword";
53 }
54 if (atoms.propertyIsEnumerable(cur)) return "atom";
55 return "word";
56 }
57
58 function tokenString(quote) {
59 return function(stream, state) {
60 var escaped = false, next, end = false;
61 while ((next = stream.next()) != null) {
62 if (next == quote && !escaped) {end = true; break;}
63 escaped = !escaped && next == "\\";
64 }
65 if (end || !escaped) state.tokenize = null;
66 return "string";
67 };
68 }
69
70 function tokenComment(stream, state) {
71 var maybeEnd = false, ch;
72 while (ch = stream.next()) {
73 if (ch == ")" && maybeEnd) {
74 state.tokenize = null;
75 break;
76 }
77 maybeEnd = (ch == "*");
78 }
79 return "comment";
80 }
81
82 function Context(indented, column, type, align, prev) {
83 this.indented = indented;
84 this.column = column;
85 this.type = type;
86 this.align = align;
87 this.prev = prev;
88 }
89 function pushContext(state, col, type) {
90 return state.context = new Context(state.indented, col, type, null, state.context);
91 }
92 function popContext(state) {
93 var t = state.context.type;
94 if (t == ")" || t == "]" )
95 state.indented = state.context.indented;
96 return state.context = state.context.prev;
97 }
98
99 // Interface
100
101 return {
102 startState: function(basecolumn) {
103 return {
104 tokenize: null,
105 context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
106 indented: 0,
107 startOfLine: true
108 };
109 },
110
111 token: function(stream, state) {
112 var ctx = state.context;
113 if (stream.sol()) {
114 if (ctx.align == null) ctx.align = false;
115 state.indented = stream.indentation();
116 state.startOfLine = true;
117 }
118 if (stream.eatSpace()) return null;
119 curPunc = null;
120 var style = (state.tokenize || tokenBase)(stream, state);
121 if (style == "comment" || style == "meta") return style;
122 if (ctx.align == null) ctx.align = true;
123
124 if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
125 else if (curPunc == "[") pushContext(state, stream.column(), "]");
126 else if (curPunc == "(") pushContext(state, stream.column(), ")");
127 else if (curPunc == ctx.type) popContext(state);
128 else if ( ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
129 pushContext(state, stream.column(), "statement");
130 state.startOfLine = false;
131 return style;
132 },
133
134 electricChars: "{}"
135 };
136});
137
138CodeMirror.defineMIME("text/x-pascal", "pascal");