| OLD | NEW |
| 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others | 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others |
| 2 // Distributed under an MIT license: http://codemirror.net/LICENSE | 2 // Distributed under an MIT license: http://codemirror.net/LICENSE |
| 3 | 3 |
| 4 /** | 4 /** |
| 5 * Author: Hans Engel | 5 * Author: Hans Engel |
| 6 * Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementatio
n by Koh Zi Chun) | 6 * Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementatio
n by Koh Zi Chun) |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 (function(mod) { | 9 (function(mod) { |
| 10 if (typeof exports == "object" && typeof module == "object") // CommonJS | 10 if (typeof exports == "object" && typeof module == "object") // CommonJS |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 function makeKeywords(str) { | 25 function makeKeywords(str) { |
| 26 var obj = {}, words = str.split(" "); | 26 var obj = {}, words = str.split(" "); |
| 27 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | 27 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; |
| 28 return obj; | 28 return obj; |
| 29 } | 29 } |
| 30 | 30 |
| 31 var atoms = makeKeywords("true false nil"); | 31 var atoms = makeKeywords("true false nil"); |
| 32 | 32 |
| 33 var keywords = makeKeywords( | 33 var keywords = makeKeywords( |
| 34 "defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype
defprotocol defrecord defproject deftest slice defalias defhinted defmacro- def
n-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do c
ase cond condp for loop recur when when-not when-let when-first if if-let if-not
. .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport n
s in-ns refer try catch finally throw with-open with-local-vars binding gen-clas
s gen-and-load-class gen-and-save-class handler-case handle"); | 34 "defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype
defprotocol defrecord defproject deftest " + |
| 35 "slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbo
und defunbound- defvar defvar- let letfn " + |
| 36 "do case cond condp for loop recur when when-not when-let when-first if if
-let if-not . .. -> ->> doto and or dosync " + |
| 37 "doseq dotimes dorun doall load import unimport ns in-ns refer try catch f
inally throw with-open with-local-vars " + |
| 38 "binding gen-class gen-and-load-class gen-and-save-class handler-case hand
le"); |
| 35 | 39 |
| 36 var builtins = makeKeywords( | 40 var builtins = makeKeywords( |
| 37 "* *' *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version
* *command-line-args* *compile-files* *compile-path* *compiler-options* *data-re
aders* *e *err* *file* *flush-on-newline* *fn-loader* *in* *math-context* *ns* *
out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *rea
d-eval* *source-path* *unchecked-math* *use-context-classloader* *verbose-defrec
ords* *warn-on-reflection* + +' - -' -> ->> ->ArrayChunk ->Vec ->VecNode ->VecSe
q -cache-protocol-fn -reset-methods .. / < <= = == > >= EMPTY-NODE accessor aclo
ne add-classpath add-watch agent agent-error agent-errors aget alength alias all
-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map
aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long
aset-short assert assoc assoc! assoc-in associative? atom await await-for await1
bases bean bigdec bigint biginteger binding bit-and bit-and-not bit-clear bit-f
lip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boole
an boolean-array booleans bound-fn bound-fn* bound? butlast byte byte-array byte
s case cast char char-array char-escape-string char-name-string char? chars chun
k chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked
-seq? class class? clear-agent-errors clojure-version coll? comment commute comp
comparator compare compare-and-set! compile complement concat cond condp conj c
onj! cons constantly construct-proxy contains? count counted? create-ns create-s
truct cycle dec dec' decimal? declare default-data-readers definline definterfac
e defmacro defmethod defmulti defn defn- defonce defprotocol defrecord defstruct
deftype delay delay? deliver denominator deref derive descendants destructure d
isj disj! dissoc dissoc! distinct distinct? doall dorun doseq dosync dotimes dot
o double double-array doubles drop drop-last drop-while empty empty? ensure enum
eration-seq error-handler error-mode eval even? every-pred every? ex-data ex-inf
o extend extend-protocol extend-type extenders extends? false? ffirst file-seq f
ilter filterv find find-keyword find-ns find-protocol-impl find-protocol-method
find-var first flatten float float-array float? floats flush fn fn? fnext fnil f
or force format frequencies future future-call future-cancel future-cancelled? f
uture-done? future? gen-class gen-interface gensym get get-in get-method get-pro
xy-class get-thread-bindings get-validator group-by hash hash-combine hash-map h
ash-set identical? identity if-let if-not ifn? import in-ns inc inc' init-proxy
instance? int int-array integer? interleave intern interpose into into-array int
s io! isa? iterate iterator-seq juxt keep keep-indexed key keys keyword keyword?
last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-
reader load-string loaded-libs locking long long-array longs loop macroexpand ma
croexpand-1 make-array make-hierarchy map map-indexed map? mapcat mapv max max-k
ey memfn memoize merge merge-with meta method-sig methods min min-key mod munge
name namespace namespace-munge neg? newline next nfirst nil? nnext not not-any?
not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-
publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext nthrest num number?
numerator object-array odd? or parents partial partition partition-all partitio
n-by pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str pr
efer-method prefers primitives-classnames print print-ctor print-dup print-metho
d print-simple print-str printf println println-str prn prn-str promise proxy pr
oxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings p
values quot rand rand-int rand-nth range ratio? rational? rationalize re-find re
-groups re-matcher re-matches re-pattern re-seq read read-line read-string reali
zed? reduce reduce-kv reductions ref ref-history-count ref-max-history ref-min-h
istory ref-set refer refer-clojure reify release-pending-sends rem remove remove
-all-methods remove-method remove-ns remove-watch repeat repeatedly replace repl
icate require reset! reset-meta! resolve rest restart-agent resultset-seq revers
e reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq?
seque sequence sequential? set set-error-handler! set-error-mode! set-validator!
set? short short-array shorts shuffle shutdown-agents slurp some some-fn sort s
ort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-symbol?
spit split-at split-with str string? struct struct-map subs subseq subvec super
s swap! symbol symbol? sync take take-last take-nth take-while test the-ns threa
d-bound? time to-array to-array-2d trampoline transient tree-seq true? type unch
ecked-add unchecked-add-int unchecked-byte unchecked-char unchecked-dec unchecke
d-dec-int unchecked-divide-int unchecked-double unchecked-float unchecked-inc un
checked-inc-int unchecked-int unchecked-long unchecked-multiply unchecked-multip
ly-int unchecked-negate unchecked-negate-int unchecked-remainder-int unchecked-s
hort unchecked-subtract unchecked-subtract-int underive unquote unquote-splicing
update-in update-proxy use val vals var-get var-set var? vary-meta vec vector v
ector-of vector? when when-first when-let when-not while with-bindings with-bind
ings* with-in-str with-loading-context with-local-vars with-meta with-open with-
out-str with-precision with-redefs with-redefs-fn xml-seq zero? zipmap *default-
data-reader-fn* as-> cond-> cond->> reduced reduced? send-via set-agent-send-exe
cutor! set-agent-send-off-executor! some-> some->>"); | 41 "* *' *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version
* *command-line-args* *compile-files* " + |
| 42 "*compile-path* *compiler-options* *data-readers* *e *err* *file* *flush
-on-newline* *fn-loader* *in* " + |
| 43 "*math-context* *ns* *out* *print-dup* *print-length* *print-level* *pri
nt-meta* *print-readably* *read-eval* " + |
| 44 "*source-path* *unchecked-math* *use-context-classloader* *verbose-defre
cords* *warn-on-reflection* + +' - -' -> " + |
| 45 "->> ->ArrayChunk ->Vec ->VecNode ->VecSeq -cache-protocol-fn -reset-met
hods .. / < <= = == > >= EMPTY-NODE accessor " + |
| 46 "aclone add-classpath add-watch agent agent-error agent-errors aget alen
gth alias all-ns alter alter-meta! " + |
| 47 "alter-var-root amap ancestors and apply areduce array-map aset aset-boo
lean aset-byte aset-char aset-double " + |
| 48 "aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in a
ssociative? atom await await-for await1 " + |
| 49 "bases bean bigdec bigint biginteger binding bit-and bit-and-not bit-cle
ar bit-flip bit-not bit-or bit-set " + |
| 50 "bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array b
ooleans bound-fn bound-fn* bound? butlast " + |
| 51 "byte byte-array bytes case cat cast char char-array char-escape-string
char-name-string char? chars chunk chunk-append " + |
| 52 "chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq?
class class? clear-agent-errors " + |
| 53 "clojure-version coll? comment commute comp comparator compare compare-a
nd-set! compile complement completing concat cond condp " + |
| 54 "conj conj! cons constantly construct-proxy contains? count counted? cre
ate-ns create-struct cycle dec dec' decimal? " + |
| 55 "declare dedupe default-data-readers definline definterface defmacro def
method defmulti defn defn- defonce defprotocol " + |
| 56 "defrecord defstruct deftype delay delay? deliver denominator deref deri
ve descendants destructure disj disj! dissoc " + |
| 57 "dissoc! distinct distinct? doall dorun doseq dosync dotimes doto double
double-array doubles drop drop-last " + |
| 58 "drop-while eduction empty empty? ensure enumeration-seq error-handler e
rror-mode eval even? every-pred every? ex-data ex-info " + |
| 59 "extend extend-protocol extend-type extenders extends? false? ffirst fil
e-seq filter filterv find find-keyword " + |
| 60 "find-ns find-protocol-impl find-protocol-method find-var first flatten
float float-array float? floats flush fn fn? " + |
| 61 "fnext fnil for force format frequencies future future-call future-cance
l future-cancelled? future-done? future? " + |
| 62 "gen-class gen-interface gensym get get-in get-method get-proxy-class ge
t-thread-bindings get-validator group-by hash " + |
| 63 "hash-combine hash-map hash-set identical? identity if-let if-not ifn? i
mport in-ns inc inc' init-proxy instance? " + |
| 64 "int int-array integer? interleave intern interpose into into-array ints
io! isa? iterate iterator-seq juxt keep " + |
| 65 "keep-indexed key keys keyword keyword? last lazy-cat lazy-seq let letfn
line-seq list list* list? load load-file " + |
| 66 "load-reader load-string loaded-libs locking long long-array longs loop
macroexpand macroexpand-1 make-array " + |
| 67 "make-hierarchy map map-indexed map? mapcat mapv max max-key memfn memoi
ze merge merge-with meta method-sig methods " + |
| 68 "min min-key mod munge name namespace namespace-munge neg? newline next
nfirst nil? nnext not not-any? not-empty " + |
| 69 "not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-p
ublics ns-refers ns-resolve ns-unalias " + |
| 70 "ns-unmap nth nthnext nthrest num number? numerator object-array odd? or
parents partial partition partition-all " + |
| 71 "partition-by pcalls peek persistent! pmap pop pop! pop-thread-bindings
pos? pr pr-str prefer-method prefers " + |
| 72 "primitives-classnames print print-ctor print-dup print-method print-sim
ple print-str printf println println-str " + |
| 73 "prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-na
me proxy-super push-thread-bindings pvalues " + |
| 74 "quot rand rand-int rand-nth random-sample range ratio? rational? ration
alize re-find re-groups re-matcher re-matches re-pattern " + |
| 75 "re-seq read read-line read-string realized? reduce reduce-kv reductions
ref ref-history-count ref-max-history " + |
| 76 "ref-min-history ref-set refer refer-clojure reify release-pending-sends
rem remove remove-all-methods " + |
| 77 "remove-method remove-ns remove-watch repeat repeatedly replace replicat
e require reset! reset-meta! resolve rest " + |
| 78 "restart-agent resultset-seq reverse reversible? rseq rsubseq satisfies?
second select-keys send send-off seq seq? " + |
| 79 "seque sequence sequential? set set-error-handler! set-error-mode! set-v
alidator! set? short short-array shorts " + |
| 80 "shuffle shutdown-agents slurp some some-fn sort sort-by sorted-map sort
ed-map-by sorted-set sorted-set-by sorted? " + |
| 81 "special-symbol? spit split-at split-with str string? struct struct-map
subs subseq subvec supers swap! symbol " + |
| 82 "symbol? sync take take-last take-nth take-while test the-ns thread-boun
d? time to-array to-array-2d trampoline transduce " + |
| 83 "transient tree-seq true? type unchecked-add unchecked-add-int unchecked
-byte unchecked-char unchecked-dec " + |
| 84 "unchecked-dec-int unchecked-divide-int unchecked-double unchecked-float
unchecked-inc unchecked-inc-int " + |
| 85 "unchecked-int unchecked-long unchecked-multiply unchecked-multiply-int
unchecked-negate unchecked-negate-int "+ |
| 86 "unchecked-remainder-int unchecked-short unchecked-subtract unchecked-su
btract-int underive unquote " + |
| 87 "unquote-splicing update update-in update-proxy use val vals var-get var
-set var? vary-meta vec vector vector-of " + |
| 88 "vector? volatile! volatile? vreset! vswap! when when-first when-let whe
n-not while with-bindings with-bindings* with-in-str with-loading-context " + |
| 89 "with-local-vars with-meta with-open with-out-str with-precision with-re
defs with-redefs-fn xml-seq zero? zipmap " + |
| 90 "*default-data-reader-fn* as-> cond-> cond->> reduced reduced? send-via
set-agent-send-executor! " + |
| 91 "set-agent-send-off-executor! some-> some->>"); |
| 38 | 92 |
| 39 var indentKeys = makeKeywords( | 93 var indentKeys = makeKeywords( |
| 40 // Built-ins | 94 // Built-ins |
| 41 "ns fn def defn defmethod bound-fn if if-not case condp when while when-
not when-first do future comment doto locking proxy with-open with-precision rei
fy deftype defrecord defprotocol extend extend-protocol extend-type try catch "
+ | 95 "ns fn def defn defmethod bound-fn if if-not case condp when while when-
not when-first do future comment doto " + |
| 96 "locking proxy with-open with-precision reify deftype defrecord defproto
col extend extend-protocol extend-type " + |
| 97 "try catch " + |
| 42 | 98 |
| 43 // Binding forms | 99 // Binding forms |
| 44 "let letfn binding loop for doseq dotimes when-let if-let " + | 100 "let letfn binding loop for doseq dotimes when-let if-let " + |
| 45 | 101 |
| 46 // Data structures | 102 // Data structures |
| 47 "defstruct struct-map assoc " + | 103 "defstruct struct-map assoc " + |
| 48 | 104 |
| 49 // clojure.test | 105 // clojure.test |
| 50 "testing deftest " + | 106 "testing deftest " + |
| 51 | 107 |
| 52 // contrib | 108 // contrib |
| 53 "handler-case handle dotrace deftrace"); | 109 "handler-case handle dotrace deftrace"); |
| 54 | 110 |
| 55 var tests = { | 111 var tests = { |
| 56 digit: /\d/, | 112 digit: /\d/, |
| 57 digit_or_colon: /[\d:]/, | 113 digit_or_colon: /[\d:]/, |
| 58 hex: /[0-9a-f]/i, | 114 hex: /[0-9a-f]/i, |
| 59 sign: /[+-]/, | 115 sign: /[+-]/, |
| 60 exponent: /e/i, | 116 exponent: /e/i, |
| 61 keyword_char: /[^\s\(\[\;\)\]]/, | 117 keyword_char: /[^\s\(\[\;\)\]]/, |
| 62 symbol: /[\w*+!\-\._?:<>\/\xa1-\uffff]/ | 118 symbol: /[\w*+!\-\._?:<>\/\xa1-\uffff]/, |
| 119 block_indent: /^(?:def|with)[^\/]+$|\/(?:def|with)/ |
| 63 }; | 120 }; |
| 64 | 121 |
| 65 function stateStack(indent, type, prev) { // represents a state stack object | 122 function stateStack(indent, type, prev) { // represents a state stack object |
| 66 this.indent = indent; | 123 this.indent = indent; |
| 67 this.type = type; | 124 this.type = type; |
| 68 this.prev = prev; | 125 this.prev = prev; |
| 69 } | 126 } |
| 70 | 127 |
| 71 function pushStack(state, indent, type) { | 128 function pushStack(state, indent, type) { |
| 72 state.indentStack = new stateStack(indent, type, state.indentStack); | 129 state.indentStack = new stateStack(indent, type, state.indentStack); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 ch = stream.next(); | 146 ch = stream.next(); |
| 90 } | 147 } |
| 91 | 148 |
| 92 if ( tests.digit.test(ch) ) { | 149 if ( tests.digit.test(ch) ) { |
| 93 stream.eat(ch); | 150 stream.eat(ch); |
| 94 stream.eatWhile(tests.digit); | 151 stream.eatWhile(tests.digit); |
| 95 | 152 |
| 96 if ( '.' == stream.peek() ) { | 153 if ( '.' == stream.peek() ) { |
| 97 stream.eat('.'); | 154 stream.eat('.'); |
| 98 stream.eatWhile(tests.digit); | 155 stream.eatWhile(tests.digit); |
| 156 } else if ('/' == stream.peek() ) { |
| 157 stream.eat('/'); |
| 158 stream.eatWhile(tests.digit); |
| 99 } | 159 } |
| 100 | 160 |
| 101 if ( stream.eat(tests.exponent) ) { | 161 if ( stream.eat(tests.exponent) ) { |
| 102 stream.eat(tests.sign); | 162 stream.eat(tests.sign); |
| 103 stream.eatWhile(tests.digit); | 163 stream.eatWhile(tests.digit); |
| 104 } | 164 } |
| 105 | 165 |
| 106 return true; | 166 return true; |
| 107 } | 167 } |
| 108 | 168 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 132 }; | 192 }; |
| 133 }, | 193 }, |
| 134 | 194 |
| 135 token: function (stream, state) { | 195 token: function (stream, state) { |
| 136 if (state.indentStack == null && stream.sol()) { | 196 if (state.indentStack == null && stream.sol()) { |
| 137 // update indentation, but only if indentStack is empty | 197 // update indentation, but only if indentStack is empty |
| 138 state.indentation = stream.indentation(); | 198 state.indentation = stream.indentation(); |
| 139 } | 199 } |
| 140 | 200 |
| 141 // skip spaces | 201 // skip spaces |
| 142 if (stream.eatSpace()) { | 202 if (state.mode != "string" && stream.eatSpace()) { |
| 143 return null; | 203 return null; |
| 144 } | 204 } |
| 145 var returnType = null; | 205 var returnType = null; |
| 146 | 206 |
| 147 switch(state.mode){ | 207 switch(state.mode){ |
| 148 case "string": // multi-line string parsing mode | 208 case "string": // multi-line string parsing mode |
| 149 var next, escaped = false; | 209 var next, escaped = false; |
| 150 while ((next = stream.next()) != null) { | 210 while ((next = stream.next()) != null) { |
| 151 if (next == "\"" && !escaped) { | 211 if (next == "\"" && !escaped) { |
| 152 | 212 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 180 (indent-word .. | 240 (indent-word .. |
| 181 (non-indent-word .. | 241 (non-indent-word .. |
| 182 (;something else, bracket, etc. | 242 (;something else, bracket, etc. |
| 183 */ | 243 */ |
| 184 | 244 |
| 185 if (ch == "(") while ((letter = stream.eat(tests.keyword
_char)) != null) { | 245 if (ch == "(") while ((letter = stream.eat(tests.keyword
_char)) != null) { |
| 186 keyWord += letter; | 246 keyWord += letter; |
| 187 } | 247 } |
| 188 | 248 |
| 189 if (keyWord.length > 0 && (indentKeys.propertyIsEnumerab
le(keyWord) || | 249 if (keyWord.length > 0 && (indentKeys.propertyIsEnumerab
le(keyWord) || |
| 190 /^(?:def|with)/.test(keyWord)
)) { // indent-word | 250 tests.block_indent.test(keyWo
rd))) { // indent-word |
| 191 pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); | 251 pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); |
| 192 } else { // non-indent word | 252 } else { // non-indent word |
| 193 // we continue eating the spaces | 253 // we continue eating the spaces |
| 194 stream.eatSpace(); | 254 stream.eatSpace(); |
| 195 if (stream.eol() || stream.peek() == ";") { | 255 if (stream.eol() || stream.peek() == ";") { |
| 196 // nothing significant after | 256 // nothing significant after |
| 197 // we restart indentation the user defined space
s after | 257 // we restart indentation the user defined space
s after |
| 198 pushStack(state, indentTemp + NORMAL_INDENT_UNIT
, ch); | 258 pushStack(state, indentTemp + NORMAL_INDENT_UNIT
, ch); |
| 199 } else { | 259 } else { |
| 200 pushStack(state, indentTemp + stream.current().l
ength, ch); // else we match | 260 pushStack(state, indentTemp + stream.current().l
ength, ch); // else we match |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (state.indentStack == null) return state.indentation; | 293 if (state.indentStack == null) return state.indentation; |
| 234 return state.indentStack.indent; | 294 return state.indentStack.indent; |
| 235 }, | 295 }, |
| 236 | 296 |
| 237 closeBrackets: {pairs: "()[]{}\"\""}, | 297 closeBrackets: {pairs: "()[]{}\"\""}, |
| 238 lineComment: ";;" | 298 lineComment: ";;" |
| 239 }; | 299 }; |
| 240 }); | 300 }); |
| 241 | 301 |
| 242 CodeMirror.defineMIME("text/x-clojure", "clojure"); | 302 CodeMirror.defineMIME("text/x-clojure", "clojure"); |
| 303 CodeMirror.defineMIME("text/x-clojurescript", "clojure"); |
| 304 CodeMirror.defineMIME("application/edn", "clojure"); |
| 243 | 305 |
| 244 }); | 306 }); |
| OLD | NEW |