|
11 | 11 | })(function(CodeMirror) { |
12 | 12 | "use strict"; |
13 | 13 |
|
| 14 | +function Context(indented, column, type, align, prev) { |
| 15 | + this.indented = indented; |
| 16 | + this.column = column; |
| 17 | + this.type = type; |
| 18 | + this.align = align; |
| 19 | + this.prev = prev; |
| 20 | +} |
| 21 | +function isStatement(type) { |
| 22 | + return type == "statement" || type == "switchstatement" || type == "namespace"; |
| 23 | +} |
| 24 | +function pushContext(state, col, type) { |
| 25 | + var indent = state.indented; |
| 26 | + if (state.context && isStatement(state.context.type) && !isStatement(type)) |
| 27 | + indent = state.context.indented; |
| 28 | + return state.context = new Context(indent, col, type, null, state.context); |
| 29 | +} |
| 30 | +function popContext(state) { |
| 31 | + var t = state.context.type; |
| 32 | + if (t == ")" || t == "]" || t == "}") |
| 33 | + state.indented = state.context.indented; |
| 34 | + return state.context = state.context.prev; |
| 35 | +} |
| 36 | + |
| 37 | +function typeBefore(stream, state) { |
| 38 | + if (state.prevToken == "variable" || state.prevToken == "variable-3") return true; |
| 39 | + if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, stream.start))) return true; |
| 40 | +} |
| 41 | + |
| 42 | +function isTopScope(context) { |
| 43 | + for (;;) { |
| 44 | + if (!context || context.type == "top") return true; |
| 45 | + if (context.type == "}" && context.prev.type != "namespace") return false; |
| 46 | + context = context.prev; |
| 47 | + } |
| 48 | +} |
| 49 | + |
14 | 50 | CodeMirror.defineMode("clike", function(config, parserConfig) { |
15 | 51 | var indentUnit = config.indentUnit, |
16 | 52 | statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, |
@@ -111,42 +147,6 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { |
111 | 147 | return "comment"; |
112 | 148 | } |
113 | 149 |
|
114 | | - function Context(indented, column, type, align, prev) { |
115 | | - this.indented = indented; |
116 | | - this.column = column; |
117 | | - this.type = type; |
118 | | - this.align = align; |
119 | | - this.prev = prev; |
120 | | - } |
121 | | - function isStatement(type) { |
122 | | - return type == "statement" || type == "switchstatement" || type == "namespace"; |
123 | | - } |
124 | | - function pushContext(state, col, type) { |
125 | | - var indent = state.indented; |
126 | | - if (state.context && isStatement(state.context.type) && !isStatement(type)) |
127 | | - indent = state.context.indented; |
128 | | - return state.context = new Context(indent, col, type, null, state.context); |
129 | | - } |
130 | | - function popContext(state) { |
131 | | - var t = state.context.type; |
132 | | - if (t == ")" || t == "]" || t == "}") |
133 | | - state.indented = state.context.indented; |
134 | | - return state.context = state.context.prev; |
135 | | - } |
136 | | - |
137 | | - function typeBefore(stream, state) { |
138 | | - if (state.prevToken == "variable" || state.prevToken == "variable-3") return true; |
139 | | - if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, stream.start))) return true; |
140 | | - } |
141 | | - |
142 | | - function isTopScope(context) { |
143 | | - for (;;) { |
144 | | - if (!context || context.type == "top") return true; |
145 | | - if (context.type == "}" && context.prev.type != "namespace") return false; |
146 | | - context = context.prev; |
147 | | - } |
148 | | - } |
149 | | - |
150 | 150 | // Interface |
151 | 151 |
|
152 | 152 | return { |
@@ -497,7 +497,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { |
497 | 497 | ), |
498 | 498 | types: words( |
499 | 499 | "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " + |
500 | | - "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " + |
| 500 | + "Enumeration Equiv Error Exception Fractional Function IndexedSeq Int Integral Iterable " + |
501 | 501 | "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " + |
502 | 502 | "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " + |
503 | 503 | "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector " + |
@@ -527,6 +527,15 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { |
527 | 527 | "'": function(stream) { |
528 | 528 | stream.eatWhile(/[\w\$_\xa1-\uffff]/); |
529 | 529 | return "atom"; |
| 530 | + }, |
| 531 | + "=": function(stream, state) { |
| 532 | + var cx = state.context |
| 533 | + if (cx.type == "}" && cx.align && stream.eat(">")) { |
| 534 | + state.context = new Context(cx.indented, cx.column, cx.type, null, cx.prev) |
| 535 | + return "operator" |
| 536 | + } else { |
| 537 | + return false |
| 538 | + } |
530 | 539 | } |
531 | 540 | }, |
532 | 541 | modeProps: {closeBrackets: {triples: '"'}} |
|
0 commit comments