diff options
author | Ananya Sen | 2012-02-27 14:41:21 -0800 |
---|---|---|
committer | Ananya Sen | 2012-02-27 14:41:21 -0800 |
commit | 51ed781953bc44bba3c70938aa57b856394cbc88 (patch) | |
tree | 483bcacdcdcc6802d2d048b576406b111656fa05 /imports/codemirror/mode/pascal/pascal.js | |
parent | 15d00c49b522aa471d1ccfbbd33f5c0e721eb89e (diff) | |
download | ninja-51ed781953bc44bba3c70938aa57b856394cbc88.tar.gz |
updating to codemirror 2.22
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'imports/codemirror/mode/pascal/pascal.js')
-rw-r--r--[-rwxr-xr-x] | imports/codemirror/mode/pascal/pascal.js | 48 |
1 files changed, 2 insertions, 46 deletions
diff --git a/imports/codemirror/mode/pascal/pascal.js b/imports/codemirror/mode/pascal/pascal.js index 86c6f71c..9ac522f7 100755..100644 --- a/imports/codemirror/mode/pascal/pascal.js +++ b/imports/codemirror/mode/pascal/pascal.js | |||
@@ -7,11 +7,9 @@ CodeMirror.defineMode("pascal", function(config) { | |||
7 | var keywords = words("and array begin case const div do downto else end file for forward integer " + | 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 " + | 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"); | 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}; | 10 | var atoms = {"null": true}; |
12 | 11 | ||
13 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | 12 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; |
14 | var curPunc; | ||
15 | 13 | ||
16 | function tokenBase(stream, state) { | 14 | function tokenBase(stream, state) { |
17 | var ch = stream.next(); | 15 | var ch = stream.next(); |
@@ -28,7 +26,6 @@ CodeMirror.defineMode("pascal", function(config) { | |||
28 | return tokenComment(stream, state); | 26 | return tokenComment(stream, state); |
29 | } | 27 | } |
30 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | 28 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { |
31 | curPunc = ch; | ||
32 | return null | 29 | return null |
33 | } | 30 | } |
34 | if (/\d/.test(ch)) { | 31 | if (/\d/.test(ch)) { |
@@ -47,10 +44,7 @@ CodeMirror.defineMode("pascal", function(config) { | |||
47 | } | 44 | } |
48 | stream.eatWhile(/[\w\$_]/); | 45 | stream.eatWhile(/[\w\$_]/); |
49 | var cur = stream.current(); | 46 | var cur = stream.current(); |
50 | if (keywords.propertyIsEnumerable(cur)) { | 47 | if (keywords.propertyIsEnumerable(cur)) return "keyword"; |
51 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | ||
52 | return "keyword"; | ||
53 | } | ||
54 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | 48 | if (atoms.propertyIsEnumerable(cur)) return "atom"; |
55 | return "word"; | 49 | return "word"; |
56 | } | 50 | } |
@@ -79,55 +73,17 @@ CodeMirror.defineMode("pascal", function(config) { | |||
79 | return "comment"; | 73 | return "comment"; |
80 | } | 74 | } |
81 | 75 | ||
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 | 76 | // Interface |
100 | 77 | ||
101 | return { | 78 | return { |
102 | startState: function(basecolumn) { | 79 | startState: function(basecolumn) { |
103 | return { | 80 | return {tokenize: null}; |
104 | tokenize: null, | ||
105 | context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false), | ||
106 | indented: 0, | ||
107 | startOfLine: true | ||
108 | }; | ||
109 | }, | 81 | }, |
110 | 82 | ||
111 | token: function(stream, state) { | 83 | 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; | 84 | if (stream.eatSpace()) return null; |
119 | curPunc = null; | ||
120 | var style = (state.tokenize || tokenBase)(stream, state); | 85 | var style = (state.tokenize || tokenBase)(stream, state); |
121 | if (style == "comment" || style == "meta") return style; | 86 | 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; | 87 | return style; |
132 | }, | 88 | }, |
133 | 89 | ||