Show More
The requested changes are too big and content was truncated. Show full diff
@@ -0,0 +1,114 b'' | |||||
|
1 | (function() { | |||
|
2 | if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js"; | |||
|
3 | ||||
|
4 | var loading = {}; | |||
|
5 | function splitCallback(cont, n) { | |||
|
6 | var countDown = n; | |||
|
7 | return function() { if (--countDown == 0) cont(); }; | |||
|
8 | } | |||
|
9 | function ensureDeps(mode, cont) { | |||
|
10 | var deps = CodeMirror.modes[mode].dependencies; | |||
|
11 | if (!deps) return cont(); | |||
|
12 | var missing = []; | |||
|
13 | for (var i = 0; i < deps.length; ++i) { | |||
|
14 | if (!CodeMirror.modes.hasOwnProperty(deps[i])) | |||
|
15 | missing.push(deps[i]); | |||
|
16 | } | |||
|
17 | if (!missing.length) return cont(); | |||
|
18 | var split = splitCallback(cont, missing.length); | |||
|
19 | for (var i = 0; i < missing.length; ++i) | |||
|
20 | CodeMirror.requireMode(missing[i], split); | |||
|
21 | } | |||
|
22 | ||||
|
23 | CodeMirror.requireMode = function(mode, cont) { | |||
|
24 | if (typeof mode != "string") mode = mode.name; | |||
|
25 | if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont); | |||
|
26 | if (loading.hasOwnProperty(mode)) return loading[mode].push(cont); | |||
|
27 | ||||
|
28 | var script = document.createElement("script"); | |||
|
29 | script.src = CodeMirror.modeURL.replace(/%N/g, mode); | |||
|
30 | var others = document.getElementsByTagName("script")[0]; | |||
|
31 | others.parentNode.insertBefore(script, others); | |||
|
32 | var list = loading[mode] = [cont]; | |||
|
33 | var count = 0, poll = setInterval(function() { | |||
|
34 | if (++count > 100) return clearInterval(poll); | |||
|
35 | if (CodeMirror.modes.hasOwnProperty(mode)) { | |||
|
36 | clearInterval(poll); | |||
|
37 | loading[mode] = null; | |||
|
38 | ensureDeps(mode, function() { | |||
|
39 | for (var i = 0; i < list.length; ++i) list[i](); | |||
|
40 | }); | |||
|
41 | } | |||
|
42 | }, 200); | |||
|
43 | }; | |||
|
44 | ||||
|
45 | CodeMirror.autoLoadMode = function(instance, mode) { | |||
|
46 | if (!CodeMirror.modes.hasOwnProperty(mode)) | |||
|
47 | CodeMirror.requireMode(mode, function() { | |||
|
48 | instance.setOption("mode", instance.getOption("mode")); | |||
|
49 | }); | |||
|
50 | }; | |||
|
51 | }()); | |||
|
52 | ||||
|
53 | ||||
|
54 | //overlay plugin | |||
|
55 | ||||
|
56 | // Utility function that allows modes to be combined. The mode given | |||
|
57 | // as the base argument takes care of most of the normal mode | |||
|
58 | // functionality, but a second (typically simple) mode is used, which | |||
|
59 | // can override the style of text. Both modes get to parse all of the | |||
|
60 | // text, but when both assign a non-null style to a piece of code, the | |||
|
61 | // overlay wins, unless the combine argument was true, in which case | |||
|
62 | // the styles are combined. | |||
|
63 | ||||
|
64 | // overlayParser is the old, deprecated name | |||
|
65 | CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) { | |||
|
66 | return { | |||
|
67 | startState: function() { | |||
|
68 | return { | |||
|
69 | base: CodeMirror.startState(base), | |||
|
70 | overlay: CodeMirror.startState(overlay), | |||
|
71 | basePos: 0, baseCur: null, | |||
|
72 | overlayPos: 0, overlayCur: null | |||
|
73 | }; | |||
|
74 | }, | |||
|
75 | copyState: function(state) { | |||
|
76 | return { | |||
|
77 | base: CodeMirror.copyState(base, state.base), | |||
|
78 | overlay: CodeMirror.copyState(overlay, state.overlay), | |||
|
79 | basePos: state.basePos, baseCur: null, | |||
|
80 | overlayPos: state.overlayPos, overlayCur: null | |||
|
81 | }; | |||
|
82 | }, | |||
|
83 | ||||
|
84 | token: function(stream, state) { | |||
|
85 | if (stream.start == state.basePos) { | |||
|
86 | state.baseCur = base.token(stream, state.base); | |||
|
87 | state.basePos = stream.pos; | |||
|
88 | } | |||
|
89 | if (stream.start == state.overlayPos) { | |||
|
90 | stream.pos = stream.start; | |||
|
91 | state.overlayCur = overlay.token(stream, state.overlay); | |||
|
92 | state.overlayPos = stream.pos; | |||
|
93 | } | |||
|
94 | stream.pos = Math.min(state.basePos, state.overlayPos); | |||
|
95 | if (stream.eol()) state.basePos = state.overlayPos = 0; | |||
|
96 | ||||
|
97 | if (state.overlayCur == null) return state.baseCur; | |||
|
98 | if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur; | |||
|
99 | else return state.overlayCur; | |||
|
100 | }, | |||
|
101 | ||||
|
102 | indent: base.indent && function(state, textAfter) { | |||
|
103 | return base.indent(state.base, textAfter); | |||
|
104 | }, | |||
|
105 | electricChars: base.electricChars, | |||
|
106 | ||||
|
107 | innerMode: function(state) { return {state: state.base, mode: base}; }, | |||
|
108 | ||||
|
109 | blankLine: function(state) { | |||
|
110 | if (base.blankLine) base.blankLine(state.base); | |||
|
111 | if (overlay.blankLine) overlay.blankLine(state.overlay); | |||
|
112 | } | |||
|
113 | }; | |||
|
114 | }; |
@@ -0,0 +1,160 b'' | |||||
|
1 | CodeMirror.defineMode("apl", function() { | |||
|
2 | var builtInOps = { | |||
|
3 | ".": "innerProduct", | |||
|
4 | "\\": "scan", | |||
|
5 | "/": "reduce", | |||
|
6 | "⌿": "reduce1Axis", | |||
|
7 | "⍀": "scan1Axis", | |||
|
8 | "¨": "each", | |||
|
9 | "⍣": "power" | |||
|
10 | }; | |||
|
11 | var builtInFuncs = { | |||
|
12 | "+": ["conjugate", "add"], | |||
|
13 | "−": ["negate", "subtract"], | |||
|
14 | "×": ["signOf", "multiply"], | |||
|
15 | "÷": ["reciprocal", "divide"], | |||
|
16 | "⌈": ["ceiling", "greaterOf"], | |||
|
17 | "⌊": ["floor", "lesserOf"], | |||
|
18 | "∣": ["absolute", "residue"], | |||
|
19 | "⍳": ["indexGenerate", "indexOf"], | |||
|
20 | "?": ["roll", "deal"], | |||
|
21 | "⋆": ["exponentiate", "toThePowerOf"], | |||
|
22 | "⍟": ["naturalLog", "logToTheBase"], | |||
|
23 | "○": ["piTimes", "circularFuncs"], | |||
|
24 | "!": ["factorial", "binomial"], | |||
|
25 | "⌹": ["matrixInverse", "matrixDivide"], | |||
|
26 | "<": [null, "lessThan"], | |||
|
27 | "≤": [null, "lessThanOrEqual"], | |||
|
28 | "=": [null, "equals"], | |||
|
29 | ">": [null, "greaterThan"], | |||
|
30 | "≥": [null, "greaterThanOrEqual"], | |||
|
31 | "≠": [null, "notEqual"], | |||
|
32 | "≡": ["depth", "match"], | |||
|
33 | "≢": [null, "notMatch"], | |||
|
34 | "∈": ["enlist", "membership"], | |||
|
35 | "⍷": [null, "find"], | |||
|
36 | "∪": ["unique", "union"], | |||
|
37 | "∩": [null, "intersection"], | |||
|
38 | "∼": ["not", "without"], | |||
|
39 | "∨": [null, "or"], | |||
|
40 | "∧": [null, "and"], | |||
|
41 | "⍱": [null, "nor"], | |||
|
42 | "⍲": [null, "nand"], | |||
|
43 | "⍴": ["shapeOf", "reshape"], | |||
|
44 | ",": ["ravel", "catenate"], | |||
|
45 | "⍪": [null, "firstAxisCatenate"], | |||
|
46 | "⌽": ["reverse", "rotate"], | |||
|
47 | "⊖": ["axis1Reverse", "axis1Rotate"], | |||
|
48 | "⍉": ["transpose", null], | |||
|
49 | "↑": ["first", "take"], | |||
|
50 | "↓": [null, "drop"], | |||
|
51 | "⊂": ["enclose", "partitionWithAxis"], | |||
|
52 | "⊃": ["diclose", "pick"], | |||
|
53 | "⌷": [null, "index"], | |||
|
54 | "⍋": ["gradeUp", null], | |||
|
55 | "⍒": ["gradeDown", null], | |||
|
56 | "⊤": ["encode", null], | |||
|
57 | "⊥": ["decode", null], | |||
|
58 | "⍕": ["format", "formatByExample"], | |||
|
59 | "⍎": ["execute", null], | |||
|
60 | "⊣": ["stop", "left"], | |||
|
61 | "⊢": ["pass", "right"] | |||
|
62 | }; | |||
|
63 | ||||
|
64 | var isOperator = /[\.\/⌿⍀¨⍣]/; | |||
|
65 | var isNiladic = /⍬/; | |||
|
66 | var isFunction = /[\+−×÷⌈⌊∣⍳\?⋆⍟○!⌹<≤=>≥≠≡≢∈⍷∪∩∼∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢]/; | |||
|
67 | var isArrow = /←/; | |||
|
68 | var isComment = /[⍝#].*$/; | |||
|
69 | ||||
|
70 | var stringEater = function(type) { | |||
|
71 | var prev; | |||
|
72 | prev = false; | |||
|
73 | return function(c) { | |||
|
74 | prev = c; | |||
|
75 | if (c === type) { | |||
|
76 | return prev === "\\"; | |||
|
77 | } | |||
|
78 | return true; | |||
|
79 | }; | |||
|
80 | }; | |||
|
81 | return { | |||
|
82 | startState: function() { | |||
|
83 | return { | |||
|
84 | prev: false, | |||
|
85 | func: false, | |||
|
86 | op: false, | |||
|
87 | string: false, | |||
|
88 | escape: false | |||
|
89 | }; | |||
|
90 | }, | |||
|
91 | token: function(stream, state) { | |||
|
92 | var ch, funcName, word; | |||
|
93 | if (stream.eatSpace()) { | |||
|
94 | return null; | |||
|
95 | } | |||
|
96 | ch = stream.next(); | |||
|
97 | if (ch === '"' || ch === "'") { | |||
|
98 | stream.eatWhile(stringEater(ch)); | |||
|
99 | stream.next(); | |||
|
100 | state.prev = true; | |||
|
101 | return "string"; | |||
|
102 | } | |||
|
103 | if (/[\[{\(]/.test(ch)) { | |||
|
104 | state.prev = false; | |||
|
105 | return null; | |||
|
106 | } | |||
|
107 | if (/[\]}\)]/.test(ch)) { | |||
|
108 | state.prev = true; | |||
|
109 | return null; | |||
|
110 | } | |||
|
111 | if (isNiladic.test(ch)) { | |||
|
112 | state.prev = false; | |||
|
113 | return "niladic"; | |||
|
114 | } | |||
|
115 | if (/[¯\d]/.test(ch)) { | |||
|
116 | if (state.func) { | |||
|
117 | state.func = false; | |||
|
118 | state.prev = false; | |||
|
119 | } else { | |||
|
120 | state.prev = true; | |||
|
121 | } | |||
|
122 | stream.eatWhile(/[\w\.]/); | |||
|
123 | return "number"; | |||
|
124 | } | |||
|
125 | if (isOperator.test(ch)) { | |||
|
126 | return "operator apl-" + builtInOps[ch]; | |||
|
127 | } | |||
|
128 | if (isArrow.test(ch)) { | |||
|
129 | return "apl-arrow"; | |||
|
130 | } | |||
|
131 | if (isFunction.test(ch)) { | |||
|
132 | funcName = "apl-"; | |||
|
133 | if (builtInFuncs[ch] != null) { | |||
|
134 | if (state.prev) { | |||
|
135 | funcName += builtInFuncs[ch][1]; | |||
|
136 | } else { | |||
|
137 | funcName += builtInFuncs[ch][0]; | |||
|
138 | } | |||
|
139 | } | |||
|
140 | state.func = true; | |||
|
141 | state.prev = false; | |||
|
142 | return "function " + funcName; | |||
|
143 | } | |||
|
144 | if (isComment.test(ch)) { | |||
|
145 | stream.skipToEnd(); | |||
|
146 | return "comment"; | |||
|
147 | } | |||
|
148 | if (ch === "∘" && stream.peek() === ".") { | |||
|
149 | stream.next(); | |||
|
150 | return "function jot-dot"; | |||
|
151 | } | |||
|
152 | stream.eatWhile(/[\w\$_]/); | |||
|
153 | word = stream.current(); | |||
|
154 | state.prev = true; | |||
|
155 | return "keyword"; | |||
|
156 | } | |||
|
157 | }; | |||
|
158 | }); | |||
|
159 | ||||
|
160 | CodeMirror.defineMIME("text/apl", "apl"); |
@@ -0,0 +1,61 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: APL mode</title> | |||
|
6 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
7 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
8 | <script src="../../lib/codemirror.js"></script> | |||
|
9 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
10 | <script src="apl.js"></script> | |||
|
11 | <style> | |||
|
12 | .CodeMirror { border: 2px inset #dee; } | |||
|
13 | </style> | |||
|
14 | </head> | |||
|
15 | <body> | |||
|
16 | <h1>CodeMirror: APL mode</h1> | |||
|
17 | ||||
|
18 | <form><textarea id="code" name="code"> | |||
|
19 | ⍝ Conway's game of life | |||
|
20 | ||||
|
21 | ⍝ This example was inspired by the impressive demo at | |||
|
22 | ⍝ http://www.youtube.com/watch?v=a9xAKttWgP4 | |||
|
23 | ||||
|
24 | ⍝ Create a matrix: | |||
|
25 | ⍝ 0 1 1 | |||
|
26 | ⍝ 1 1 0 | |||
|
27 | ⍝ 0 1 0 | |||
|
28 | creature ← (3 3 ⍴ ⍳ 9) ∈ 1 2 3 4 7 ⍝ Original creature from demo | |||
|
29 | creature ← (3 3 ⍴ ⍳ 9) ∈ 1 3 6 7 8 ⍝ Glider | |||
|
30 | ||||
|
31 | ⍝ Place the creature on a larger board, near the centre | |||
|
32 | board ← ¯1 ⊖ ¯2 ⌽ 5 7 ↑ creature | |||
|
33 | ||||
|
34 | ⍝ A function to move from one generation to the next | |||
|
35 | life ← {∨/ 1 ⍵ ∧ 3 4 = ⊂+/ +⌿ 1 0 ¯1 ∘.⊖ 1 0 ¯1 ⌽¨ ⊂⍵} | |||
|
36 | ||||
|
37 | ⍝ Compute n-th generation and format it as a | |||
|
38 | ⍝ character matrix | |||
|
39 | gen ← {' #'[(life ⍣ ⍵) board]} | |||
|
40 | ||||
|
41 | ⍝ Show first three generations | |||
|
42 | (gen 1) (gen 2) (gen 3) | |||
|
43 | </textarea></form> | |||
|
44 | ||||
|
45 | <script> | |||
|
46 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
47 | lineNumbers: true, | |||
|
48 | matchBrackets: true, | |||
|
49 | mode: "text/apl" | |||
|
50 | }); | |||
|
51 | </script> | |||
|
52 | ||||
|
53 | <p>Simple mode that tries to handle APL as well as it can.</p> | |||
|
54 | <p>It attempts to label functions/operators based upon | |||
|
55 | monadic/dyadic usage (but this is far from fully fleshed out). | |||
|
56 | This means there are meaningful classnames so hover states can | |||
|
57 | have popups etc.</p> | |||
|
58 | ||||
|
59 | <p><strong>MIME types defined:</strong> <code>text/apl</code> (APL code)</p> | |||
|
60 | </body> | |||
|
61 | </html> |
@@ -0,0 +1,183 b'' | |||||
|
1 | /* | |||
|
2 | * ===================================================================================== | |||
|
3 | * | |||
|
4 | * Filename: mode/asterisk/asterisk.js | |||
|
5 | * | |||
|
6 | * Description: CodeMirror mode for Asterisk dialplan | |||
|
7 | * | |||
|
8 | * Created: 05/17/2012 09:20:25 PM | |||
|
9 | * Revision: none | |||
|
10 | * | |||
|
11 | * Author: Stas Kobzar (stas@modulis.ca), | |||
|
12 | * Company: Modulis.ca Inc. | |||
|
13 | * | |||
|
14 | * ===================================================================================== | |||
|
15 | */ | |||
|
16 | ||||
|
17 | CodeMirror.defineMode("asterisk", function() { | |||
|
18 | var atoms = ["exten", "same", "include","ignorepat","switch"], | |||
|
19 | dpcmd = ["#include","#exec"], | |||
|
20 | apps = [ | |||
|
21 | "addqueuemember","adsiprog","aelsub","agentlogin","agentmonitoroutgoing","agi", | |||
|
22 | "alarmreceiver","amd","answer","authenticate","background","backgrounddetect", | |||
|
23 | "bridge","busy","callcompletioncancel","callcompletionrequest","celgenuserevent", | |||
|
24 | "changemonitor","chanisavail","channelredirect","chanspy","clearhash","confbridge", | |||
|
25 | "congestion","continuewhile","controlplayback","dahdiacceptr2call","dahdibarge", | |||
|
26 | "dahdiras","dahdiscan","dahdisendcallreroutingfacility","dahdisendkeypadfacility", | |||
|
27 | "datetime","dbdel","dbdeltree","deadagi","dial","dictate","directory","disa", | |||
|
28 | "dumpchan","eagi","echo","endwhile","exec","execif","execiftime","exitwhile","extenspy", | |||
|
29 | "externalivr","festival","flash","followme","forkcdr","getcpeid","gosub","gosubif", | |||
|
30 | "goto","gotoif","gotoiftime","hangup","iax2provision","ices","importvar","incomplete", | |||
|
31 | "ivrdemo","jabberjoin","jabberleave","jabbersend","jabbersendgroup","jabberstatus", | |||
|
32 | "jack","log","macro","macroexclusive","macroexit","macroif","mailboxexists","meetme", | |||
|
33 | "meetmeadmin","meetmechanneladmin","meetmecount","milliwatt","minivmaccmess","minivmdelete", | |||
|
34 | "minivmgreet","minivmmwi","minivmnotify","minivmrecord","mixmonitor","monitor","morsecode", | |||
|
35 | "mp3player","mset","musiconhold","nbscat","nocdr","noop","odbc","odbc","odbcfinish", | |||
|
36 | "originate","ospauth","ospfinish","osplookup","ospnext","page","park","parkandannounce", | |||
|
37 | "parkedcall","pausemonitor","pausequeuemember","pickup","pickupchan","playback","playtones", | |||
|
38 | "privacymanager","proceeding","progress","queue","queuelog","raiseexception","read","readexten", | |||
|
39 | "readfile","receivefax","receivefax","receivefax","record","removequeuemember", | |||
|
40 | "resetcdr","retrydial","return","ringing","sayalpha","saycountedadj","saycountednoun", | |||
|
41 | "saycountpl","saydigits","saynumber","sayphonetic","sayunixtime","senddtmf","sendfax", | |||
|
42 | "sendfax","sendfax","sendimage","sendtext","sendurl","set","setamaflags", | |||
|
43 | "setcallerpres","setmusiconhold","sipaddheader","sipdtmfmode","sipremoveheader","skel", | |||
|
44 | "slastation","slatrunk","sms","softhangup","speechactivategrammar","speechbackground", | |||
|
45 | "speechcreate","speechdeactivategrammar","speechdestroy","speechloadgrammar","speechprocessingsound", | |||
|
46 | "speechstart","speechunloadgrammar","stackpop","startmusiconhold","stopmixmonitor","stopmonitor", | |||
|
47 | "stopmusiconhold","stopplaytones","system","testclient","testserver","transfer","tryexec", | |||
|
48 | "trysystem","unpausemonitor","unpausequeuemember","userevent","verbose","vmauthenticate", | |||
|
49 | "vmsayname","voicemail","voicemailmain","wait","waitexten","waitfornoise","waitforring", | |||
|
50 | "waitforsilence","waitmusiconhold","waituntil","while","zapateller" | |||
|
51 | ]; | |||
|
52 | ||||
|
53 | function basicToken(stream,state){ | |||
|
54 | var cur = ''; | |||
|
55 | var ch = ''; | |||
|
56 | ch = stream.next(); | |||
|
57 | // comment | |||
|
58 | if(ch == ";") { | |||
|
59 | stream.skipToEnd(); | |||
|
60 | return "comment"; | |||
|
61 | } | |||
|
62 | // context | |||
|
63 | if(ch == '[') { | |||
|
64 | stream.skipTo(']'); | |||
|
65 | stream.eat(']'); | |||
|
66 | return "header"; | |||
|
67 | } | |||
|
68 | // string | |||
|
69 | if(ch == '"') { | |||
|
70 | stream.skipTo('"'); | |||
|
71 | return "string"; | |||
|
72 | } | |||
|
73 | if(ch == "'") { | |||
|
74 | stream.skipTo("'"); | |||
|
75 | return "string-2"; | |||
|
76 | } | |||
|
77 | // dialplan commands | |||
|
78 | if(ch == '#') { | |||
|
79 | stream.eatWhile(/\w/); | |||
|
80 | cur = stream.current(); | |||
|
81 | if(dpcmd.indexOf(cur) !== -1) { | |||
|
82 | stream.skipToEnd(); | |||
|
83 | return "strong"; | |||
|
84 | } | |||
|
85 | } | |||
|
86 | // application args | |||
|
87 | if(ch == '$'){ | |||
|
88 | var ch1 = stream.peek(); | |||
|
89 | if(ch1 == '{'){ | |||
|
90 | stream.skipTo('}'); | |||
|
91 | stream.eat('}'); | |||
|
92 | return "variable-3"; | |||
|
93 | } | |||
|
94 | } | |||
|
95 | // extension | |||
|
96 | stream.eatWhile(/\w/); | |||
|
97 | cur = stream.current(); | |||
|
98 | if(atoms.indexOf(cur) !== -1) { | |||
|
99 | state.extenStart = true; | |||
|
100 | switch(cur) { | |||
|
101 | case 'same': state.extenSame = true; break; | |||
|
102 | case 'include': | |||
|
103 | case 'switch': | |||
|
104 | case 'ignorepat': | |||
|
105 | state.extenInclude = true;break; | |||
|
106 | default:break; | |||
|
107 | } | |||
|
108 | return "atom"; | |||
|
109 | } | |||
|
110 | } | |||
|
111 | ||||
|
112 | return { | |||
|
113 | startState: function() { | |||
|
114 | return { | |||
|
115 | extenStart: false, | |||
|
116 | extenSame: false, | |||
|
117 | extenInclude: false, | |||
|
118 | extenExten: false, | |||
|
119 | extenPriority: false, | |||
|
120 | extenApplication: false | |||
|
121 | }; | |||
|
122 | }, | |||
|
123 | token: function(stream, state) { | |||
|
124 | ||||
|
125 | var cur = ''; | |||
|
126 | var ch = ''; | |||
|
127 | if(stream.eatSpace()) return null; | |||
|
128 | // extension started | |||
|
129 | if(state.extenStart){ | |||
|
130 | stream.eatWhile(/[^\s]/); | |||
|
131 | cur = stream.current(); | |||
|
132 | if(/^=>?$/.test(cur)){ | |||
|
133 | state.extenExten = true; | |||
|
134 | state.extenStart = false; | |||
|
135 | return "strong"; | |||
|
136 | } else { | |||
|
137 | state.extenStart = false; | |||
|
138 | stream.skipToEnd(); | |||
|
139 | return "error"; | |||
|
140 | } | |||
|
141 | } else if(state.extenExten) { | |||
|
142 | // set exten and priority | |||
|
143 | state.extenExten = false; | |||
|
144 | state.extenPriority = true; | |||
|
145 | stream.eatWhile(/[^,]/); | |||
|
146 | if(state.extenInclude) { | |||
|
147 | stream.skipToEnd(); | |||
|
148 | state.extenPriority = false; | |||
|
149 | state.extenInclude = false; | |||
|
150 | } | |||
|
151 | if(state.extenSame) { | |||
|
152 | state.extenPriority = false; | |||
|
153 | state.extenSame = false; | |||
|
154 | state.extenApplication = true; | |||
|
155 | } | |||
|
156 | return "tag"; | |||
|
157 | } else if(state.extenPriority) { | |||
|
158 | state.extenPriority = false; | |||
|
159 | state.extenApplication = true; | |||
|
160 | ch = stream.next(); // get comma | |||
|
161 | if(state.extenSame) return null; | |||
|
162 | stream.eatWhile(/[^,]/); | |||
|
163 | return "number"; | |||
|
164 | } else if(state.extenApplication) { | |||
|
165 | stream.eatWhile(/,/); | |||
|
166 | cur = stream.current(); | |||
|
167 | if(cur === ',') return null; | |||
|
168 | stream.eatWhile(/\w/); | |||
|
169 | cur = stream.current().toLowerCase(); | |||
|
170 | state.extenApplication = false; | |||
|
171 | if(apps.indexOf(cur) !== -1){ | |||
|
172 | return "def strong"; | |||
|
173 | } | |||
|
174 | } else{ | |||
|
175 | return basicToken(stream,state); | |||
|
176 | } | |||
|
177 | ||||
|
178 | return null; | |||
|
179 | } | |||
|
180 | }; | |||
|
181 | }); | |||
|
182 | ||||
|
183 | CodeMirror.defineMIME("text/x-asterisk", "asterisk"); |
@@ -0,0 +1,142 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Asterisk dialplan mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="asterisk.js"></script> | |||
|
9 | <style> | |||
|
10 | .CodeMirror {border: 1px solid #999;} | |||
|
11 | .cm-s-default span.cm-arrow { color: red; } | |||
|
12 | </style> | |||
|
13 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
14 | </head> | |||
|
15 | <body> | |||
|
16 | <h1>CodeMirror: Asterisk dialplan mode</h1> | |||
|
17 | <form><textarea id="code" name="code"> | |||
|
18 | ; extensions.conf - the Asterisk dial plan | |||
|
19 | ; | |||
|
20 | ||||
|
21 | [general] | |||
|
22 | ; | |||
|
23 | ; If static is set to no, or omitted, then the pbx_config will rewrite | |||
|
24 | ; this file when extensions are modified. Remember that all comments | |||
|
25 | ; made in the file will be lost when that happens. | |||
|
26 | static=yes | |||
|
27 | ||||
|
28 | #include "/etc/asterisk/additional_general.conf | |||
|
29 | ||||
|
30 | [iaxprovider] | |||
|
31 | switch => IAX2/user:[key]@myserver/mycontext | |||
|
32 | ||||
|
33 | [dynamic] | |||
|
34 | #exec /usr/bin/dynamic-peers.pl | |||
|
35 | ||||
|
36 | [trunkint] | |||
|
37 | ; | |||
|
38 | ; International long distance through trunk | |||
|
39 | ; | |||
|
40 | exten => _9011.,1,Macro(dundi-e164,${EXTEN:4}) | |||
|
41 | exten => _9011.,n,Dial(${GLOBAL(TRUNK)}/${FILTER(0-9,${EXTEN:${GLOBAL(TRUNKMSD)}})}) | |||
|
42 | ||||
|
43 | [local] | |||
|
44 | ; | |||
|
45 | ; Master context for local, toll-free, and iaxtel calls only | |||
|
46 | ; | |||
|
47 | ignorepat => 9 | |||
|
48 | include => default | |||
|
49 | ||||
|
50 | [demo] | |||
|
51 | include => stdexten | |||
|
52 | ; | |||
|
53 | ; We start with what to do when a call first comes in. | |||
|
54 | ; | |||
|
55 | exten => s,1,Wait(1) ; Wait a second, just for fun | |||
|
56 | same => n,Answer ; Answer the line | |||
|
57 | same => n,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 seconds | |||
|
58 | same => n,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 seconds | |||
|
59 | same => n(restart),BackGround(demo-congrats) ; Play a congratulatory message | |||
|
60 | same => n(instruct),BackGround(demo-instruct) ; Play some instructions | |||
|
61 | same => n,WaitExten ; Wait for an extension to be dialed. | |||
|
62 | ||||
|
63 | exten => 2,1,BackGround(demo-moreinfo) ; Give some more information. | |||
|
64 | exten => 2,n,Goto(s,instruct) | |||
|
65 | ||||
|
66 | exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french | |||
|
67 | exten => 3,n,Goto(s,restart) ; Start with the congratulations | |||
|
68 | ||||
|
69 | exten => 1000,1,Goto(default,s,1) | |||
|
70 | ; | |||
|
71 | ; We also create an example user, 1234, who is on the console and has | |||
|
72 | ; voicemail, etc. | |||
|
73 | ; | |||
|
74 | exten => 1234,1,Playback(transfer,skip) ; "Please hold while..." | |||
|
75 | ; (but skip if channel is not up) | |||
|
76 | exten => 1234,n,Gosub(${EXTEN},stdexten(${GLOBAL(CONSOLE)})) | |||
|
77 | exten => 1234,n,Goto(default,s,1) ; exited Voicemail | |||
|
78 | ||||
|
79 | exten => 1235,1,Voicemail(1234,u) ; Right to voicemail | |||
|
80 | ||||
|
81 | exten => 1236,1,Dial(Console/dsp) ; Ring forever | |||
|
82 | exten => 1236,n,Voicemail(1234,b) ; Unless busy | |||
|
83 | ||||
|
84 | ; | |||
|
85 | ; # for when they're done with the demo | |||
|
86 | ; | |||
|
87 | exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo" | |||
|
88 | exten => #,n,Hangup ; Hang them up. | |||
|
89 | ||||
|
90 | ; | |||
|
91 | ; A timeout and "invalid extension rule" | |||
|
92 | ; | |||
|
93 | exten => t,1,Goto(#,1) ; If they take too long, give up | |||
|
94 | exten => i,1,Playback(invalid) ; "That's not valid, try again" | |||
|
95 | ||||
|
96 | ; | |||
|
97 | ; Create an extension, 500, for dialing the | |||
|
98 | ; Asterisk demo. | |||
|
99 | ; | |||
|
100 | exten => 500,1,Playback(demo-abouttotry); Let them know what's going on | |||
|
101 | exten => 500,n,Dial(IAX2/guest@pbx.digium.com/s@default) ; Call the Asterisk demo | |||
|
102 | exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site | |||
|
103 | exten => 500,n,Goto(s,6) ; Return to the start over message. | |||
|
104 | ||||
|
105 | ; | |||
|
106 | ; Create an extension, 600, for evaluating echo latency. | |||
|
107 | ; | |||
|
108 | exten => 600,1,Playback(demo-echotest) ; Let them know what's going on | |||
|
109 | exten => 600,n,Echo ; Do the echo test | |||
|
110 | exten => 600,n,Playback(demo-echodone) ; Let them know it's over | |||
|
111 | exten => 600,n,Goto(s,6) ; Start over | |||
|
112 | ||||
|
113 | ; | |||
|
114 | ; You can use the Macro Page to intercom a individual user | |||
|
115 | exten => 76245,1,Macro(page,SIP/Grandstream1) | |||
|
116 | ; or if your peernames are the same as extensions | |||
|
117 | exten => _7XXX,1,Macro(page,SIP/${EXTEN}) | |||
|
118 | ; | |||
|
119 | ; | |||
|
120 | ; System Wide Page at extension 7999 | |||
|
121 | ; | |||
|
122 | exten => 7999,1,Set(TIMEOUT(absolute)=60) | |||
|
123 | exten => 7999,2,Page(Local/Grandstream1@page&Local/Xlite1@page&Local/1234@page/n,d) | |||
|
124 | ||||
|
125 | ; Give voicemail at extension 8500 | |||
|
126 | ; | |||
|
127 | exten => 8500,1,VoicemailMain | |||
|
128 | exten => 8500,n,Goto(s,6) | |||
|
129 | ||||
|
130 | </textarea></form> | |||
|
131 | <script> | |||
|
132 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
133 | mode: "text/x-asterisk", | |||
|
134 | matchBrackets: true, | |||
|
135 | lineNumber: true | |||
|
136 | }); | |||
|
137 | </script> | |||
|
138 | ||||
|
139 | <p><strong>MIME types defined:</strong> <code>text/x-asterisk</code>.</p> | |||
|
140 | ||||
|
141 | </body> | |||
|
142 | </html> |
@@ -0,0 +1,361 b'' | |||||
|
1 | CodeMirror.defineMode("clike", function(config, parserConfig) { | |||
|
2 | var indentUnit = config.indentUnit, | |||
|
3 | statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, | |||
|
4 | dontAlignCalls = parserConfig.dontAlignCalls, | |||
|
5 | keywords = parserConfig.keywords || {}, | |||
|
6 | builtin = parserConfig.builtin || {}, | |||
|
7 | blockKeywords = parserConfig.blockKeywords || {}, | |||
|
8 | atoms = parserConfig.atoms || {}, | |||
|
9 | hooks = parserConfig.hooks || {}, | |||
|
10 | multiLineStrings = parserConfig.multiLineStrings; | |||
|
11 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | |||
|
12 | ||||
|
13 | var curPunc; | |||
|
14 | ||||
|
15 | function tokenBase(stream, state) { | |||
|
16 | var ch = stream.next(); | |||
|
17 | if (hooks[ch]) { | |||
|
18 | var result = hooks[ch](stream, state); | |||
|
19 | if (result !== false) return result; | |||
|
20 | } | |||
|
21 | if (ch == '"' || ch == "'") { | |||
|
22 | state.tokenize = tokenString(ch); | |||
|
23 | return state.tokenize(stream, state); | |||
|
24 | } | |||
|
25 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |||
|
26 | curPunc = ch; | |||
|
27 | return null; | |||
|
28 | } | |||
|
29 | if (/\d/.test(ch)) { | |||
|
30 | stream.eatWhile(/[\w\.]/); | |||
|
31 | return "number"; | |||
|
32 | } | |||
|
33 | if (ch == "/") { | |||
|
34 | if (stream.eat("*")) { | |||
|
35 | state.tokenize = tokenComment; | |||
|
36 | return tokenComment(stream, state); | |||
|
37 | } | |||
|
38 | if (stream.eat("/")) { | |||
|
39 | stream.skipToEnd(); | |||
|
40 | return "comment"; | |||
|
41 | } | |||
|
42 | } | |||
|
43 | if (isOperatorChar.test(ch)) { | |||
|
44 | stream.eatWhile(isOperatorChar); | |||
|
45 | return "operator"; | |||
|
46 | } | |||
|
47 | stream.eatWhile(/[\w\$_]/); | |||
|
48 | var cur = stream.current(); | |||
|
49 | if (keywords.propertyIsEnumerable(cur)) { | |||
|
50 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
51 | return "keyword"; | |||
|
52 | } | |||
|
53 | if (builtin.propertyIsEnumerable(cur)) { | |||
|
54 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
55 | return "builtin"; | |||
|
56 | } | |||
|
57 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | |||
|
58 | return "variable"; | |||
|
59 | } | |||
|
60 | ||||
|
61 | function tokenString(quote) { | |||
|
62 | return function(stream, state) { | |||
|
63 | var escaped = false, next, end = false; | |||
|
64 | while ((next = stream.next()) != null) { | |||
|
65 | if (next == quote && !escaped) {end = true; break;} | |||
|
66 | escaped = !escaped && next == "\\"; | |||
|
67 | } | |||
|
68 | if (end || !(escaped || multiLineStrings)) | |||
|
69 | state.tokenize = null; | |||
|
70 | return "string"; | |||
|
71 | }; | |||
|
72 | } | |||
|
73 | ||||
|
74 | function tokenComment(stream, state) { | |||
|
75 | var maybeEnd = false, ch; | |||
|
76 | while (ch = stream.next()) { | |||
|
77 | if (ch == "/" && maybeEnd) { | |||
|
78 | state.tokenize = null; | |||
|
79 | break; | |||
|
80 | } | |||
|
81 | maybeEnd = (ch == "*"); | |||
|
82 | } | |||
|
83 | return "comment"; | |||
|
84 | } | |||
|
85 | ||||
|
86 | function Context(indented, column, type, align, prev) { | |||
|
87 | this.indented = indented; | |||
|
88 | this.column = column; | |||
|
89 | this.type = type; | |||
|
90 | this.align = align; | |||
|
91 | this.prev = prev; | |||
|
92 | } | |||
|
93 | function pushContext(state, col, type) { | |||
|
94 | var indent = state.indented; | |||
|
95 | if (state.context && state.context.type == "statement") | |||
|
96 | indent = state.context.indented; | |||
|
97 | return state.context = new Context(indent, col, type, null, state.context); | |||
|
98 | } | |||
|
99 | function popContext(state) { | |||
|
100 | var t = state.context.type; | |||
|
101 | if (t == ")" || t == "]" || t == "}") | |||
|
102 | state.indented = state.context.indented; | |||
|
103 | return state.context = state.context.prev; | |||
|
104 | } | |||
|
105 | ||||
|
106 | // Interface | |||
|
107 | ||||
|
108 | return { | |||
|
109 | startState: function(basecolumn) { | |||
|
110 | return { | |||
|
111 | tokenize: null, | |||
|
112 | context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | |||
|
113 | indented: 0, | |||
|
114 | startOfLine: true | |||
|
115 | }; | |||
|
116 | }, | |||
|
117 | ||||
|
118 | token: function(stream, state) { | |||
|
119 | var ctx = state.context; | |||
|
120 | if (stream.sol()) { | |||
|
121 | if (ctx.align == null) ctx.align = false; | |||
|
122 | state.indented = stream.indentation(); | |||
|
123 | state.startOfLine = true; | |||
|
124 | } | |||
|
125 | if (stream.eatSpace()) return null; | |||
|
126 | curPunc = null; | |||
|
127 | var style = (state.tokenize || tokenBase)(stream, state); | |||
|
128 | if (style == "comment" || style == "meta") return style; | |||
|
129 | if (ctx.align == null) ctx.align = true; | |||
|
130 | ||||
|
131 | if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state); | |||
|
132 | else if (curPunc == "{") pushContext(state, stream.column(), "}"); | |||
|
133 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); | |||
|
134 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); | |||
|
135 | else if (curPunc == "}") { | |||
|
136 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
137 | if (ctx.type == "}") ctx = popContext(state); | |||
|
138 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
139 | } | |||
|
140 | else if (curPunc == ctx.type) popContext(state); | |||
|
141 | else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement")) | |||
|
142 | pushContext(state, stream.column(), "statement"); | |||
|
143 | state.startOfLine = false; | |||
|
144 | return style; | |||
|
145 | }, | |||
|
146 | ||||
|
147 | indent: function(state, textAfter) { | |||
|
148 | if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass; | |||
|
149 | var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); | |||
|
150 | if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; | |||
|
151 | var closing = firstChar == ctx.type; | |||
|
152 | if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit); | |||
|
153 | else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1); | |||
|
154 | else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit; | |||
|
155 | else return ctx.indented + (closing ? 0 : indentUnit); | |||
|
156 | }, | |||
|
157 | ||||
|
158 | electricChars: "{}", | |||
|
159 | blockCommentStart: "/*", | |||
|
160 | blockCommentEnd: "*/", | |||
|
161 | lineComment: "//" | |||
|
162 | }; | |||
|
163 | }); | |||
|
164 | ||||
|
165 | (function() { | |||
|
166 | function words(str) { | |||
|
167 | var obj = {}, words = str.split(" "); | |||
|
168 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | |||
|
169 | return obj; | |||
|
170 | } | |||
|
171 | var cKeywords = "auto if break int case long char register continue return default short do sizeof " + | |||
|
172 | "double static else struct entry switch extern typedef float union for unsigned " + | |||
|
173 | "goto while enum void const signed volatile"; | |||
|
174 | ||||
|
175 | function cppHook(stream, state) { | |||
|
176 | if (!state.startOfLine) return false; | |||
|
177 | for (;;) { | |||
|
178 | if (stream.skipTo("\\")) { | |||
|
179 | stream.next(); | |||
|
180 | if (stream.eol()) { | |||
|
181 | state.tokenize = cppHook; | |||
|
182 | break; | |||
|
183 | } | |||
|
184 | } else { | |||
|
185 | stream.skipToEnd(); | |||
|
186 | state.tokenize = null; | |||
|
187 | break; | |||
|
188 | } | |||
|
189 | } | |||
|
190 | return "meta"; | |||
|
191 | } | |||
|
192 | ||||
|
193 | // C#-style strings where "" escapes a quote. | |||
|
194 | function tokenAtString(stream, state) { | |||
|
195 | var next; | |||
|
196 | while ((next = stream.next()) != null) { | |||
|
197 | if (next == '"' && !stream.eat('"')) { | |||
|
198 | state.tokenize = null; | |||
|
199 | break; | |||
|
200 | } | |||
|
201 | } | |||
|
202 | return "string"; | |||
|
203 | } | |||
|
204 | ||||
|
205 | function mimes(ms, mode) { | |||
|
206 | for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode); | |||
|
207 | } | |||
|
208 | ||||
|
209 | mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], { | |||
|
210 | name: "clike", | |||
|
211 | keywords: words(cKeywords), | |||
|
212 | blockKeywords: words("case do else for if switch while struct"), | |||
|
213 | atoms: words("null"), | |||
|
214 | hooks: {"#": cppHook} | |||
|
215 | }); | |||
|
216 | mimes(["text/x-c++src", "text/x-c++hdr"], { | |||
|
217 | name: "clike", | |||
|
218 | keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " + | |||
|
219 | "static_cast typeid catch operator template typename class friend private " + | |||
|
220 | "this using const_cast inline public throw virtual delete mutable protected " + | |||
|
221 | "wchar_t"), | |||
|
222 | blockKeywords: words("catch class do else finally for if struct switch try while"), | |||
|
223 | atoms: words("true false null"), | |||
|
224 | hooks: {"#": cppHook} | |||
|
225 | }); | |||
|
226 | CodeMirror.defineMIME("text/x-java", { | |||
|
227 | name: "clike", | |||
|
228 | keywords: words("abstract assert boolean break byte case catch char class const continue default " + | |||
|
229 | "do double else enum extends final finally float for goto if implements import " + | |||
|
230 | "instanceof int interface long native new package private protected public " + | |||
|
231 | "return short static strictfp super switch synchronized this throw throws transient " + | |||
|
232 | "try void volatile while"), | |||
|
233 | blockKeywords: words("catch class do else finally for if switch try while"), | |||
|
234 | atoms: words("true false null"), | |||
|
235 | hooks: { | |||
|
236 | "@": function(stream) { | |||
|
237 | stream.eatWhile(/[\w\$_]/); | |||
|
238 | return "meta"; | |||
|
239 | } | |||
|
240 | } | |||
|
241 | }); | |||
|
242 | CodeMirror.defineMIME("text/x-csharp", { | |||
|
243 | name: "clike", | |||
|
244 | keywords: words("abstract as base break case catch checked class const continue" + | |||
|
245 | " default delegate do else enum event explicit extern finally fixed for" + | |||
|
246 | " foreach goto if implicit in interface internal is lock namespace new" + | |||
|
247 | " operator out override params private protected public readonly ref return sealed" + | |||
|
248 | " sizeof stackalloc static struct switch this throw try typeof unchecked" + | |||
|
249 | " unsafe using virtual void volatile while add alias ascending descending dynamic from get" + | |||
|
250 | " global group into join let orderby partial remove select set value var yield"), | |||
|
251 | blockKeywords: words("catch class do else finally for foreach if struct switch try while"), | |||
|
252 | builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" + | |||
|
253 | " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" + | |||
|
254 | " UInt64 bool byte char decimal double short int long object" + | |||
|
255 | " sbyte float string ushort uint ulong"), | |||
|
256 | atoms: words("true false null"), | |||
|
257 | hooks: { | |||
|
258 | "@": function(stream, state) { | |||
|
259 | if (stream.eat('"')) { | |||
|
260 | state.tokenize = tokenAtString; | |||
|
261 | return tokenAtString(stream, state); | |||
|
262 | } | |||
|
263 | stream.eatWhile(/[\w\$_]/); | |||
|
264 | return "meta"; | |||
|
265 | } | |||
|
266 | } | |||
|
267 | }); | |||
|
268 | CodeMirror.defineMIME("text/x-scala", { | |||
|
269 | name: "clike", | |||
|
270 | keywords: words( | |||
|
271 | ||||
|
272 | /* scala */ | |||
|
273 | "abstract case catch class def do else extends false final finally for forSome if " + | |||
|
274 | "implicit import lazy match new null object override package private protected return " + | |||
|
275 | "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " + | |||
|
276 | "<% >: # @ " + | |||
|
277 | ||||
|
278 | /* package scala */ | |||
|
279 | "assert assume require print println printf readLine readBoolean readByte readShort " + | |||
|
280 | "readChar readInt readLong readFloat readDouble " + | |||
|
281 | ||||
|
282 | "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " + | |||
|
283 | "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " + | |||
|
284 | "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " + | |||
|
285 | "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " + | |||
|
286 | "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " + | |||
|
287 | ||||
|
288 | /* package java.lang */ | |||
|
289 | "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " + | |||
|
290 | "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " + | |||
|
291 | "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " + | |||
|
292 | "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" | |||
|
293 | ||||
|
294 | ||||
|
295 | ), | |||
|
296 | blockKeywords: words("catch class do else finally for forSome if match switch try while"), | |||
|
297 | atoms: words("true false null"), | |||
|
298 | hooks: { | |||
|
299 | "@": function(stream) { | |||
|
300 | stream.eatWhile(/[\w\$_]/); | |||
|
301 | return "meta"; | |||
|
302 | } | |||
|
303 | } | |||
|
304 | }); | |||
|
305 | mimes(["x-shader/x-vertex", "x-shader/x-fragment"], { | |||
|
306 | name: "clike", | |||
|
307 | keywords: words("float int bool void " + | |||
|
308 | "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + | |||
|
309 | "mat2 mat3 mat4 " + | |||
|
310 | "sampler1D sampler2D sampler3D samplerCube " + | |||
|
311 | "sampler1DShadow sampler2DShadow" + | |||
|
312 | "const attribute uniform varying " + | |||
|
313 | "break continue discard return " + | |||
|
314 | "for while do if else struct " + | |||
|
315 | "in out inout"), | |||
|
316 | blockKeywords: words("for while do if else struct"), | |||
|
317 | builtin: words("radians degrees sin cos tan asin acos atan " + | |||
|
318 | "pow exp log exp2 sqrt inversesqrt " + | |||
|
319 | "abs sign floor ceil fract mod min max clamp mix step smootstep " + | |||
|
320 | "length distance dot cross normalize ftransform faceforward " + | |||
|
321 | "reflect refract matrixCompMult " + | |||
|
322 | "lessThan lessThanEqual greaterThan greaterThanEqual " + | |||
|
323 | "equal notEqual any all not " + | |||
|
324 | "texture1D texture1DProj texture1DLod texture1DProjLod " + | |||
|
325 | "texture2D texture2DProj texture2DLod texture2DProjLod " + | |||
|
326 | "texture3D texture3DProj texture3DLod texture3DProjLod " + | |||
|
327 | "textureCube textureCubeLod " + | |||
|
328 | "shadow1D shadow2D shadow1DProj shadow2DProj " + | |||
|
329 | "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " + | |||
|
330 | "dFdx dFdy fwidth " + | |||
|
331 | "noise1 noise2 noise3 noise4"), | |||
|
332 | atoms: words("true false " + | |||
|
333 | "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " + | |||
|
334 | "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " + | |||
|
335 | "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " + | |||
|
336 | "gl_FogCoord " + | |||
|
337 | "gl_Position gl_PointSize gl_ClipVertex " + | |||
|
338 | "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " + | |||
|
339 | "gl_TexCoord gl_FogFragCoord " + | |||
|
340 | "gl_FragCoord gl_FrontFacing " + | |||
|
341 | "gl_FragColor gl_FragData gl_FragDepth " + | |||
|
342 | "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " + | |||
|
343 | "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " + | |||
|
344 | "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " + | |||
|
345 | "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " + | |||
|
346 | "gl_ProjectionMatrixInverseTranspose " + | |||
|
347 | "gl_ModelViewProjectionMatrixInverseTranspose " + | |||
|
348 | "gl_TextureMatrixInverseTranspose " + | |||
|
349 | "gl_NormalScale gl_DepthRange gl_ClipPlane " + | |||
|
350 | "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " + | |||
|
351 | "gl_FrontLightModelProduct gl_BackLightModelProduct " + | |||
|
352 | "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " + | |||
|
353 | "gl_FogParameters " + | |||
|
354 | "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " + | |||
|
355 | "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " + | |||
|
356 | "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + | |||
|
357 | "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " + | |||
|
358 | "gl_MaxDrawBuffers"), | |||
|
359 | hooks: {"#": cppHook} | |||
|
360 | }); | |||
|
361 | }()); |
@@ -0,0 +1,103 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: C-like mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="clike.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | <style>.CodeMirror {border: 2px inset #dee;}</style> | |||
|
12 | </head> | |||
|
13 | <body> | |||
|
14 | <h1>CodeMirror: C-like mode</h1> | |||
|
15 | ||||
|
16 | <form><textarea id="code" name="code"> | |||
|
17 | /* C demo code */ | |||
|
18 | ||||
|
19 | #include <zmq.h> | |||
|
20 | #include <pthread.h> | |||
|
21 | #include <semaphore.h> | |||
|
22 | #include <time.h> | |||
|
23 | #include <stdio.h> | |||
|
24 | #include <fcntl.h> | |||
|
25 | #include <malloc.h> | |||
|
26 | ||||
|
27 | typedef struct { | |||
|
28 | void* arg_socket; | |||
|
29 | zmq_msg_t* arg_msg; | |||
|
30 | char* arg_string; | |||
|
31 | unsigned long arg_len; | |||
|
32 | int arg_int, arg_command; | |||
|
33 | ||||
|
34 | int signal_fd; | |||
|
35 | int pad; | |||
|
36 | void* context; | |||
|
37 | sem_t sem; | |||
|
38 | } acl_zmq_context; | |||
|
39 | ||||
|
40 | #define p(X) (context->arg_##X) | |||
|
41 | ||||
|
42 | void* zmq_thread(void* context_pointer) { | |||
|
43 | acl_zmq_context* context = (acl_zmq_context*)context_pointer; | |||
|
44 | char ok = 'K', err = 'X'; | |||
|
45 | int res; | |||
|
46 | ||||
|
47 | while (1) { | |||
|
48 | while ((res = sem_wait(&context->sem)) == EINTR); | |||
|
49 | if (res) {write(context->signal_fd, &err, 1); goto cleanup;} | |||
|
50 | switch(p(command)) { | |||
|
51 | case 0: goto cleanup; | |||
|
52 | case 1: p(socket) = zmq_socket(context->context, p(int)); break; | |||
|
53 | case 2: p(int) = zmq_close(p(socket)); break; | |||
|
54 | case 3: p(int) = zmq_bind(p(socket), p(string)); break; | |||
|
55 | case 4: p(int) = zmq_connect(p(socket), p(string)); break; | |||
|
56 | case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break; | |||
|
57 | case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break; | |||
|
58 | case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break; | |||
|
59 | case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break; | |||
|
60 | case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break; | |||
|
61 | } | |||
|
62 | p(command) = errno; | |||
|
63 | write(context->signal_fd, &ok, 1); | |||
|
64 | } | |||
|
65 | cleanup: | |||
|
66 | close(context->signal_fd); | |||
|
67 | free(context_pointer); | |||
|
68 | return 0; | |||
|
69 | } | |||
|
70 | ||||
|
71 | void* zmq_thread_init(void* zmq_context, int signal_fd) { | |||
|
72 | acl_zmq_context* context = malloc(sizeof(acl_zmq_context)); | |||
|
73 | pthread_t thread; | |||
|
74 | ||||
|
75 | context->context = zmq_context; | |||
|
76 | context->signal_fd = signal_fd; | |||
|
77 | sem_init(&context->sem, 1, 0); | |||
|
78 | pthread_create(&thread, 0, &zmq_thread, context); | |||
|
79 | pthread_detach(thread); | |||
|
80 | return context; | |||
|
81 | } | |||
|
82 | </textarea></form> | |||
|
83 | ||||
|
84 | <script> | |||
|
85 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
86 | lineNumbers: true, | |||
|
87 | matchBrackets: true, | |||
|
88 | mode: "text/x-csrc" | |||
|
89 | }); | |||
|
90 | </script> | |||
|
91 | ||||
|
92 | <p>Simple mode that tries to handle C-like languages as well as it | |||
|
93 | can. Takes two configuration parameters: <code>keywords</code>, an | |||
|
94 | object whose property names are the keywords in the language, | |||
|
95 | and <code>useCPP</code>, which determines whether C preprocessor | |||
|
96 | directives are recognized.</p> | |||
|
97 | ||||
|
98 | <p><strong>MIME types defined:</strong> <code>text/x-csrc</code> | |||
|
99 | (C code), <code>text/x-c++src</code> (C++ | |||
|
100 | code), <code>text/x-java</code> (Java | |||
|
101 | code), <code>text/x-csharp</code> (C#).</p> | |||
|
102 | </body> | |||
|
103 | </html> |
This diff has been collapsed as it changes many lines, (767 lines changed) Show them Hide them | |||||
@@ -0,0 +1,767 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: C-like mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <link rel="stylesheet" href="../../theme/ambiance.css"> | |||
|
8 | <script src="../../lib/codemirror.js"></script> | |||
|
9 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
10 | <script src="clike.js"></script> | |||
|
11 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
12 | <style> | |||
|
13 | body | |||
|
14 | { | |||
|
15 | margin: 0; | |||
|
16 | padding: 0; | |||
|
17 | max-width:inherit; | |||
|
18 | height: 100%; | |||
|
19 | } | |||
|
20 | html, form, .CodeMirror, .CodeMirror-scroll | |||
|
21 | { | |||
|
22 | height: 100%; | |||
|
23 | } | |||
|
24 | </style> | |||
|
25 | </head> | |||
|
26 | <body> | |||
|
27 | <form> | |||
|
28 | <textarea id="code" name="code"> | |||
|
29 | ||||
|
30 | /* __ *\ | |||
|
31 | ** ________ ___ / / ___ Scala API ** | |||
|
32 | ** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** | |||
|
33 | ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | |||
|
34 | ** /____/\___/_/ |_/____/_/ | | ** | |||
|
35 | ** |/ ** | |||
|
36 | \* */ | |||
|
37 | ||||
|
38 | package scala.collection | |||
|
39 | ||||
|
40 | import generic._ | |||
|
41 | import mutable.{ Builder, ListBuffer } | |||
|
42 | import annotation.{tailrec, migration, bridge} | |||
|
43 | import annotation.unchecked.{ uncheckedVariance => uV } | |||
|
44 | import parallel.ParIterable | |||
|
45 | ||||
|
46 | /** A template trait for traversable collections of type `Traversable[A]`. | |||
|
47 | * | |||
|
48 | * $traversableInfo | |||
|
49 | * @define mutability | |||
|
50 | * @define traversableInfo | |||
|
51 | * This is a base trait of all kinds of $mutability Scala collections. It | |||
|
52 | * implements the behavior common to all collections, in terms of a method | |||
|
53 | * `foreach` with signature: | |||
|
54 | * {{{ | |||
|
55 | * def foreach[U](f: Elem => U): Unit | |||
|
56 | * }}} | |||
|
57 | * Collection classes mixing in this trait provide a concrete | |||
|
58 | * `foreach` method which traverses all the | |||
|
59 | * elements contained in the collection, applying a given function to each. | |||
|
60 | * They also need to provide a method `newBuilder` | |||
|
61 | * which creates a builder for collections of the same kind. | |||
|
62 | * | |||
|
63 | * A traversable class might or might not have two properties: strictness | |||
|
64 | * and orderedness. Neither is represented as a type. | |||
|
65 | * | |||
|
66 | * The instances of a strict collection class have all their elements | |||
|
67 | * computed before they can be used as values. By contrast, instances of | |||
|
68 | * a non-strict collection class may defer computation of some of their | |||
|
69 | * elements until after the instance is available as a value. | |||
|
70 | * A typical example of a non-strict collection class is a | |||
|
71 | * <a href="../immutable/Stream.html" target="ContentFrame"> | |||
|
72 | * `scala.collection.immutable.Stream`</a>. | |||
|
73 | * A more general class of examples are `TraversableViews`. | |||
|
74 | * | |||
|
75 | * If a collection is an instance of an ordered collection class, traversing | |||
|
76 | * its elements with `foreach` will always visit elements in the | |||
|
77 | * same order, even for different runs of the program. If the class is not | |||
|
78 | * ordered, `foreach` can visit elements in different orders for | |||
|
79 | * different runs (but it will keep the same order in the same run).' | |||
|
80 | * | |||
|
81 | * A typical example of a collection class which is not ordered is a | |||
|
82 | * `HashMap` of objects. The traversal order for hash maps will | |||
|
83 | * depend on the hash codes of its elements, and these hash codes might | |||
|
84 | * differ from one run to the next. By contrast, a `LinkedHashMap` | |||
|
85 | * is ordered because it's `foreach` method visits elements in the | |||
|
86 | * order they were inserted into the `HashMap`. | |||
|
87 | * | |||
|
88 | * @author Martin Odersky | |||
|
89 | * @version 2.8 | |||
|
90 | * @since 2.8 | |||
|
91 | * @tparam A the element type of the collection | |||
|
92 | * @tparam Repr the type of the actual collection containing the elements. | |||
|
93 | * | |||
|
94 | * @define Coll Traversable | |||
|
95 | * @define coll traversable collection | |||
|
96 | */ | |||
|
97 | trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] | |||
|
98 | with FilterMonadic[A, Repr] | |||
|
99 | with TraversableOnce[A] | |||
|
100 | with GenTraversableLike[A, Repr] | |||
|
101 | with Parallelizable[A, ParIterable[A]] | |||
|
102 | { | |||
|
103 | self => | |||
|
104 | ||||
|
105 | import Traversable.breaks._ | |||
|
106 | ||||
|
107 | /** The type implementing this traversable */ | |||
|
108 | protected type Self = Repr | |||
|
109 | ||||
|
110 | /** The collection of type $coll underlying this `TraversableLike` object. | |||
|
111 | * By default this is implemented as the `TraversableLike` object itself, | |||
|
112 | * but this can be overridden. | |||
|
113 | */ | |||
|
114 | def repr: Repr = this.asInstanceOf[Repr] | |||
|
115 | ||||
|
116 | /** The underlying collection seen as an instance of `$Coll`. | |||
|
117 | * By default this is implemented as the current collection object itself, | |||
|
118 | * but this can be overridden. | |||
|
119 | */ | |||
|
120 | protected[this] def thisCollection: Traversable[A] = this.asInstanceOf[Traversable[A]] | |||
|
121 | ||||
|
122 | /** A conversion from collections of type `Repr` to `$Coll` objects. | |||
|
123 | * By default this is implemented as just a cast, but this can be overridden. | |||
|
124 | */ | |||
|
125 | protected[this] def toCollection(repr: Repr): Traversable[A] = repr.asInstanceOf[Traversable[A]] | |||
|
126 | ||||
|
127 | /** Creates a new builder for this collection type. | |||
|
128 | */ | |||
|
129 | protected[this] def newBuilder: Builder[A, Repr] | |||
|
130 | ||||
|
131 | protected[this] def parCombiner = ParIterable.newCombiner[A] | |||
|
132 | ||||
|
133 | /** Applies a function `f` to all elements of this $coll. | |||
|
134 | * | |||
|
135 | * Note: this method underlies the implementation of most other bulk operations. | |||
|
136 | * It's important to implement this method in an efficient way. | |||
|
137 | * | |||
|
138 | * | |||
|
139 | * @param f the function that is applied for its side-effect to every element. | |||
|
140 | * The result of function `f` is discarded. | |||
|
141 | * | |||
|
142 | * @tparam U the type parameter describing the result of function `f`. | |||
|
143 | * This result will always be ignored. Typically `U` is `Unit`, | |||
|
144 | * but this is not necessary. | |||
|
145 | * | |||
|
146 | * @usecase def foreach(f: A => Unit): Unit | |||
|
147 | */ | |||
|
148 | def foreach[U](f: A => U): Unit | |||
|
149 | ||||
|
150 | /** Tests whether this $coll is empty. | |||
|
151 | * | |||
|
152 | * @return `true` if the $coll contain no elements, `false` otherwise. | |||
|
153 | */ | |||
|
154 | def isEmpty: Boolean = { | |||
|
155 | var result = true | |||
|
156 | breakable { | |||
|
157 | for (x <- this) { | |||
|
158 | result = false | |||
|
159 | break | |||
|
160 | } | |||
|
161 | } | |||
|
162 | result | |||
|
163 | } | |||
|
164 | ||||
|
165 | /** Tests whether this $coll is known to have a finite size. | |||
|
166 | * All strict collections are known to have finite size. For a non-strict collection | |||
|
167 | * such as `Stream`, the predicate returns `true` if all elements have been computed. | |||
|
168 | * It returns `false` if the stream is not yet evaluated to the end. | |||
|
169 | * | |||
|
170 | * Note: many collection methods will not work on collections of infinite sizes. | |||
|
171 | * | |||
|
172 | * @return `true` if this collection is known to have finite size, `false` otherwise. | |||
|
173 | */ | |||
|
174 | def hasDefiniteSize = true | |||
|
175 | ||||
|
176 | def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
177 | val b = bf(repr) | |||
|
178 | if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.seq.size) | |||
|
179 | b ++= thisCollection | |||
|
180 | b ++= that.seq | |||
|
181 | b.result | |||
|
182 | } | |||
|
183 | ||||
|
184 | @bridge | |||
|
185 | def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = | |||
|
186 | ++(that: GenTraversableOnce[B])(bf) | |||
|
187 | ||||
|
188 | /** Concatenates this $coll with the elements of a traversable collection. | |||
|
189 | * It differs from ++ in that the right operand determines the type of the | |||
|
190 | * resulting collection rather than the left one. | |||
|
191 | * | |||
|
192 | * @param that the traversable to append. | |||
|
193 | * @tparam B the element type of the returned collection. | |||
|
194 | * @tparam That $thatinfo | |||
|
195 | * @param bf $bfinfo | |||
|
196 | * @return a new collection of type `That` which contains all elements | |||
|
197 | * of this $coll followed by all elements of `that`. | |||
|
198 | * | |||
|
199 | * @usecase def ++:[B](that: TraversableOnce[B]): $Coll[B] | |||
|
200 | * | |||
|
201 | * @return a new $coll which contains all elements of this $coll | |||
|
202 | * followed by all elements of `that`. | |||
|
203 | */ | |||
|
204 | def ++:[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
205 | val b = bf(repr) | |||
|
206 | if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.size) | |||
|
207 | b ++= that | |||
|
208 | b ++= thisCollection | |||
|
209 | b.result | |||
|
210 | } | |||
|
211 | ||||
|
212 | /** This overload exists because: for the implementation of ++: we should reuse | |||
|
213 | * that of ++ because many collections override it with more efficient versions. | |||
|
214 | * Since TraversableOnce has no '++' method, we have to implement that directly, | |||
|
215 | * but Traversable and down can use the overload. | |||
|
216 | */ | |||
|
217 | def ++:[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = | |||
|
218 | (that ++ seq)(breakOut) | |||
|
219 | ||||
|
220 | def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
221 | val b = bf(repr) | |||
|
222 | b.sizeHint(this) | |||
|
223 | for (x <- this) b += f(x) | |||
|
224 | b.result | |||
|
225 | } | |||
|
226 | ||||
|
227 | def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
228 | val b = bf(repr) | |||
|
229 | for (x <- this) b ++= f(x).seq | |||
|
230 | b.result | |||
|
231 | } | |||
|
232 | ||||
|
233 | /** Selects all elements of this $coll which satisfy a predicate. | |||
|
234 | * | |||
|
235 | * @param p the predicate used to test elements. | |||
|
236 | * @return a new $coll consisting of all elements of this $coll that satisfy the given | |||
|
237 | * predicate `p`. The order of the elements is preserved. | |||
|
238 | */ | |||
|
239 | def filter(p: A => Boolean): Repr = { | |||
|
240 | val b = newBuilder | |||
|
241 | for (x <- this) | |||
|
242 | if (p(x)) b += x | |||
|
243 | b.result | |||
|
244 | } | |||
|
245 | ||||
|
246 | /** Selects all elements of this $coll which do not satisfy a predicate. | |||
|
247 | * | |||
|
248 | * @param p the predicate used to test elements. | |||
|
249 | * @return a new $coll consisting of all elements of this $coll that do not satisfy the given | |||
|
250 | * predicate `p`. The order of the elements is preserved. | |||
|
251 | */ | |||
|
252 | def filterNot(p: A => Boolean): Repr = filter(!p(_)) | |||
|
253 | ||||
|
254 | def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
255 | val b = bf(repr) | |||
|
256 | for (x <- this) if (pf.isDefinedAt(x)) b += pf(x) | |||
|
257 | b.result | |||
|
258 | } | |||
|
259 | ||||
|
260 | /** Builds a new collection by applying an option-valued function to all | |||
|
261 | * elements of this $coll on which the function is defined. | |||
|
262 | * | |||
|
263 | * @param f the option-valued function which filters and maps the $coll. | |||
|
264 | * @tparam B the element type of the returned collection. | |||
|
265 | * @tparam That $thatinfo | |||
|
266 | * @param bf $bfinfo | |||
|
267 | * @return a new collection of type `That` resulting from applying the option-valued function | |||
|
268 | * `f` to each element and collecting all defined results. | |||
|
269 | * The order of the elements is preserved. | |||
|
270 | * | |||
|
271 | * @usecase def filterMap[B](f: A => Option[B]): $Coll[B] | |||
|
272 | * | |||
|
273 | * @param pf the partial function which filters and maps the $coll. | |||
|
274 | * @return a new $coll resulting from applying the given option-valued function | |||
|
275 | * `f` to each element and collecting all defined results. | |||
|
276 | * The order of the elements is preserved. | |||
|
277 | def filterMap[B, That](f: A => Option[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
278 | val b = bf(repr) | |||
|
279 | for (x <- this) | |||
|
280 | f(x) match { | |||
|
281 | case Some(y) => b += y | |||
|
282 | case _ => | |||
|
283 | } | |||
|
284 | b.result | |||
|
285 | } | |||
|
286 | */ | |||
|
287 | ||||
|
288 | /** Partitions this $coll in two ${coll}s according to a predicate. | |||
|
289 | * | |||
|
290 | * @param p the predicate on which to partition. | |||
|
291 | * @return a pair of ${coll}s: the first $coll consists of all elements that | |||
|
292 | * satisfy the predicate `p` and the second $coll consists of all elements | |||
|
293 | * that don't. The relative order of the elements in the resulting ${coll}s | |||
|
294 | * is the same as in the original $coll. | |||
|
295 | */ | |||
|
296 | def partition(p: A => Boolean): (Repr, Repr) = { | |||
|
297 | val l, r = newBuilder | |||
|
298 | for (x <- this) (if (p(x)) l else r) += x | |||
|
299 | (l.result, r.result) | |||
|
300 | } | |||
|
301 | ||||
|
302 | def groupBy[K](f: A => K): immutable.Map[K, Repr] = { | |||
|
303 | val m = mutable.Map.empty[K, Builder[A, Repr]] | |||
|
304 | for (elem <- this) { | |||
|
305 | val key = f(elem) | |||
|
306 | val bldr = m.getOrElseUpdate(key, newBuilder) | |||
|
307 | bldr += elem | |||
|
308 | } | |||
|
309 | val b = immutable.Map.newBuilder[K, Repr] | |||
|
310 | for ((k, v) <- m) | |||
|
311 | b += ((k, v.result)) | |||
|
312 | ||||
|
313 | b.result | |||
|
314 | } | |||
|
315 | ||||
|
316 | /** Tests whether a predicate holds for all elements of this $coll. | |||
|
317 | * | |||
|
318 | * $mayNotTerminateInf | |||
|
319 | * | |||
|
320 | * @param p the predicate used to test elements. | |||
|
321 | * @return `true` if the given predicate `p` holds for all elements | |||
|
322 | * of this $coll, otherwise `false`. | |||
|
323 | */ | |||
|
324 | def forall(p: A => Boolean): Boolean = { | |||
|
325 | var result = true | |||
|
326 | breakable { | |||
|
327 | for (x <- this) | |||
|
328 | if (!p(x)) { result = false; break } | |||
|
329 | } | |||
|
330 | result | |||
|
331 | } | |||
|
332 | ||||
|
333 | /** Tests whether a predicate holds for some of the elements of this $coll. | |||
|
334 | * | |||
|
335 | * $mayNotTerminateInf | |||
|
336 | * | |||
|
337 | * @param p the predicate used to test elements. | |||
|
338 | * @return `true` if the given predicate `p` holds for some of the | |||
|
339 | * elements of this $coll, otherwise `false`. | |||
|
340 | */ | |||
|
341 | def exists(p: A => Boolean): Boolean = { | |||
|
342 | var result = false | |||
|
343 | breakable { | |||
|
344 | for (x <- this) | |||
|
345 | if (p(x)) { result = true; break } | |||
|
346 | } | |||
|
347 | result | |||
|
348 | } | |||
|
349 | ||||
|
350 | /** Finds the first element of the $coll satisfying a predicate, if any. | |||
|
351 | * | |||
|
352 | * $mayNotTerminateInf | |||
|
353 | * $orderDependent | |||
|
354 | * | |||
|
355 | * @param p the predicate used to test elements. | |||
|
356 | * @return an option value containing the first element in the $coll | |||
|
357 | * that satisfies `p`, or `None` if none exists. | |||
|
358 | */ | |||
|
359 | def find(p: A => Boolean): Option[A] = { | |||
|
360 | var result: Option[A] = None | |||
|
361 | breakable { | |||
|
362 | for (x <- this) | |||
|
363 | if (p(x)) { result = Some(x); break } | |||
|
364 | } | |||
|
365 | result | |||
|
366 | } | |||
|
367 | ||||
|
368 | def scan[B >: A, That](z: B)(op: (B, B) => B)(implicit cbf: CanBuildFrom[Repr, B, That]): That = scanLeft(z)(op) | |||
|
369 | ||||
|
370 | def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
371 | val b = bf(repr) | |||
|
372 | b.sizeHint(this, 1) | |||
|
373 | var acc = z | |||
|
374 | b += acc | |||
|
375 | for (x <- this) { acc = op(acc, x); b += acc } | |||
|
376 | b.result | |||
|
377 | } | |||
|
378 | ||||
|
379 | @migration(2, 9, | |||
|
380 | "This scanRight definition has changed in 2.9.\n" + | |||
|
381 | "The previous behavior can be reproduced with scanRight.reverse." | |||
|
382 | ) | |||
|
383 | def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
384 | var scanned = List(z) | |||
|
385 | var acc = z | |||
|
386 | for (x <- reversed) { | |||
|
387 | acc = op(x, acc) | |||
|
388 | scanned ::= acc | |||
|
389 | } | |||
|
390 | val b = bf(repr) | |||
|
391 | for (elem <- scanned) b += elem | |||
|
392 | b.result | |||
|
393 | } | |||
|
394 | ||||
|
395 | /** Selects the first element of this $coll. | |||
|
396 | * $orderDependent | |||
|
397 | * @return the first element of this $coll. | |||
|
398 | * @throws `NoSuchElementException` if the $coll is empty. | |||
|
399 | */ | |||
|
400 | def head: A = { | |||
|
401 | var result: () => A = () => throw new NoSuchElementException | |||
|
402 | breakable { | |||
|
403 | for (x <- this) { | |||
|
404 | result = () => x | |||
|
405 | break | |||
|
406 | } | |||
|
407 | } | |||
|
408 | result() | |||
|
409 | } | |||
|
410 | ||||
|
411 | /** Optionally selects the first element. | |||
|
412 | * $orderDependent | |||
|
413 | * @return the first element of this $coll if it is nonempty, `None` if it is empty. | |||
|
414 | */ | |||
|
415 | def headOption: Option[A] = if (isEmpty) None else Some(head) | |||
|
416 | ||||
|
417 | /** Selects all elements except the first. | |||
|
418 | * $orderDependent | |||
|
419 | * @return a $coll consisting of all elements of this $coll | |||
|
420 | * except the first one. | |||
|
421 | * @throws `UnsupportedOperationException` if the $coll is empty. | |||
|
422 | */ | |||
|
423 | override def tail: Repr = { | |||
|
424 | if (isEmpty) throw new UnsupportedOperationException("empty.tail") | |||
|
425 | drop(1) | |||
|
426 | } | |||
|
427 | ||||
|
428 | /** Selects the last element. | |||
|
429 | * $orderDependent | |||
|
430 | * @return The last element of this $coll. | |||
|
431 | * @throws NoSuchElementException If the $coll is empty. | |||
|
432 | */ | |||
|
433 | def last: A = { | |||
|
434 | var lst = head | |||
|
435 | for (x <- this) | |||
|
436 | lst = x | |||
|
437 | lst | |||
|
438 | } | |||
|
439 | ||||
|
440 | /** Optionally selects the last element. | |||
|
441 | * $orderDependent | |||
|
442 | * @return the last element of this $coll$ if it is nonempty, `None` if it is empty. | |||
|
443 | */ | |||
|
444 | def lastOption: Option[A] = if (isEmpty) None else Some(last) | |||
|
445 | ||||
|
446 | /** Selects all elements except the last. | |||
|
447 | * $orderDependent | |||
|
448 | * @return a $coll consisting of all elements of this $coll | |||
|
449 | * except the last one. | |||
|
450 | * @throws `UnsupportedOperationException` if the $coll is empty. | |||
|
451 | */ | |||
|
452 | def init: Repr = { | |||
|
453 | if (isEmpty) throw new UnsupportedOperationException("empty.init") | |||
|
454 | var lst = head | |||
|
455 | var follow = false | |||
|
456 | val b = newBuilder | |||
|
457 | b.sizeHint(this, -1) | |||
|
458 | for (x <- this.seq) { | |||
|
459 | if (follow) b += lst | |||
|
460 | else follow = true | |||
|
461 | lst = x | |||
|
462 | } | |||
|
463 | b.result | |||
|
464 | } | |||
|
465 | ||||
|
466 | def take(n: Int): Repr = slice(0, n) | |||
|
467 | ||||
|
468 | def drop(n: Int): Repr = | |||
|
469 | if (n <= 0) { | |||
|
470 | val b = newBuilder | |||
|
471 | b.sizeHint(this) | |||
|
472 | b ++= thisCollection result | |||
|
473 | } | |||
|
474 | else sliceWithKnownDelta(n, Int.MaxValue, -n) | |||
|
475 | ||||
|
476 | def slice(from: Int, until: Int): Repr = sliceWithKnownBound(math.max(from, 0), until) | |||
|
477 | ||||
|
478 | // Precondition: from >= 0, until > 0, builder already configured for building. | |||
|
479 | private[this] def sliceInternal(from: Int, until: Int, b: Builder[A, Repr]): Repr = { | |||
|
480 | var i = 0 | |||
|
481 | breakable { | |||
|
482 | for (x <- this.seq) { | |||
|
483 | if (i >= from) b += x | |||
|
484 | i += 1 | |||
|
485 | if (i >= until) break | |||
|
486 | } | |||
|
487 | } | |||
|
488 | b.result | |||
|
489 | } | |||
|
490 | // Precondition: from >= 0 | |||
|
491 | private[scala] def sliceWithKnownDelta(from: Int, until: Int, delta: Int): Repr = { | |||
|
492 | val b = newBuilder | |||
|
493 | if (until <= from) b.result | |||
|
494 | else { | |||
|
495 | b.sizeHint(this, delta) | |||
|
496 | sliceInternal(from, until, b) | |||
|
497 | } | |||
|
498 | } | |||
|
499 | // Precondition: from >= 0 | |||
|
500 | private[scala] def sliceWithKnownBound(from: Int, until: Int): Repr = { | |||
|
501 | val b = newBuilder | |||
|
502 | if (until <= from) b.result | |||
|
503 | else { | |||
|
504 | b.sizeHintBounded(until - from, this) | |||
|
505 | sliceInternal(from, until, b) | |||
|
506 | } | |||
|
507 | } | |||
|
508 | ||||
|
509 | def takeWhile(p: A => Boolean): Repr = { | |||
|
510 | val b = newBuilder | |||
|
511 | breakable { | |||
|
512 | for (x <- this) { | |||
|
513 | if (!p(x)) break | |||
|
514 | b += x | |||
|
515 | } | |||
|
516 | } | |||
|
517 | b.result | |||
|
518 | } | |||
|
519 | ||||
|
520 | def dropWhile(p: A => Boolean): Repr = { | |||
|
521 | val b = newBuilder | |||
|
522 | var go = false | |||
|
523 | for (x <- this) { | |||
|
524 | if (!p(x)) go = true | |||
|
525 | if (go) b += x | |||
|
526 | } | |||
|
527 | b.result | |||
|
528 | } | |||
|
529 | ||||
|
530 | def span(p: A => Boolean): (Repr, Repr) = { | |||
|
531 | val l, r = newBuilder | |||
|
532 | var toLeft = true | |||
|
533 | for (x <- this) { | |||
|
534 | toLeft = toLeft && p(x) | |||
|
535 | (if (toLeft) l else r) += x | |||
|
536 | } | |||
|
537 | (l.result, r.result) | |||
|
538 | } | |||
|
539 | ||||
|
540 | def splitAt(n: Int): (Repr, Repr) = { | |||
|
541 | val l, r = newBuilder | |||
|
542 | l.sizeHintBounded(n, this) | |||
|
543 | if (n >= 0) r.sizeHint(this, -n) | |||
|
544 | var i = 0 | |||
|
545 | for (x <- this) { | |||
|
546 | (if (i < n) l else r) += x | |||
|
547 | i += 1 | |||
|
548 | } | |||
|
549 | (l.result, r.result) | |||
|
550 | } | |||
|
551 | ||||
|
552 | /** Iterates over the tails of this $coll. The first value will be this | |||
|
553 | * $coll and the final one will be an empty $coll, with the intervening | |||
|
554 | * values the results of successive applications of `tail`. | |||
|
555 | * | |||
|
556 | * @return an iterator over all the tails of this $coll | |||
|
557 | * @example `List(1,2,3).tails = Iterator(List(1,2,3), List(2,3), List(3), Nil)` | |||
|
558 | */ | |||
|
559 | def tails: Iterator[Repr] = iterateUntilEmpty(_.tail) | |||
|
560 | ||||
|
561 | /** Iterates over the inits of this $coll. The first value will be this | |||
|
562 | * $coll and the final one will be an empty $coll, with the intervening | |||
|
563 | * values the results of successive applications of `init`. | |||
|
564 | * | |||
|
565 | * @return an iterator over all the inits of this $coll | |||
|
566 | * @example `List(1,2,3).inits = Iterator(List(1,2,3), List(1,2), List(1), Nil)` | |||
|
567 | */ | |||
|
568 | def inits: Iterator[Repr] = iterateUntilEmpty(_.init) | |||
|
569 | ||||
|
570 | /** Copies elements of this $coll to an array. | |||
|
571 | * Fills the given array `xs` with at most `len` elements of | |||
|
572 | * this $coll, starting at position `start`. | |||
|
573 | * Copying will stop once either the end of the current $coll is reached, | |||
|
574 | * or the end of the array is reached, or `len` elements have been copied. | |||
|
575 | * | |||
|
576 | * $willNotTerminateInf | |||
|
577 | * | |||
|
578 | * @param xs the array to fill. | |||
|
579 | * @param start the starting index. | |||
|
580 | * @param len the maximal number of elements to copy. | |||
|
581 | * @tparam B the type of the elements of the array. | |||
|
582 | * | |||
|
583 | * | |||
|
584 | * @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit | |||
|
585 | */ | |||
|
586 | def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) { | |||
|
587 | var i = start | |||
|
588 | val end = (start + len) min xs.length | |||
|
589 | breakable { | |||
|
590 | for (x <- this) { | |||
|
591 | if (i >= end) break | |||
|
592 | xs(i) = x | |||
|
593 | i += 1 | |||
|
594 | } | |||
|
595 | } | |||
|
596 | } | |||
|
597 | ||||
|
598 | def toTraversable: Traversable[A] = thisCollection | |||
|
599 | def toIterator: Iterator[A] = toStream.iterator | |||
|
600 | def toStream: Stream[A] = toBuffer.toStream | |||
|
601 | ||||
|
602 | /** Converts this $coll to a string. | |||
|
603 | * | |||
|
604 | * @return a string representation of this collection. By default this | |||
|
605 | * string consists of the `stringPrefix` of this $coll, | |||
|
606 | * followed by all elements separated by commas and enclosed in parentheses. | |||
|
607 | */ | |||
|
608 | override def toString = mkString(stringPrefix + "(", ", ", ")") | |||
|
609 | ||||
|
610 | /** Defines the prefix of this object's `toString` representation. | |||
|
611 | * | |||
|
612 | * @return a string representation which starts the result of `toString` | |||
|
613 | * applied to this $coll. By default the string prefix is the | |||
|
614 | * simple name of the collection class $coll. | |||
|
615 | */ | |||
|
616 | def stringPrefix : String = { | |||
|
617 | var string = repr.asInstanceOf[AnyRef].getClass.getName | |||
|
618 | val idx1 = string.lastIndexOf('.' : Int) | |||
|
619 | if (idx1 != -1) string = string.substring(idx1 + 1) | |||
|
620 | val idx2 = string.indexOf('$') | |||
|
621 | if (idx2 != -1) string = string.substring(0, idx2) | |||
|
622 | string | |||
|
623 | } | |||
|
624 | ||||
|
625 | /** Creates a non-strict view of this $coll. | |||
|
626 | * | |||
|
627 | * @return a non-strict view of this $coll. | |||
|
628 | */ | |||
|
629 | def view = new TraversableView[A, Repr] { | |||
|
630 | protected lazy val underlying = self.repr | |||
|
631 | override def foreach[U](f: A => U) = self foreach f | |||
|
632 | } | |||
|
633 | ||||
|
634 | /** Creates a non-strict view of a slice of this $coll. | |||
|
635 | * | |||
|
636 | * Note: the difference between `view` and `slice` is that `view` produces | |||
|
637 | * a view of the current $coll, whereas `slice` produces a new $coll. | |||
|
638 | * | |||
|
639 | * Note: `view(from, to)` is equivalent to `view.slice(from, to)` | |||
|
640 | * $orderDependent | |||
|
641 | * | |||
|
642 | * @param from the index of the first element of the view | |||
|
643 | * @param until the index of the element following the view | |||
|
644 | * @return a non-strict view of a slice of this $coll, starting at index `from` | |||
|
645 | * and extending up to (but not including) index `until`. | |||
|
646 | */ | |||
|
647 | def view(from: Int, until: Int): TraversableView[A, Repr] = view.slice(from, until) | |||
|
648 | ||||
|
649 | /** Creates a non-strict filter of this $coll. | |||
|
650 | * | |||
|
651 | * Note: the difference between `c filter p` and `c withFilter p` is that | |||
|
652 | * the former creates a new collection, whereas the latter only | |||
|
653 | * restricts the domain of subsequent `map`, `flatMap`, `foreach`, | |||
|
654 | * and `withFilter` operations. | |||
|
655 | * $orderDependent | |||
|
656 | * | |||
|
657 | * @param p the predicate used to test elements. | |||
|
658 | * @return an object of class `WithFilter`, which supports | |||
|
659 | * `map`, `flatMap`, `foreach`, and `withFilter` operations. | |||
|
660 | * All these operations apply to those elements of this $coll which | |||
|
661 | * satisfy the predicate `p`. | |||
|
662 | */ | |||
|
663 | def withFilter(p: A => Boolean): FilterMonadic[A, Repr] = new WithFilter(p) | |||
|
664 | ||||
|
665 | /** A class supporting filtered operations. Instances of this class are | |||
|
666 | * returned by method `withFilter`. | |||
|
667 | */ | |||
|
668 | class WithFilter(p: A => Boolean) extends FilterMonadic[A, Repr] { | |||
|
669 | ||||
|
670 | /** Builds a new collection by applying a function to all elements of the | |||
|
671 | * outer $coll containing this `WithFilter` instance that satisfy predicate `p`. | |||
|
672 | * | |||
|
673 | * @param f the function to apply to each element. | |||
|
674 | * @tparam B the element type of the returned collection. | |||
|
675 | * @tparam That $thatinfo | |||
|
676 | * @param bf $bfinfo | |||
|
677 | * @return a new collection of type `That` resulting from applying | |||
|
678 | * the given function `f` to each element of the outer $coll | |||
|
679 | * that satisfies predicate `p` and collecting the results. | |||
|
680 | * | |||
|
681 | * @usecase def map[B](f: A => B): $Coll[B] | |||
|
682 | * | |||
|
683 | * @return a new $coll resulting from applying the given function | |||
|
684 | * `f` to each element of the outer $coll that satisfies | |||
|
685 | * predicate `p` and collecting the results. | |||
|
686 | */ | |||
|
687 | def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
688 | val b = bf(repr) | |||
|
689 | for (x <- self) | |||
|
690 | if (p(x)) b += f(x) | |||
|
691 | b.result | |||
|
692 | } | |||
|
693 | ||||
|
694 | /** Builds a new collection by applying a function to all elements of the | |||
|
695 | * outer $coll containing this `WithFilter` instance that satisfy | |||
|
696 | * predicate `p` and concatenating the results. | |||
|
697 | * | |||
|
698 | * @param f the function to apply to each element. | |||
|
699 | * @tparam B the element type of the returned collection. | |||
|
700 | * @tparam That $thatinfo | |||
|
701 | * @param bf $bfinfo | |||
|
702 | * @return a new collection of type `That` resulting from applying | |||
|
703 | * the given collection-valued function `f` to each element | |||
|
704 | * of the outer $coll that satisfies predicate `p` and | |||
|
705 | * concatenating the results. | |||
|
706 | * | |||
|
707 | * @usecase def flatMap[B](f: A => TraversableOnce[B]): $Coll[B] | |||
|
708 | * | |||
|
709 | * @return a new $coll resulting from applying the given collection-valued function | |||
|
710 | * `f` to each element of the outer $coll that satisfies predicate `p` and concatenating the results. | |||
|
711 | */ | |||
|
712 | def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |||
|
713 | val b = bf(repr) | |||
|
714 | for (x <- self) | |||
|
715 | if (p(x)) b ++= f(x).seq | |||
|
716 | b.result | |||
|
717 | } | |||
|
718 | ||||
|
719 | /** Applies a function `f` to all elements of the outer $coll containing | |||
|
720 | * this `WithFilter` instance that satisfy predicate `p`. | |||
|
721 | * | |||
|
722 | * @param f the function that is applied for its side-effect to every element. | |||
|
723 | * The result of function `f` is discarded. | |||
|
724 | * | |||
|
725 | * @tparam U the type parameter describing the result of function `f`. | |||
|
726 | * This result will always be ignored. Typically `U` is `Unit`, | |||
|
727 | * but this is not necessary. | |||
|
728 | * | |||
|
729 | * @usecase def foreach(f: A => Unit): Unit | |||
|
730 | */ | |||
|
731 | def foreach[U](f: A => U): Unit = | |||
|
732 | for (x <- self) | |||
|
733 | if (p(x)) f(x) | |||
|
734 | ||||
|
735 | /** Further refines the filter for this $coll. | |||
|
736 | * | |||
|
737 | * @param q the predicate used to test elements. | |||
|
738 | * @return an object of class `WithFilter`, which supports | |||
|
739 | * `map`, `flatMap`, `foreach`, and `withFilter` operations. | |||
|
740 | * All these operations apply to those elements of this $coll which | |||
|
741 | * satisfy the predicate `q` in addition to the predicate `p`. | |||
|
742 | */ | |||
|
743 | def withFilter(q: A => Boolean): WithFilter = | |||
|
744 | new WithFilter(x => p(x) && q(x)) | |||
|
745 | } | |||
|
746 | ||||
|
747 | // A helper for tails and inits. | |||
|
748 | private def iterateUntilEmpty(f: Traversable[A @uV] => Traversable[A @uV]): Iterator[Repr] = { | |||
|
749 | val it = Iterator.iterate(thisCollection)(f) takeWhile (x => !x.isEmpty) | |||
|
750 | it ++ Iterator(Nil) map (newBuilder ++= _ result) | |||
|
751 | } | |||
|
752 | } | |||
|
753 | ||||
|
754 | ||||
|
755 | </textarea> | |||
|
756 | </form> | |||
|
757 | ||||
|
758 | <script> | |||
|
759 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
760 | lineNumbers: true, | |||
|
761 | matchBrackets: true, | |||
|
762 | theme: "ambiance", | |||
|
763 | mode: "text/x-scala" | |||
|
764 | }); | |||
|
765 | </script> | |||
|
766 | </body> | |||
|
767 | </html> |
@@ -0,0 +1,224 b'' | |||||
|
1 | /** | |||
|
2 | * Author: Hans Engel | |||
|
3 | * Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementation by Koh Zi Chun) | |||
|
4 | */ | |||
|
5 | CodeMirror.defineMode("clojure", function () { | |||
|
6 | var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", CHARACTER = "string-2", | |||
|
7 | ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword"; | |||
|
8 | var INDENT_WORD_SKIP = 2; | |||
|
9 | ||||
|
10 | function makeKeywords(str) { | |||
|
11 | var obj = {}, words = str.split(" "); | |||
|
12 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | |||
|
13 | return obj; | |||
|
14 | } | |||
|
15 | ||||
|
16 | var atoms = makeKeywords("true false nil"); | |||
|
17 | ||||
|
18 | var keywords = makeKeywords( | |||
|
19 | "defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord defproject deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case 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 ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle"); | |||
|
20 | ||||
|
21 | var builtins = makeKeywords( | |||
|
22 | "* *' *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* *command-line-args* *compile-files* *compile-path* *compiler-options* *data-readers* *e *err* *file* *flush-on-newline* *fn-loader* *in* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *unchecked-math* *use-context-classloader* *verbose-defrecords* *warn-on-reflection* + +' - -' -> ->> ->ArrayChunk ->Vec ->VecNode ->VecSeq -cache-protocol-fn -reset-methods .. / < <= = == > >= EMPTY-NODE accessor aclone 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-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* bound? butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk 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 conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec dec' decimal? declare default-data-readers definline definterface defmacro defmethod defmulti defn defn- defonce defprotocol defrecord defstruct deftype delay delay? deliver denominator deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq error-handler error-mode eval even? every-pred every? ex-data ex-info extend extend-protocol extend-type extenders extends? false? ffirst file-seq filter 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 for force format frequencies future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator group-by hash hash-combine hash-map hash-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 ints 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 macroexpand-1 make-array make-hierarchy map map-indexed map? mapcat mapv max max-key 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 partition-by pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-dup print-method print-simple print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues 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 realized? reduce reduce-kv reductions ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure reify release-pending-sends rem remove remove-all-methods remove-method remove-ns remove-watch repeat repeatedly replace replicate require reset! reset-meta! resolve rest restart-agent resultset-seq reverse 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 sort-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 supers swap! symbol symbol? sync take take-last take-nth take-while test the-ns thread-bound? time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-add-int unchecked-byte unchecked-char unchecked-dec unchecked-dec-int unchecked-divide-int unchecked-double unchecked-float unchecked-inc unchecked-inc-int unchecked-int unchecked-long unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int unchecked-remainder-int unchecked-short 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 vector-of vector? when when-first when-let when-not while with-bindings with-bindings* 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-executor! set-agent-send-off-executor! some-> some->>"); | |||
|
23 | ||||
|
24 | var indentKeys = makeKeywords( | |||
|
25 | // Built-ins | |||
|
26 | "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 reify deftype defrecord defprotocol extend extend-protocol extend-type try catch " + | |||
|
27 | ||||
|
28 | // Binding forms | |||
|
29 | "let letfn binding loop for doseq dotimes when-let if-let " + | |||
|
30 | ||||
|
31 | // Data structures | |||
|
32 | "defstruct struct-map assoc " + | |||
|
33 | ||||
|
34 | // clojure.test | |||
|
35 | "testing deftest " + | |||
|
36 | ||||
|
37 | // contrib | |||
|
38 | "handler-case handle dotrace deftrace"); | |||
|
39 | ||||
|
40 | var tests = { | |||
|
41 | digit: /\d/, | |||
|
42 | digit_or_colon: /[\d:]/, | |||
|
43 | hex: /[0-9a-f]/i, | |||
|
44 | sign: /[+-]/, | |||
|
45 | exponent: /e/i, | |||
|
46 | keyword_char: /[^\s\(\[\;\)\]]/, | |||
|
47 | symbol: /[\w*+!\-\._?:\/]/ | |||
|
48 | }; | |||
|
49 | ||||
|
50 | function stateStack(indent, type, prev) { // represents a state stack object | |||
|
51 | this.indent = indent; | |||
|
52 | this.type = type; | |||
|
53 | this.prev = prev; | |||
|
54 | } | |||
|
55 | ||||
|
56 | function pushStack(state, indent, type) { | |||
|
57 | state.indentStack = new stateStack(indent, type, state.indentStack); | |||
|
58 | } | |||
|
59 | ||||
|
60 | function popStack(state) { | |||
|
61 | state.indentStack = state.indentStack.prev; | |||
|
62 | } | |||
|
63 | ||||
|
64 | function isNumber(ch, stream){ | |||
|
65 | // hex | |||
|
66 | if ( ch === '0' && stream.eat(/x/i) ) { | |||
|
67 | stream.eatWhile(tests.hex); | |||
|
68 | return true; | |||
|
69 | } | |||
|
70 | ||||
|
71 | // leading sign | |||
|
72 | if ( ( ch == '+' || ch == '-' ) && ( tests.digit.test(stream.peek()) ) ) { | |||
|
73 | stream.eat(tests.sign); | |||
|
74 | ch = stream.next(); | |||
|
75 | } | |||
|
76 | ||||
|
77 | if ( tests.digit.test(ch) ) { | |||
|
78 | stream.eat(ch); | |||
|
79 | stream.eatWhile(tests.digit); | |||
|
80 | ||||
|
81 | if ( '.' == stream.peek() ) { | |||
|
82 | stream.eat('.'); | |||
|
83 | stream.eatWhile(tests.digit); | |||
|
84 | } | |||
|
85 | ||||
|
86 | if ( stream.eat(tests.exponent) ) { | |||
|
87 | stream.eat(tests.sign); | |||
|
88 | stream.eatWhile(tests.digit); | |||
|
89 | } | |||
|
90 | ||||
|
91 | return true; | |||
|
92 | } | |||
|
93 | ||||
|
94 | return false; | |||
|
95 | } | |||
|
96 | ||||
|
97 | // Eat character that starts after backslash \ | |||
|
98 | function eatCharacter(stream) { | |||
|
99 | var first = stream.next(); | |||
|
100 | // Read special literals: backspace, newline, space, return. | |||
|
101 | // Just read all lowercase letters. | |||
|
102 | if (first.match(/[a-z]/) && stream.match(/[a-z]+/, true)) { | |||
|
103 | return; | |||
|
104 | } | |||
|
105 | // Read unicode character: \u1000 \uA0a1 | |||
|
106 | if (first === "u") { | |||
|
107 | stream.match(/[0-9a-z]{4}/i, true); | |||
|
108 | } | |||
|
109 | } | |||
|
110 | ||||
|
111 | return { | |||
|
112 | startState: function () { | |||
|
113 | return { | |||
|
114 | indentStack: null, | |||
|
115 | indentation: 0, | |||
|
116 | mode: false | |||
|
117 | }; | |||
|
118 | }, | |||
|
119 | ||||
|
120 | token: function (stream, state) { | |||
|
121 | if (state.indentStack == null && stream.sol()) { | |||
|
122 | // update indentation, but only if indentStack is empty | |||
|
123 | state.indentation = stream.indentation(); | |||
|
124 | } | |||
|
125 | ||||
|
126 | // skip spaces | |||
|
127 | if (stream.eatSpace()) { | |||
|
128 | return null; | |||
|
129 | } | |||
|
130 | var returnType = null; | |||
|
131 | ||||
|
132 | switch(state.mode){ | |||
|
133 | case "string": // multi-line string parsing mode | |||
|
134 | var next, escaped = false; | |||
|
135 | while ((next = stream.next()) != null) { | |||
|
136 | if (next == "\"" && !escaped) { | |||
|
137 | ||||
|
138 | state.mode = false; | |||
|
139 | break; | |||
|
140 | } | |||
|
141 | escaped = !escaped && next == "\\"; | |||
|
142 | } | |||
|
143 | returnType = STRING; // continue on in string mode | |||
|
144 | break; | |||
|
145 | default: // default parsing mode | |||
|
146 | var ch = stream.next(); | |||
|
147 | ||||
|
148 | if (ch == "\"") { | |||
|
149 | state.mode = "string"; | |||
|
150 | returnType = STRING; | |||
|
151 | } else if (ch == "\\") { | |||
|
152 | eatCharacter(stream); | |||
|
153 | returnType = CHARACTER; | |||
|
154 | } else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) { | |||
|
155 | returnType = ATOM; | |||
|
156 | } else if (ch == ";") { // comment | |||
|
157 | stream.skipToEnd(); // rest of the line is a comment | |||
|
158 | returnType = COMMENT; | |||
|
159 | } else if (isNumber(ch,stream)){ | |||
|
160 | returnType = NUMBER; | |||
|
161 | } else if (ch == "(" || ch == "[" || ch == "{" ) { | |||
|
162 | var keyWord = '', indentTemp = stream.column(), letter; | |||
|
163 | /** | |||
|
164 | Either | |||
|
165 | (indent-word .. | |||
|
166 | (non-indent-word .. | |||
|
167 | (;something else, bracket, etc. | |||
|
168 | */ | |||
|
169 | ||||
|
170 | if (ch == "(") while ((letter = stream.eat(tests.keyword_char)) != null) { | |||
|
171 | keyWord += letter; | |||
|
172 | } | |||
|
173 | ||||
|
174 | if (keyWord.length > 0 && (indentKeys.propertyIsEnumerable(keyWord) || | |||
|
175 | /^(?:def|with)/.test(keyWord))) { // indent-word | |||
|
176 | pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); | |||
|
177 | } else { // non-indent word | |||
|
178 | // we continue eating the spaces | |||
|
179 | stream.eatSpace(); | |||
|
180 | if (stream.eol() || stream.peek() == ";") { | |||
|
181 | // nothing significant after | |||
|
182 | // we restart indentation 1 space after | |||
|
183 | pushStack(state, indentTemp + 1, ch); | |||
|
184 | } else { | |||
|
185 | pushStack(state, indentTemp + stream.current().length, ch); // else we match | |||
|
186 | } | |||
|
187 | } | |||
|
188 | stream.backUp(stream.current().length - 1); // undo all the eating | |||
|
189 | ||||
|
190 | returnType = BRACKET; | |||
|
191 | } else if (ch == ")" || ch == "]" || ch == "}") { | |||
|
192 | returnType = BRACKET; | |||
|
193 | if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : (ch == "]" ? "[" :"{"))) { | |||
|
194 | popStack(state); | |||
|
195 | } | |||
|
196 | } else if ( ch == ":" ) { | |||
|
197 | stream.eatWhile(tests.symbol); | |||
|
198 | return ATOM; | |||
|
199 | } else { | |||
|
200 | stream.eatWhile(tests.symbol); | |||
|
201 | ||||
|
202 | if (keywords && keywords.propertyIsEnumerable(stream.current())) { | |||
|
203 | returnType = KEYWORD; | |||
|
204 | } else if (builtins && builtins.propertyIsEnumerable(stream.current())) { | |||
|
205 | returnType = BUILTIN; | |||
|
206 | } else if (atoms && atoms.propertyIsEnumerable(stream.current())) { | |||
|
207 | returnType = ATOM; | |||
|
208 | } else returnType = null; | |||
|
209 | } | |||
|
210 | } | |||
|
211 | ||||
|
212 | return returnType; | |||
|
213 | }, | |||
|
214 | ||||
|
215 | indent: function (state) { | |||
|
216 | if (state.indentStack == null) return state.indentation; | |||
|
217 | return state.indentStack.indent; | |||
|
218 | }, | |||
|
219 | ||||
|
220 | lineComment: ";;" | |||
|
221 | }; | |||
|
222 | }); | |||
|
223 | ||||
|
224 | CodeMirror.defineMIME("text/x-clojure", "clojure"); |
@@ -0,0 +1,76 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Clojure mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="clojure.js"></script> | |||
|
9 | <style>.CodeMirror {background: #f8f8f8;}</style> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Clojure mode</h1> | |||
|
14 | <form><textarea id="code" name="code"> | |||
|
15 | ; Conway's Game of Life, based on the work of: | |||
|
16 | ;; Laurent Petit https://gist.github.com/1200343 | |||
|
17 | ;; Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life | |||
|
18 | ||||
|
19 | (ns ^{:doc "Conway's Game of Life."} | |||
|
20 | game-of-life) | |||
|
21 | ||||
|
22 | ;; Core game of life's algorithm functions | |||
|
23 | ||||
|
24 | (defn neighbours | |||
|
25 | "Given a cell's coordinates, returns the coordinates of its neighbours." | |||
|
26 | [[x y]] | |||
|
27 | (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])] | |||
|
28 | [(+ dx x) (+ dy y)])) | |||
|
29 | ||||
|
30 | (defn step | |||
|
31 | "Given a set of living cells, computes the new set of living cells." | |||
|
32 | [cells] | |||
|
33 | (set (for [[cell n] (frequencies (mapcat neighbours cells)) | |||
|
34 | :when (or (= n 3) (and (= n 2) (cells cell)))] | |||
|
35 | cell))) | |||
|
36 | ||||
|
37 | ;; Utility methods for displaying game on a text terminal | |||
|
38 | ||||
|
39 | (defn print-board | |||
|
40 | "Prints a board on *out*, representing a step in the game." | |||
|
41 | [board w h] | |||
|
42 | (doseq [x (range (inc w)) y (range (inc h))] | |||
|
43 | (if (= y 0) (print "\n")) | |||
|
44 | (print (if (board [x y]) "[X]" " . ")))) | |||
|
45 | ||||
|
46 | (defn display-grids | |||
|
47 | "Prints a squence of boards on *out*, representing several steps." | |||
|
48 | [grids w h] | |||
|
49 | (doseq [board grids] | |||
|
50 | (print-board board w h) | |||
|
51 | (print "\n"))) | |||
|
52 | ||||
|
53 | ;; Launches an example board | |||
|
54 | ||||
|
55 | (def | |||
|
56 | ^{:doc "board represents the initial set of living cells"} | |||
|
57 | board #{[2 1] [2 2] [2 3]}) | |||
|
58 | ||||
|
59 | (display-grids (take 3 (iterate step board)) 5 5) | |||
|
60 | ||||
|
61 | ;; Let's play with characters | |||
|
62 | (println \1 \a \# \\ | |||
|
63 | \" \( \newline | |||
|
64 | \} \" \space | |||
|
65 | \tab \return \backspace | |||
|
66 | \u1000 \uAaAa \u9F9F) | |||
|
67 | ||||
|
68 | </textarea></form> | |||
|
69 | <script> | |||
|
70 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | |||
|
71 | </script> | |||
|
72 | ||||
|
73 | <p><strong>MIME types defined:</strong> <code>text/x-clojure</code>.</p> | |||
|
74 | ||||
|
75 | </body> | |||
|
76 | </html> |
@@ -0,0 +1,240 b'' | |||||
|
1 | /** | |||
|
2 | * Author: Gautam Mehta | |||
|
3 | * Branched from CodeMirror's Scheme mode | |||
|
4 | */ | |||
|
5 | CodeMirror.defineMode("cobol", function () { | |||
|
6 | var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", | |||
|
7 | ATOM = "atom", NUMBER = "number", KEYWORD = "keyword", MODTAG = "header", | |||
|
8 | COBOLLINENUM = "def", PERIOD = "link"; | |||
|
9 | function makeKeywords(str) { | |||
|
10 | var obj = {}, words = str.split(" "); | |||
|
11 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | |||
|
12 | return obj; | |||
|
13 | } | |||
|
14 | var atoms = makeKeywords("TRUE FALSE ZEROES ZEROS ZERO SPACES SPACE LOW-VALUE LOW-VALUES "); | |||
|
15 | var keywords = makeKeywords( | |||
|
16 | "ACCEPT ACCESS ACQUIRE ADD ADDRESS " + | |||
|
17 | "ADVANCING AFTER ALIAS ALL ALPHABET " + | |||
|
18 | "ALPHABETIC ALPHABETIC-LOWER ALPHABETIC-UPPER ALPHANUMERIC ALPHANUMERIC-EDITED " + | |||
|
19 | "ALSO ALTER ALTERNATE AND ANY " + | |||
|
20 | "ARE AREA AREAS ARITHMETIC ASCENDING " + | |||
|
21 | "ASSIGN AT ATTRIBUTE AUTHOR AUTO " + | |||
|
22 | "AUTO-SKIP AUTOMATIC B-AND B-EXOR B-LESS " + | |||
|
23 | "B-NOT B-OR BACKGROUND-COLOR BACKGROUND-COLOUR BEEP " + | |||
|
24 | "BEFORE BELL BINARY BIT BITS " + | |||
|
25 | "BLANK BLINK BLOCK BOOLEAN BOTTOM " + | |||
|
26 | "BY CALL CANCEL CD CF " + | |||
|
27 | "CH CHARACTER CHARACTERS CLASS CLOCK-UNITS " + | |||
|
28 | "CLOSE COBOL CODE CODE-SET COL " + | |||
|
29 | "COLLATING COLUMN COMMA COMMIT COMMITMENT " + | |||
|
30 | "COMMON COMMUNICATION COMP COMP-0 COMP-1 " + | |||
|
31 | "COMP-2 COMP-3 COMP-4 COMP-5 COMP-6 " + | |||
|
32 | "COMP-7 COMP-8 COMP-9 COMPUTATIONAL COMPUTATIONAL-0 " + | |||
|
33 | "COMPUTATIONAL-1 COMPUTATIONAL-2 COMPUTATIONAL-3 COMPUTATIONAL-4 COMPUTATIONAL-5 " + | |||
|
34 | "COMPUTATIONAL-6 COMPUTATIONAL-7 COMPUTATIONAL-8 COMPUTATIONAL-9 COMPUTE " + | |||
|
35 | "CONFIGURATION CONNECT CONSOLE CONTAINED CONTAINS " + | |||
|
36 | "CONTENT CONTINUE CONTROL CONTROL-AREA CONTROLS " + | |||
|
37 | "CONVERTING COPY CORR CORRESPONDING COUNT " + | |||
|
38 | "CRT CRT-UNDER CURRENCY CURRENT CURSOR " + | |||
|
39 | "DATA DATE DATE-COMPILED DATE-WRITTEN DAY " + | |||
|
40 | "DAY-OF-WEEK DB DB-ACCESS-CONTROL-KEY DB-DATA-NAME DB-EXCEPTION " + | |||
|
41 | "DB-FORMAT-NAME DB-RECORD-NAME DB-SET-NAME DB-STATUS DBCS " + | |||
|
42 | "DBCS-EDITED DE DEBUG-CONTENTS DEBUG-ITEM DEBUG-LINE " + | |||
|
43 | "DEBUG-NAME DEBUG-SUB-1 DEBUG-SUB-2 DEBUG-SUB-3 DEBUGGING " + | |||
|
44 | "DECIMAL-POINT DECLARATIVES DEFAULT DELETE DELIMITED " + | |||
|
45 | "DELIMITER DEPENDING DESCENDING DESCRIBED DESTINATION " + | |||
|
46 | "DETAIL DISABLE DISCONNECT DISPLAY DISPLAY-1 " + | |||
|
47 | "DISPLAY-2 DISPLAY-3 DISPLAY-4 DISPLAY-5 DISPLAY-6 " + | |||
|
48 | "DISPLAY-7 DISPLAY-8 DISPLAY-9 DIVIDE DIVISION " + | |||
|
49 | "DOWN DROP DUPLICATE DUPLICATES DYNAMIC " + | |||
|
50 | "EBCDIC EGI EJECT ELSE EMI " + | |||
|
51 | "EMPTY EMPTY-CHECK ENABLE END END. END-ACCEPT END-ACCEPT. " + | |||
|
52 | "END-ADD END-CALL END-COMPUTE END-DELETE END-DISPLAY " + | |||
|
53 | "END-DIVIDE END-EVALUATE END-IF END-INVOKE END-MULTIPLY " + | |||
|
54 | "END-OF-PAGE END-PERFORM END-READ END-RECEIVE END-RETURN " + | |||
|
55 | "END-REWRITE END-SEARCH END-START END-STRING END-SUBTRACT " + | |||
|
56 | "END-UNSTRING END-WRITE END-XML ENTER ENTRY " + | |||
|
57 | "ENVIRONMENT EOP EQUAL EQUALS ERASE " + | |||
|
58 | "ERROR ESI EVALUATE EVERY EXCEEDS " + | |||
|
59 | "EXCEPTION EXCLUSIVE EXIT EXTEND EXTERNAL " + | |||
|
60 | "EXTERNALLY-DESCRIBED-KEY FD FETCH FILE FILE-CONTROL " + | |||
|
61 | "FILE-STREAM FILES FILLER FINAL FIND " + | |||
|
62 | "FINISH FIRST FOOTING FOR FOREGROUND-COLOR " + | |||
|
63 | "FOREGROUND-COLOUR FORMAT FREE FROM FULL " + | |||
|
64 | "FUNCTION GENERATE GET GIVING GLOBAL " + | |||
|
65 | "GO GOBACK GREATER GROUP HEADING " + | |||
|
66 | "HIGH-VALUE HIGH-VALUES HIGHLIGHT I-O I-O-CONTROL " + | |||
|
67 | "ID IDENTIFICATION IF IN INDEX " + | |||
|
68 | "INDEX-1 INDEX-2 INDEX-3 INDEX-4 INDEX-5 " + | |||
|
69 | "INDEX-6 INDEX-7 INDEX-8 INDEX-9 INDEXED " + | |||
|
70 | "INDIC INDICATE INDICATOR INDICATORS INITIAL " + | |||
|
71 | "INITIALIZE INITIATE INPUT INPUT-OUTPUT INSPECT " + | |||
|
72 | "INSTALLATION INTO INVALID INVOKE IS " + | |||
|
73 | "JUST JUSTIFIED KANJI KEEP KEY " + | |||
|
74 | "LABEL LAST LD LEADING LEFT " + | |||
|
75 | "LEFT-JUSTIFY LENGTH LENGTH-CHECK LESS LIBRARY " + | |||
|
76 | "LIKE LIMIT LIMITS LINAGE LINAGE-COUNTER " + | |||
|
77 | "LINE LINE-COUNTER LINES LINKAGE LOCAL-STORAGE " + | |||
|
78 | "LOCALE LOCALLY LOCK " + | |||
|
79 | "MEMBER MEMORY MERGE MESSAGE METACLASS " + | |||
|
80 | "MODE MODIFIED MODIFY MODULES MOVE " + | |||
|
81 | "MULTIPLE MULTIPLY NATIONAL NATIVE NEGATIVE " + | |||
|
82 | "NEXT NO NO-ECHO NONE NOT " + | |||
|
83 | "NULL NULL-KEY-MAP NULL-MAP NULLS NUMBER " + | |||
|
84 | "NUMERIC NUMERIC-EDITED OBJECT OBJECT-COMPUTER OCCURS " + | |||
|
85 | "OF OFF OMITTED ON ONLY " + | |||
|
86 | "OPEN OPTIONAL OR ORDER ORGANIZATION " + | |||
|
87 | "OTHER OUTPUT OVERFLOW OWNER PACKED-DECIMAL " + | |||
|
88 | "PADDING PAGE PAGE-COUNTER PARSE PERFORM " + | |||
|
89 | "PF PH PIC PICTURE PLUS " + | |||
|
90 | "POINTER POSITION POSITIVE PREFIX PRESENT " + | |||
|
91 | "PRINTING PRIOR PROCEDURE PROCEDURE-POINTER PROCEDURES " + | |||
|
92 | "PROCEED PROCESS PROCESSING PROGRAM PROGRAM-ID " + | |||
|
93 | "PROMPT PROTECTED PURGE QUEUE QUOTE " + | |||
|
94 | "QUOTES RANDOM RD READ READY " + | |||
|
95 | "REALM RECEIVE RECONNECT RECORD RECORD-NAME " + | |||
|
96 | "RECORDS RECURSIVE REDEFINES REEL REFERENCE " + | |||
|
97 | "REFERENCE-MONITOR REFERENCES RELATION RELATIVE RELEASE " + | |||
|
98 | "REMAINDER REMOVAL RENAMES REPEATED REPLACE " + | |||
|
99 | "REPLACING REPORT REPORTING REPORTS REPOSITORY " + | |||
|
100 | "REQUIRED RERUN RESERVE RESET RETAINING " + | |||
|
101 | "RETRIEVAL RETURN RETURN-CODE RETURNING REVERSE-VIDEO " + | |||
|
102 | "REVERSED REWIND REWRITE RF RH " + | |||
|
103 | "RIGHT RIGHT-JUSTIFY ROLLBACK ROLLING ROUNDED " + | |||
|
104 | "RUN SAME SCREEN SD SEARCH " + | |||
|
105 | "SECTION SECURE SECURITY SEGMENT SEGMENT-LIMIT " + | |||
|
106 | "SELECT SEND SENTENCE SEPARATE SEQUENCE " + | |||
|
107 | "SEQUENTIAL SET SHARED SIGN SIZE " + | |||
|
108 | "SKIP1 SKIP2 SKIP3 SORT SORT-MERGE " + | |||
|
109 | "SORT-RETURN SOURCE SOURCE-COMPUTER SPACE-FILL " + | |||
|
110 | "SPECIAL-NAMES STANDARD STANDARD-1 STANDARD-2 " + | |||
|
111 | "START STARTING STATUS STOP STORE " + | |||
|
112 | "STRING SUB-QUEUE-1 SUB-QUEUE-2 SUB-QUEUE-3 SUB-SCHEMA " + | |||
|
113 | "SUBFILE SUBSTITUTE SUBTRACT SUM SUPPRESS " + | |||
|
114 | "SYMBOLIC SYNC SYNCHRONIZED SYSIN SYSOUT " + | |||
|
115 | "TABLE TALLYING TAPE TENANT TERMINAL " + | |||
|
116 | "TERMINATE TEST TEXT THAN THEN " + | |||
|
117 | "THROUGH THRU TIME TIMES TITLE " + | |||
|
118 | "TO TOP TRAILING TRAILING-SIGN TRANSACTION " + | |||
|
119 | "TYPE TYPEDEF UNDERLINE UNEQUAL UNIT " + | |||
|
120 | "UNSTRING UNTIL UP UPDATE UPON " + | |||
|
121 | "USAGE USAGE-MODE USE USING VALID " + | |||
|
122 | "VALIDATE VALUE VALUES VARYING VLR " + | |||
|
123 | "WAIT WHEN WHEN-COMPILED WITH WITHIN " + | |||
|
124 | "WORDS WORKING-STORAGE WRITE XML XML-CODE " + | |||
|
125 | "XML-EVENT XML-NTEXT XML-TEXT ZERO ZERO-FILL " ); | |||
|
126 | ||||
|
127 | var builtins = makeKeywords("- * ** / + < <= = > >= "); | |||
|
128 | var tests = { | |||
|
129 | digit: /\d/, | |||
|
130 | digit_or_colon: /[\d:]/, | |||
|
131 | hex: /[0-9a-f]/i, | |||
|
132 | sign: /[+-]/, | |||
|
133 | exponent: /e/i, | |||
|
134 | keyword_char: /[^\s\(\[\;\)\]]/, | |||
|
135 | symbol: /[\w*+\-]/ | |||
|
136 | }; | |||
|
137 | function isNumber(ch, stream){ | |||
|
138 | // hex | |||
|
139 | if ( ch === '0' && stream.eat(/x/i) ) { | |||
|
140 | stream.eatWhile(tests.hex); | |||
|
141 | return true; | |||
|
142 | } | |||
|
143 | // leading sign | |||
|
144 | if ( ( ch == '+' || ch == '-' ) && ( tests.digit.test(stream.peek()) ) ) { | |||
|
145 | stream.eat(tests.sign); | |||
|
146 | ch = stream.next(); | |||
|
147 | } | |||
|
148 | if ( tests.digit.test(ch) ) { | |||
|
149 | stream.eat(ch); | |||
|
150 | stream.eatWhile(tests.digit); | |||
|
151 | if ( '.' == stream.peek()) { | |||
|
152 | stream.eat('.'); | |||
|
153 | stream.eatWhile(tests.digit); | |||
|
154 | } | |||
|
155 | if ( stream.eat(tests.exponent) ) { | |||
|
156 | stream.eat(tests.sign); | |||
|
157 | stream.eatWhile(tests.digit); | |||
|
158 | } | |||
|
159 | return true; | |||
|
160 | } | |||
|
161 | return false; | |||
|
162 | } | |||
|
163 | return { | |||
|
164 | startState: function () { | |||
|
165 | return { | |||
|
166 | indentStack: null, | |||
|
167 | indentation: 0, | |||
|
168 | mode: false | |||
|
169 | }; | |||
|
170 | }, | |||
|
171 | token: function (stream, state) { | |||
|
172 | if (state.indentStack == null && stream.sol()) { | |||
|
173 | // update indentation, but only if indentStack is empty | |||
|
174 | state.indentation = 6 ; //stream.indentation(); | |||
|
175 | } | |||
|
176 | // skip spaces | |||
|
177 | if (stream.eatSpace()) { | |||
|
178 | return null; | |||
|
179 | } | |||
|
180 | var returnType = null; | |||
|
181 | switch(state.mode){ | |||
|
182 | case "string": // multi-line string parsing mode | |||
|
183 | var next = false; | |||
|
184 | while ((next = stream.next()) != null) { | |||
|
185 | if (next == "\"" || next == "\'") { | |||
|
186 | state.mode = false; | |||
|
187 | break; | |||
|
188 | } | |||
|
189 | } | |||
|
190 | returnType = STRING; // continue on in string mode | |||
|
191 | break; | |||
|
192 | default: // default parsing mode | |||
|
193 | var ch = stream.next(); | |||
|
194 | var col = stream.column(); | |||
|
195 | if (col >= 0 && col <= 5) { | |||
|
196 | returnType = COBOLLINENUM; | |||
|
197 | } else if (col >= 72 && col <= 79) { | |||
|
198 | stream.skipToEnd(); | |||
|
199 | returnType = MODTAG; | |||
|
200 | } else if (ch == "*" && col == 6) { // comment | |||
|
201 | stream.skipToEnd(); // rest of the line is a comment | |||
|
202 | returnType = COMMENT; | |||
|
203 | } else if (ch == "\"" || ch == "\'") { | |||
|
204 | state.mode = "string"; | |||
|
205 | returnType = STRING; | |||
|
206 | } else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) { | |||
|
207 | returnType = ATOM; | |||
|
208 | } else if (ch == ".") { | |||
|
209 | returnType = PERIOD; | |||
|
210 | } else if (isNumber(ch,stream)){ | |||
|
211 | returnType = NUMBER; | |||
|
212 | } else { | |||
|
213 | if (stream.current().match(tests.symbol)) { | |||
|
214 | while (col < 71) { | |||
|
215 | if (stream.eat(tests.symbol) === undefined) { | |||
|
216 | break; | |||
|
217 | } else { | |||
|
218 | col++; | |||
|
219 | } | |||
|
220 | } | |||
|
221 | } | |||
|
222 | if (keywords && keywords.propertyIsEnumerable(stream.current().toUpperCase())) { | |||
|
223 | returnType = KEYWORD; | |||
|
224 | } else if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase())) { | |||
|
225 | returnType = BUILTIN; | |||
|
226 | } else if (atoms && atoms.propertyIsEnumerable(stream.current().toUpperCase())) { | |||
|
227 | returnType = ATOM; | |||
|
228 | } else returnType = null; | |||
|
229 | } | |||
|
230 | } | |||
|
231 | return returnType; | |||
|
232 | }, | |||
|
233 | indent: function (state) { | |||
|
234 | if (state.indentStack == null) return state.indentation; | |||
|
235 | return state.indentStack.indent; | |||
|
236 | } | |||
|
237 | }; | |||
|
238 | }); | |||
|
239 | ||||
|
240 | CodeMirror.defineMIME("text/x-cobol", "cobol"); |
@@ -0,0 +1,195 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: COBOL mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="cobol.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../theme/neat.css"> | |||
|
11 | <link rel="stylesheet" href="../../theme/elegant.css"> | |||
|
12 | <link rel="stylesheet" href="../../theme/erlang-dark.css"> | |||
|
13 | <link rel="stylesheet" href="../../theme/night.css"> | |||
|
14 | <link rel="stylesheet" href="../../theme/monokai.css"> | |||
|
15 | <link rel="stylesheet" href="../../theme/cobalt.css"> | |||
|
16 | <link rel="stylesheet" href="../../theme/eclipse.css"> | |||
|
17 | <link rel="stylesheet" href="../../theme/rubyblue.css"> | |||
|
18 | <link rel="stylesheet" href="../../theme/lesser-dark.css"> | |||
|
19 | <link rel="stylesheet" href="../../theme/xq-dark.css"> | |||
|
20 | <link rel="stylesheet" href="../../theme/xq-light.css"> | |||
|
21 | <link rel="stylesheet" href="../../theme/ambiance.css"> | |||
|
22 | <link rel="stylesheet" href="../../theme/blackboard.css"> | |||
|
23 | <link rel="stylesheet" href="../../theme/vibrant-ink.css"> | |||
|
24 | <link rel="stylesheet" href="../../theme/solarized.css"> | |||
|
25 | <link rel="stylesheet" href="../../theme/twilight.css"> | |||
|
26 | <link rel="stylesheet" href="../../theme/midnight.css"> | |||
|
27 | <link rel="stylesheet" href="../../addon/dialog/dialog.css"> | |||
|
28 | <script src="../../addon/selection/active-line.js"></script> | |||
|
29 | <script src="../../addon/search/search.js"></script> | |||
|
30 | <script src="../../addon/dialog/dialog.js"></script> | |||
|
31 | <script src="../../addon/search/searchcursor.js"></script> | |||
|
32 | <style> | |||
|
33 | .CodeMirror { | |||
|
34 | border: 1px solid #eee; | |||
|
35 | font-size : 20px; | |||
|
36 | height : auto !important; | |||
|
37 | } | |||
|
38 | .CodeMirror-activeline-background {background: #555555 !important;} | |||
|
39 | </style> | |||
|
40 | </head> | |||
|
41 | <body> | |||
|
42 | <p> Select Theme <select onchange="selectTheme()" id="selectTheme"> | |||
|
43 | <option>default</option> | |||
|
44 | <option>ambiance</option> | |||
|
45 | <option>blackboard</option> | |||
|
46 | <option>cobalt</option> | |||
|
47 | <option>eclipse</option> | |||
|
48 | <option>elegant</option> | |||
|
49 | <option>erlang-dark</option> | |||
|
50 | <option>lesser-dark</option> | |||
|
51 | <option>midnight</option> | |||
|
52 | <option>monokai</option> | |||
|
53 | <option>neat</option> | |||
|
54 | <option>night</option> | |||
|
55 | <option>rubyblue</option> | |||
|
56 | <option>solarized dark</option> | |||
|
57 | <option>solarized light</option> | |||
|
58 | <option selected>twilight</option> | |||
|
59 | <option>vibrant-ink</option> | |||
|
60 | <option>xq-dark</option> | |||
|
61 | <option>xq-light</option> | |||
|
62 | </select> Select Font Size <select onchange="selectFontsize()" id="selectFontSize"> | |||
|
63 | <option value="13px">13px</option> | |||
|
64 | <option value="14px">14px</option> | |||
|
65 | <option value="16px">16px</option> | |||
|
66 | <option value="18px">18px</option> | |||
|
67 | <option value="20px" selected="selected">20px</option> | |||
|
68 | <option value="24px">24px</option> | |||
|
69 | <option value="26px">26px</option> | |||
|
70 | <option value="28px">28px</option> | |||
|
71 | <option value="30px">30px</option> | |||
|
72 | <option value="32px">32px</option> | |||
|
73 | <option value="34px">34px</option> | |||
|
74 | <option value="36px">36px</option> | |||
|
75 | </select> | |||
|
76 | <label for="checkBoxReadOnly">Read-only</label> | |||
|
77 | <input type="checkbox" id="checkBoxReadOnly" onchange="selectReadOnly()"> | |||
|
78 | <label for="id_tabToIndentSpace">Insert Spaces on Tab</label> | |||
|
79 | <input type="checkbox" id="id_tabToIndentSpace" onchange="tabToIndentSpace()"> | |||
|
80 | </p> | |||
|
81 | <textarea id="code" name="code"> | |||
|
82 | ---------1---------2---------3---------4---------5---------6---------7---------8 | |||
|
83 | 12345678911234567892123456789312345678941234567895123456789612345678971234567898 | |||
|
84 | 000010 IDENTIFICATION DIVISION. MODTGHERE | |||
|
85 | 000020 PROGRAM-ID. SAMPLE. | |||
|
86 | 000030 AUTHOR. TEST SAM. | |||
|
87 | 000040 DATE-WRITTEN. 5 February 2013 | |||
|
88 | 000041 | |||
|
89 | 000042* A sample program just to show the form. | |||
|
90 | 000043* The program copies its input to the output, | |||
|
91 | 000044* and counts the number of records. | |||
|
92 | 000045* At the end this number is printed. | |||
|
93 | 000046 | |||
|
94 | 000050 ENVIRONMENT DIVISION. | |||
|
95 | 000060 INPUT-OUTPUT SECTION. | |||
|
96 | 000070 FILE-CONTROL. | |||
|
97 | 000080 SELECT STUDENT-FILE ASSIGN TO SYSIN | |||
|
98 | 000090 ORGANIZATION IS LINE SEQUENTIAL. | |||
|
99 | 000100 SELECT PRINT-FILE ASSIGN TO SYSOUT | |||
|
100 | 000110 ORGANIZATION IS LINE SEQUENTIAL. | |||
|
101 | 000120 | |||
|
102 | 000130 DATA DIVISION. | |||
|
103 | 000140 FILE SECTION. | |||
|
104 | 000150 FD STUDENT-FILE | |||
|
105 | 000160 RECORD CONTAINS 43 CHARACTERS | |||
|
106 | 000170 DATA RECORD IS STUDENT-IN. | |||
|
107 | 000180 01 STUDENT-IN PIC X(43). | |||
|
108 | 000190 | |||
|
109 | 000200 FD PRINT-FILE | |||
|
110 | 000210 RECORD CONTAINS 80 CHARACTERS | |||
|
111 | 000220 DATA RECORD IS PRINT-LINE. | |||
|
112 | 000230 01 PRINT-LINE PIC X(80). | |||
|
113 | 000240 | |||
|
114 | 000250 WORKING-STORAGE SECTION. | |||
|
115 | 000260 01 DATA-REMAINS-SWITCH PIC X(2) VALUE SPACES. | |||
|
116 | 000261 01 RECORDS-WRITTEN PIC 99. | |||
|
117 | 000270 | |||
|
118 | 000280 01 DETAIL-LINE. | |||
|
119 | 000290 05 FILLER PIC X(7) VALUE SPACES. | |||
|
120 | 000300 05 RECORD-IMAGE PIC X(43). | |||
|
121 | 000310 05 FILLER PIC X(30) VALUE SPACES. | |||
|
122 | 000311 | |||
|
123 | 000312 01 SUMMARY-LINE. | |||
|
124 | 000313 05 FILLER PIC X(7) VALUE SPACES. | |||
|
125 | 000314 05 TOTAL-READ PIC 99. | |||
|
126 | 000315 05 FILLER PIC X VALUE SPACE. | |||
|
127 | 000316 05 FILLER PIC X(17) | |||
|
128 | 000317 VALUE 'Records were read'. | |||
|
129 | 000318 05 FILLER PIC X(53) VALUE SPACES. | |||
|
130 | 000319 | |||
|
131 | 000320 PROCEDURE DIVISION. | |||
|
132 | 000321 | |||
|
133 | 000330 PREPARE-SENIOR-REPORT. | |||
|
134 | 000340 OPEN INPUT STUDENT-FILE | |||
|
135 | 000350 OUTPUT PRINT-FILE. | |||
|
136 | 000351 MOVE ZERO TO RECORDS-WRITTEN. | |||
|
137 | 000360 READ STUDENT-FILE | |||
|
138 | 000370 AT END MOVE 'NO' TO DATA-REMAINS-SWITCH | |||
|
139 | 000380 END-READ. | |||
|
140 | 000390 PERFORM PROCESS-RECORDS | |||
|
141 | 000410 UNTIL DATA-REMAINS-SWITCH = 'NO'. | |||
|
142 | 000411 PERFORM PRINT-SUMMARY. | |||
|
143 | 000420 CLOSE STUDENT-FILE | |||
|
144 | 000430 PRINT-FILE. | |||
|
145 | 000440 STOP RUN. | |||
|
146 | 000450 | |||
|
147 | 000460 PROCESS-RECORDS. | |||
|
148 | 000470 MOVE STUDENT-IN TO RECORD-IMAGE. | |||
|
149 | 000480 MOVE DETAIL-LINE TO PRINT-LINE. | |||
|
150 | 000490 WRITE PRINT-LINE. | |||
|
151 | 000500 ADD 1 TO RECORDS-WRITTEN. | |||
|
152 | 000510 READ STUDENT-FILE | |||
|
153 | 000520 AT END MOVE 'NO' TO DATA-REMAINS-SWITCH | |||
|
154 | 000530 END-READ. | |||
|
155 | 000540 | |||
|
156 | 000550 PRINT-SUMMARY. | |||
|
157 | 000560 MOVE RECORDS-WRITTEN TO TOTAL-READ. | |||
|
158 | 000570 MOVE SUMMARY-LINE TO PRINT-LINE. | |||
|
159 | 000571 WRITE PRINT-LINE. | |||
|
160 | 000572 | |||
|
161 | 000580 | |||
|
162 | </textarea> | |||
|
163 | <script> | |||
|
164 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
165 | lineNumbers: true, | |||
|
166 | matchBrackets: true, | |||
|
167 | mode: "text/x-cobol", | |||
|
168 | theme : "twilight", | |||
|
169 | styleActiveLine: true, | |||
|
170 | showCursorWhenSelecting : true, | |||
|
171 | }); | |||
|
172 | function selectTheme() { | |||
|
173 | var themeInput = document.getElementById("selectTheme"); | |||
|
174 | var theme = themeInput.options[themeInput.selectedIndex].innerHTML; | |||
|
175 | editor.setOption("theme", theme); | |||
|
176 | } | |||
|
177 | function selectFontsize() { | |||
|
178 | var fontSizeInput = document.getElementById("selectFontSize"); | |||
|
179 | var fontSize = fontSizeInput.options[fontSizeInput.selectedIndex].innerHTML; | |||
|
180 | editor.getWrapperElement().style["font-size"] = fontSize; | |||
|
181 | editor.refresh(); | |||
|
182 | } | |||
|
183 | function selectReadOnly() { | |||
|
184 | editor.setOption("readOnly", document.getElementById("checkBoxReadOnly").checked); | |||
|
185 | } | |||
|
186 | function tabToIndentSpace() { | |||
|
187 | if (document.getElementById("id_tabToIndentSpace").checked) { | |||
|
188 | editor.setOption("extraKeys", {Tab: function(cm) { cm.replaceSelection(" ", "end"); }}); | |||
|
189 | } else { | |||
|
190 | editor.setOption("extraKeys", {Tab: function(cm) { cm.replaceSelection(" ", "end"); }}); | |||
|
191 | } | |||
|
192 | } | |||
|
193 | </script> | |||
|
194 | </body> | |||
|
195 | </html> |
@@ -0,0 +1,22 b'' | |||||
|
1 | The MIT License | |||
|
2 | ||||
|
3 | Copyright (c) 2011 Jeff Pickhardt | |||
|
4 | Modified from the Python CodeMirror mode, Copyright (c) 2010 Timothy Farrell | |||
|
5 | ||||
|
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | |||
|
7 | of this software and associated documentation files (the "Software"), to deal | |||
|
8 | in the Software without restriction, including without limitation the rights | |||
|
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
|
10 | copies of the Software, and to permit persons to whom the Software is | |||
|
11 | furnished to do so, subject to the following conditions: | |||
|
12 | ||||
|
13 | The above copyright notice and this permission notice shall be included in | |||
|
14 | all copies or substantial portions of the Software. | |||
|
15 | ||||
|
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
|
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
|
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
|
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
|
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
|
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
|
22 | THE SOFTWARE. No newline at end of file |
@@ -0,0 +1,347 b'' | |||||
|
1 | /** | |||
|
2 | * Link to the project's GitHub page: | |||
|
3 | * https://github.com/pickhardt/coffeescript-codemirror-mode | |||
|
4 | */ | |||
|
5 | CodeMirror.defineMode('coffeescript', function(conf) { | |||
|
6 | var ERRORCLASS = 'error'; | |||
|
7 | ||||
|
8 | function wordRegexp(words) { | |||
|
9 | return new RegExp("^((" + words.join(")|(") + "))\\b"); | |||
|
10 | } | |||
|
11 | ||||
|
12 | var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]"); | |||
|
13 | var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\},:`=;\\.]'); | |||
|
14 | var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))"); | |||
|
15 | var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); | |||
|
16 | var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))"); | |||
|
17 | var identifiers = new RegExp("^[_A-Za-z$][_A-Za-z$0-9]*"); | |||
|
18 | var properties = new RegExp("^(@|this\.)[_A-Za-z$][_A-Za-z$0-9]*"); | |||
|
19 | ||||
|
20 | var wordOperators = wordRegexp(['and', 'or', 'not', | |||
|
21 | 'is', 'isnt', 'in', | |||
|
22 | 'instanceof', 'typeof']); | |||
|
23 | var indentKeywords = ['for', 'while', 'loop', 'if', 'unless', 'else', | |||
|
24 | 'switch', 'try', 'catch', 'finally', 'class']; | |||
|
25 | var commonKeywords = ['break', 'by', 'continue', 'debugger', 'delete', | |||
|
26 | 'do', 'in', 'of', 'new', 'return', 'then', | |||
|
27 | 'this', 'throw', 'when', 'until']; | |||
|
28 | ||||
|
29 | var keywords = wordRegexp(indentKeywords.concat(commonKeywords)); | |||
|
30 | ||||
|
31 | indentKeywords = wordRegexp(indentKeywords); | |||
|
32 | ||||
|
33 | ||||
|
34 | var stringPrefixes = new RegExp("^('{3}|\"{3}|['\"])"); | |||
|
35 | var regexPrefixes = new RegExp("^(/{3}|/)"); | |||
|
36 | var commonConstants = ['Infinity', 'NaN', 'undefined', 'null', 'true', 'false', 'on', 'off', 'yes', 'no']; | |||
|
37 | var constants = wordRegexp(commonConstants); | |||
|
38 | ||||
|
39 | // Tokenizers | |||
|
40 | function tokenBase(stream, state) { | |||
|
41 | // Handle scope changes | |||
|
42 | if (stream.sol()) { | |||
|
43 | var scopeOffset = state.scopes[0].offset; | |||
|
44 | if (stream.eatSpace()) { | |||
|
45 | var lineOffset = stream.indentation(); | |||
|
46 | if (lineOffset > scopeOffset) { | |||
|
47 | return 'indent'; | |||
|
48 | } else if (lineOffset < scopeOffset) { | |||
|
49 | return 'dedent'; | |||
|
50 | } | |||
|
51 | return null; | |||
|
52 | } else { | |||
|
53 | if (scopeOffset > 0) { | |||
|
54 | dedent(stream, state); | |||
|
55 | } | |||
|
56 | } | |||
|
57 | } | |||
|
58 | if (stream.eatSpace()) { | |||
|
59 | return null; | |||
|
60 | } | |||
|
61 | ||||
|
62 | var ch = stream.peek(); | |||
|
63 | ||||
|
64 | // Handle docco title comment (single line) | |||
|
65 | if (stream.match("####")) { | |||
|
66 | stream.skipToEnd(); | |||
|
67 | return 'comment'; | |||
|
68 | } | |||
|
69 | ||||
|
70 | // Handle multi line comments | |||
|
71 | if (stream.match("###")) { | |||
|
72 | state.tokenize = longComment; | |||
|
73 | return state.tokenize(stream, state); | |||
|
74 | } | |||
|
75 | ||||
|
76 | // Single line comment | |||
|
77 | if (ch === '#') { | |||
|
78 | stream.skipToEnd(); | |||
|
79 | return 'comment'; | |||
|
80 | } | |||
|
81 | ||||
|
82 | // Handle number literals | |||
|
83 | if (stream.match(/^-?[0-9\.]/, false)) { | |||
|
84 | var floatLiteral = false; | |||
|
85 | // Floats | |||
|
86 | if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) { | |||
|
87 | floatLiteral = true; | |||
|
88 | } | |||
|
89 | if (stream.match(/^-?\d+\.\d*/)) { | |||
|
90 | floatLiteral = true; | |||
|
91 | } | |||
|
92 | if (stream.match(/^-?\.\d+/)) { | |||
|
93 | floatLiteral = true; | |||
|
94 | } | |||
|
95 | ||||
|
96 | if (floatLiteral) { | |||
|
97 | // prevent from getting extra . on 1.. | |||
|
98 | if (stream.peek() == "."){ | |||
|
99 | stream.backUp(1); | |||
|
100 | } | |||
|
101 | return 'number'; | |||
|
102 | } | |||
|
103 | // Integers | |||
|
104 | var intLiteral = false; | |||
|
105 | // Hex | |||
|
106 | if (stream.match(/^-?0x[0-9a-f]+/i)) { | |||
|
107 | intLiteral = true; | |||
|
108 | } | |||
|
109 | // Decimal | |||
|
110 | if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) { | |||
|
111 | intLiteral = true; | |||
|
112 | } | |||
|
113 | // Zero by itself with no other piece of number. | |||
|
114 | if (stream.match(/^-?0(?![\dx])/i)) { | |||
|
115 | intLiteral = true; | |||
|
116 | } | |||
|
117 | if (intLiteral) { | |||
|
118 | return 'number'; | |||
|
119 | } | |||
|
120 | } | |||
|
121 | ||||
|
122 | // Handle strings | |||
|
123 | if (stream.match(stringPrefixes)) { | |||
|
124 | state.tokenize = tokenFactory(stream.current(), 'string'); | |||
|
125 | return state.tokenize(stream, state); | |||
|
126 | } | |||
|
127 | // Handle regex literals | |||
|
128 | if (stream.match(regexPrefixes)) { | |||
|
129 | if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division | |||
|
130 | state.tokenize = tokenFactory(stream.current(), 'string-2'); | |||
|
131 | return state.tokenize(stream, state); | |||
|
132 | } else { | |||
|
133 | stream.backUp(1); | |||
|
134 | } | |||
|
135 | } | |||
|
136 | ||||
|
137 | // Handle operators and delimiters | |||
|
138 | if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { | |||
|
139 | return 'punctuation'; | |||
|
140 | } | |||
|
141 | if (stream.match(doubleOperators) | |||
|
142 | || stream.match(singleOperators) | |||
|
143 | || stream.match(wordOperators)) { | |||
|
144 | return 'operator'; | |||
|
145 | } | |||
|
146 | if (stream.match(singleDelimiters)) { | |||
|
147 | return 'punctuation'; | |||
|
148 | } | |||
|
149 | ||||
|
150 | if (stream.match(constants)) { | |||
|
151 | return 'atom'; | |||
|
152 | } | |||
|
153 | ||||
|
154 | if (stream.match(keywords)) { | |||
|
155 | return 'keyword'; | |||
|
156 | } | |||
|
157 | ||||
|
158 | if (stream.match(identifiers)) { | |||
|
159 | return 'variable'; | |||
|
160 | } | |||
|
161 | ||||
|
162 | if (stream.match(properties)) { | |||
|
163 | return 'property'; | |||
|
164 | } | |||
|
165 | ||||
|
166 | // Handle non-detected items | |||
|
167 | stream.next(); | |||
|
168 | return ERRORCLASS; | |||
|
169 | } | |||
|
170 | ||||
|
171 | function tokenFactory(delimiter, outclass) { | |||
|
172 | var singleline = delimiter.length == 1; | |||
|
173 | return function(stream, state) { | |||
|
174 | while (!stream.eol()) { | |||
|
175 | stream.eatWhile(/[^'"\/\\]/); | |||
|
176 | if (stream.eat('\\')) { | |||
|
177 | stream.next(); | |||
|
178 | if (singleline && stream.eol()) { | |||
|
179 | return outclass; | |||
|
180 | } | |||
|
181 | } else if (stream.match(delimiter)) { | |||
|
182 | state.tokenize = tokenBase; | |||
|
183 | return outclass; | |||
|
184 | } else { | |||
|
185 | stream.eat(/['"\/]/); | |||
|
186 | } | |||
|
187 | } | |||
|
188 | if (singleline) { | |||
|
189 | if (conf.mode.singleLineStringErrors) { | |||
|
190 | outclass = ERRORCLASS; | |||
|
191 | } else { | |||
|
192 | state.tokenize = tokenBase; | |||
|
193 | } | |||
|
194 | } | |||
|
195 | return outclass; | |||
|
196 | }; | |||
|
197 | } | |||
|
198 | ||||
|
199 | function longComment(stream, state) { | |||
|
200 | while (!stream.eol()) { | |||
|
201 | stream.eatWhile(/[^#]/); | |||
|
202 | if (stream.match("###")) { | |||
|
203 | state.tokenize = tokenBase; | |||
|
204 | break; | |||
|
205 | } | |||
|
206 | stream.eatWhile("#"); | |||
|
207 | } | |||
|
208 | return "comment"; | |||
|
209 | } | |||
|
210 | ||||
|
211 | function indent(stream, state, type) { | |||
|
212 | type = type || 'coffee'; | |||
|
213 | var indentUnit = 0; | |||
|
214 | if (type === 'coffee') { | |||
|
215 | for (var i = 0; i < state.scopes.length; i++) { | |||
|
216 | if (state.scopes[i].type === 'coffee') { | |||
|
217 | indentUnit = state.scopes[i].offset + conf.indentUnit; | |||
|
218 | break; | |||
|
219 | } | |||
|
220 | } | |||
|
221 | } else { | |||
|
222 | indentUnit = stream.column() + stream.current().length; | |||
|
223 | } | |||
|
224 | state.scopes.unshift({ | |||
|
225 | offset: indentUnit, | |||
|
226 | type: type | |||
|
227 | }); | |||
|
228 | } | |||
|
229 | ||||
|
230 | function dedent(stream, state) { | |||
|
231 | if (state.scopes.length == 1) return; | |||
|
232 | if (state.scopes[0].type === 'coffee') { | |||
|
233 | var _indent = stream.indentation(); | |||
|
234 | var _indent_index = -1; | |||
|
235 | for (var i = 0; i < state.scopes.length; ++i) { | |||
|
236 | if (_indent === state.scopes[i].offset) { | |||
|
237 | _indent_index = i; | |||
|
238 | break; | |||
|
239 | } | |||
|
240 | } | |||
|
241 | if (_indent_index === -1) { | |||
|
242 | return true; | |||
|
243 | } | |||
|
244 | while (state.scopes[0].offset !== _indent) { | |||
|
245 | state.scopes.shift(); | |||
|
246 | } | |||
|
247 | return false; | |||
|
248 | } else { | |||
|
249 | state.scopes.shift(); | |||
|
250 | return false; | |||
|
251 | } | |||
|
252 | } | |||
|
253 | ||||
|
254 | function tokenLexer(stream, state) { | |||
|
255 | var style = state.tokenize(stream, state); | |||
|
256 | var current = stream.current(); | |||
|
257 | ||||
|
258 | // Handle '.' connected identifiers | |||
|
259 | if (current === '.') { | |||
|
260 | style = state.tokenize(stream, state); | |||
|
261 | current = stream.current(); | |||
|
262 | if (style === 'variable') { | |||
|
263 | return 'variable'; | |||
|
264 | } else { | |||
|
265 | return ERRORCLASS; | |||
|
266 | } | |||
|
267 | } | |||
|
268 | ||||
|
269 | // Handle scope changes. | |||
|
270 | if (current === 'return') { | |||
|
271 | state.dedent += 1; | |||
|
272 | } | |||
|
273 | if (((current === '->' || current === '=>') && | |||
|
274 | !state.lambda && | |||
|
275 | state.scopes[0].type == 'coffee' && | |||
|
276 | stream.peek() === '') | |||
|
277 | || style === 'indent') { | |||
|
278 | indent(stream, state); | |||
|
279 | } | |||
|
280 | var delimiter_index = '[({'.indexOf(current); | |||
|
281 | if (delimiter_index !== -1) { | |||
|
282 | indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1)); | |||
|
283 | } | |||
|
284 | if (indentKeywords.exec(current)){ | |||
|
285 | indent(stream, state); | |||
|
286 | } | |||
|
287 | if (current == 'then'){ | |||
|
288 | dedent(stream, state); | |||
|
289 | } | |||
|
290 | ||||
|
291 | ||||
|
292 | if (style === 'dedent') { | |||
|
293 | if (dedent(stream, state)) { | |||
|
294 | return ERRORCLASS; | |||
|
295 | } | |||
|
296 | } | |||
|
297 | delimiter_index = '])}'.indexOf(current); | |||
|
298 | if (delimiter_index !== -1) { | |||
|
299 | if (dedent(stream, state)) { | |||
|
300 | return ERRORCLASS; | |||
|
301 | } | |||
|
302 | } | |||
|
303 | if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'coffee') { | |||
|
304 | if (state.scopes.length > 1) state.scopes.shift(); | |||
|
305 | state.dedent -= 1; | |||
|
306 | } | |||
|
307 | ||||
|
308 | return style; | |||
|
309 | } | |||
|
310 | ||||
|
311 | var external = { | |||
|
312 | startState: function(basecolumn) { | |||
|
313 | return { | |||
|
314 | tokenize: tokenBase, | |||
|
315 | scopes: [{offset:basecolumn || 0, type:'coffee'}], | |||
|
316 | lastToken: null, | |||
|
317 | lambda: false, | |||
|
318 | dedent: 0 | |||
|
319 | }; | |||
|
320 | }, | |||
|
321 | ||||
|
322 | token: function(stream, state) { | |||
|
323 | var style = tokenLexer(stream, state); | |||
|
324 | ||||
|
325 | state.lastToken = {style:style, content: stream.current()}; | |||
|
326 | ||||
|
327 | if (stream.eol() && stream.lambda) { | |||
|
328 | state.lambda = false; | |||
|
329 | } | |||
|
330 | ||||
|
331 | return style; | |||
|
332 | }, | |||
|
333 | ||||
|
334 | indent: function(state) { | |||
|
335 | if (state.tokenize != tokenBase) { | |||
|
336 | return 0; | |||
|
337 | } | |||
|
338 | ||||
|
339 | return state.scopes[0].offset; | |||
|
340 | }, | |||
|
341 | ||||
|
342 | lineComment: "#" | |||
|
343 | }; | |||
|
344 | return external; | |||
|
345 | }); | |||
|
346 | ||||
|
347 | CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript'); |
This diff has been collapsed as it changes many lines, (728 lines changed) Show them Hide them | |||||
@@ -0,0 +1,728 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: CoffeeScript mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="coffeescript.js"></script> | |||
|
9 | <style>.CodeMirror {border-top: 1px solid silver; border-bottom: 1px solid silver;}</style> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: CoffeeScript mode</h1> | |||
|
14 | <form><textarea id="code" name="code"> | |||
|
15 | # CoffeeScript mode for CodeMirror | |||
|
16 | # Copyright (c) 2011 Jeff Pickhardt, released under | |||
|
17 | # the MIT License. | |||
|
18 | # | |||
|
19 | # Modified from the Python CodeMirror mode, which also is | |||
|
20 | # under the MIT License Copyright (c) 2010 Timothy Farrell. | |||
|
21 | # | |||
|
22 | # The following script, Underscore.coffee, is used to | |||
|
23 | # demonstrate CoffeeScript mode for CodeMirror. | |||
|
24 | # | |||
|
25 | # To download CoffeeScript mode for CodeMirror, go to: | |||
|
26 | # https://github.com/pickhardt/coffeescript-codemirror-mode | |||
|
27 | ||||
|
28 | # **Underscore.coffee | |||
|
29 | # (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.** | |||
|
30 | # Underscore is freely distributable under the terms of the | |||
|
31 | # [MIT license](http://en.wikipedia.org/wiki/MIT_License). | |||
|
32 | # Portions of Underscore are inspired by or borrowed from | |||
|
33 | # [Prototype.js](http://prototypejs.org/api), Oliver Steele's | |||
|
34 | # [Functional](http://osteele.com), and John Resig's | |||
|
35 | # [Micro-Templating](http://ejohn.org). | |||
|
36 | # For all details and documentation: | |||
|
37 | # http://documentcloud.github.com/underscore/ | |||
|
38 | ||||
|
39 | ||||
|
40 | # Baseline setup | |||
|
41 | # -------------- | |||
|
42 | ||||
|
43 | # Establish the root object, `window` in the browser, or `global` on the server. | |||
|
44 | root = this | |||
|
45 | ||||
|
46 | ||||
|
47 | # Save the previous value of the `_` variable. | |||
|
48 | previousUnderscore = root._ | |||
|
49 | ||||
|
50 | ### Multiline | |||
|
51 | comment | |||
|
52 | ### | |||
|
53 | ||||
|
54 | # Establish the object that gets thrown to break out of a loop iteration. | |||
|
55 | # `StopIteration` is SOP on Mozilla. | |||
|
56 | breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration | |||
|
57 | ||||
|
58 | ||||
|
59 | #### Docco style single line comment (title) | |||
|
60 | ||||
|
61 | ||||
|
62 | # Helper function to escape **RegExp** contents, because JS doesn't have one. | |||
|
63 | escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') | |||
|
64 | ||||
|
65 | ||||
|
66 | # Save bytes in the minified (but not gzipped) version: | |||
|
67 | ArrayProto = Array.prototype | |||
|
68 | ObjProto = Object.prototype | |||
|
69 | ||||
|
70 | ||||
|
71 | # Create quick reference variables for speed access to core prototypes. | |||
|
72 | slice = ArrayProto.slice | |||
|
73 | unshift = ArrayProto.unshift | |||
|
74 | toString = ObjProto.toString | |||
|
75 | hasOwnProperty = ObjProto.hasOwnProperty | |||
|
76 | propertyIsEnumerable = ObjProto.propertyIsEnumerable | |||
|
77 | ||||
|
78 | ||||
|
79 | # All **ECMA5** native implementations we hope to use are declared here. | |||
|
80 | nativeForEach = ArrayProto.forEach | |||
|
81 | nativeMap = ArrayProto.map | |||
|
82 | nativeReduce = ArrayProto.reduce | |||
|
83 | nativeReduceRight = ArrayProto.reduceRight | |||
|
84 | nativeFilter = ArrayProto.filter | |||
|
85 | nativeEvery = ArrayProto.every | |||
|
86 | nativeSome = ArrayProto.some | |||
|
87 | nativeIndexOf = ArrayProto.indexOf | |||
|
88 | nativeLastIndexOf = ArrayProto.lastIndexOf | |||
|
89 | nativeIsArray = Array.isArray | |||
|
90 | nativeKeys = Object.keys | |||
|
91 | ||||
|
92 | ||||
|
93 | # Create a safe reference to the Underscore object for use below. | |||
|
94 | _ = (obj) -> new wrapper(obj) | |||
|
95 | ||||
|
96 | ||||
|
97 | # Export the Underscore object for **CommonJS**. | |||
|
98 | if typeof(exports) != 'undefined' then exports._ = _ | |||
|
99 | ||||
|
100 | ||||
|
101 | # Export Underscore to global scope. | |||
|
102 | root._ = _ | |||
|
103 | ||||
|
104 | ||||
|
105 | # Current version. | |||
|
106 | _.VERSION = '1.1.0' | |||
|
107 | ||||
|
108 | ||||
|
109 | # Collection Functions | |||
|
110 | # -------------------- | |||
|
111 | ||||
|
112 | # The cornerstone, an **each** implementation. | |||
|
113 | # Handles objects implementing **forEach**, arrays, and raw objects. | |||
|
114 | _.each = (obj, iterator, context) -> | |||
|
115 | try | |||
|
116 | if nativeForEach and obj.forEach is nativeForEach | |||
|
117 | obj.forEach iterator, context | |||
|
118 | else if _.isNumber obj.length | |||
|
119 | iterator.call context, obj[i], i, obj for i in [0...obj.length] | |||
|
120 | else | |||
|
121 | iterator.call context, val, key, obj for own key, val of obj | |||
|
122 | catch e | |||
|
123 | throw e if e isnt breaker | |||
|
124 | obj | |||
|
125 | ||||
|
126 | ||||
|
127 | # Return the results of applying the iterator to each element. Use JavaScript | |||
|
128 | # 1.6's version of **map**, if possible. | |||
|
129 | _.map = (obj, iterator, context) -> | |||
|
130 | return obj.map(iterator, context) if nativeMap and obj.map is nativeMap | |||
|
131 | results = [] | |||
|
132 | _.each obj, (value, index, list) -> | |||
|
133 | results.push iterator.call context, value, index, list | |||
|
134 | results | |||
|
135 | ||||
|
136 | ||||
|
137 | # **Reduce** builds up a single result from a list of values. Also known as | |||
|
138 | # **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible. | |||
|
139 | _.reduce = (obj, iterator, memo, context) -> | |||
|
140 | if nativeReduce and obj.reduce is nativeReduce | |||
|
141 | iterator = _.bind iterator, context if context | |||
|
142 | return obj.reduce iterator, memo | |||
|
143 | _.each obj, (value, index, list) -> | |||
|
144 | memo = iterator.call context, memo, value, index, list | |||
|
145 | memo | |||
|
146 | ||||
|
147 | ||||
|
148 | # The right-associative version of **reduce**, also known as **foldr**. Uses | |||
|
149 | # JavaScript 1.8's version of **reduceRight**, if available. | |||
|
150 | _.reduceRight = (obj, iterator, memo, context) -> | |||
|
151 | if nativeReduceRight and obj.reduceRight is nativeReduceRight | |||
|
152 | iterator = _.bind iterator, context if context | |||
|
153 | return obj.reduceRight iterator, memo | |||
|
154 | reversed = _.clone(_.toArray(obj)).reverse() | |||
|
155 | _.reduce reversed, iterator, memo, context | |||
|
156 | ||||
|
157 | ||||
|
158 | # Return the first value which passes a truth test. | |||
|
159 | _.detect = (obj, iterator, context) -> | |||
|
160 | result = null | |||
|
161 | _.each obj, (value, index, list) -> | |||
|
162 | if iterator.call context, value, index, list | |||
|
163 | result = value | |||
|
164 | _.breakLoop() | |||
|
165 | result | |||
|
166 | ||||
|
167 | ||||
|
168 | # Return all the elements that pass a truth test. Use JavaScript 1.6's | |||
|
169 | # **filter**, if it exists. | |||
|
170 | _.filter = (obj, iterator, context) -> | |||
|
171 | return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter | |||
|
172 | results = [] | |||
|
173 | _.each obj, (value, index, list) -> | |||
|
174 | results.push value if iterator.call context, value, index, list | |||
|
175 | results | |||
|
176 | ||||
|
177 | ||||
|
178 | # Return all the elements for which a truth test fails. | |||
|
179 | _.reject = (obj, iterator, context) -> | |||
|
180 | results = [] | |||
|
181 | _.each obj, (value, index, list) -> | |||
|
182 | results.push value if not iterator.call context, value, index, list | |||
|
183 | results | |||
|
184 | ||||
|
185 | ||||
|
186 | # Determine whether all of the elements match a truth test. Delegate to | |||
|
187 | # JavaScript 1.6's **every**, if it is present. | |||
|
188 | _.every = (obj, iterator, context) -> | |||
|
189 | iterator ||= _.identity | |||
|
190 | return obj.every iterator, context if nativeEvery and obj.every is nativeEvery | |||
|
191 | result = true | |||
|
192 | _.each obj, (value, index, list) -> | |||
|
193 | _.breakLoop() unless (result = result and iterator.call(context, value, index, list)) | |||
|
194 | result | |||
|
195 | ||||
|
196 | ||||
|
197 | # Determine if at least one element in the object matches a truth test. Use | |||
|
198 | # JavaScript 1.6's **some**, if it exists. | |||
|
199 | _.some = (obj, iterator, context) -> | |||
|
200 | iterator ||= _.identity | |||
|
201 | return obj.some iterator, context if nativeSome and obj.some is nativeSome | |||
|
202 | result = false | |||
|
203 | _.each obj, (value, index, list) -> | |||
|
204 | _.breakLoop() if (result = iterator.call(context, value, index, list)) | |||
|
205 | result | |||
|
206 | ||||
|
207 | ||||
|
208 | # Determine if a given value is included in the array or object, | |||
|
209 | # based on `===`. | |||
|
210 | _.include = (obj, target) -> | |||
|
211 | return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf | |||
|
212 | return true for own key, val of obj when val is target | |||
|
213 | false | |||
|
214 | ||||
|
215 | ||||
|
216 | # Invoke a method with arguments on every item in a collection. | |||
|
217 | _.invoke = (obj, method) -> | |||
|
218 | args = _.rest arguments, 2 | |||
|
219 | (if method then val[method] else val).apply(val, args) for val in obj | |||
|
220 | ||||
|
221 | ||||
|
222 | # Convenience version of a common use case of **map**: fetching a property. | |||
|
223 | _.pluck = (obj, key) -> | |||
|
224 | _.map(obj, (val) -> val[key]) | |||
|
225 | ||||
|
226 | ||||
|
227 | # Return the maximum item or (item-based computation). | |||
|
228 | _.max = (obj, iterator, context) -> | |||
|
229 | return Math.max.apply(Math, obj) if not iterator and _.isArray(obj) | |||
|
230 | result = computed: -Infinity | |||
|
231 | _.each obj, (value, index, list) -> | |||
|
232 | computed = if iterator then iterator.call(context, value, index, list) else value | |||
|
233 | computed >= result.computed and (result = {value: value, computed: computed}) | |||
|
234 | result.value | |||
|
235 | ||||
|
236 | ||||
|
237 | # Return the minimum element (or element-based computation). | |||
|
238 | _.min = (obj, iterator, context) -> | |||
|
239 | return Math.min.apply(Math, obj) if not iterator and _.isArray(obj) | |||
|
240 | result = computed: Infinity | |||
|
241 | _.each obj, (value, index, list) -> | |||
|
242 | computed = if iterator then iterator.call(context, value, index, list) else value | |||
|
243 | computed < result.computed and (result = {value: value, computed: computed}) | |||
|
244 | result.value | |||
|
245 | ||||
|
246 | ||||
|
247 | # Sort the object's values by a criterion produced by an iterator. | |||
|
248 | _.sortBy = (obj, iterator, context) -> | |||
|
249 | _.pluck(((_.map obj, (value, index, list) -> | |||
|
250 | {value: value, criteria: iterator.call(context, value, index, list)} | |||
|
251 | ).sort((left, right) -> | |||
|
252 | a = left.criteria; b = right.criteria | |||
|
253 | if a < b then -1 else if a > b then 1 else 0 | |||
|
254 | )), 'value') | |||
|
255 | ||||
|
256 | ||||
|
257 | # Use a comparator function to figure out at what index an object should | |||
|
258 | # be inserted so as to maintain order. Uses binary search. | |||
|
259 | _.sortedIndex = (array, obj, iterator) -> | |||
|
260 | iterator ||= _.identity | |||
|
261 | low = 0 | |||
|
262 | high = array.length | |||
|
263 | while low < high | |||
|
264 | mid = (low + high) >> 1 | |||
|
265 | if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid | |||
|
266 | low | |||
|
267 | ||||
|
268 | ||||
|
269 | # Convert anything iterable into a real, live array. | |||
|
270 | _.toArray = (iterable) -> | |||
|
271 | return [] if (!iterable) | |||
|
272 | return iterable.toArray() if (iterable.toArray) | |||
|
273 | return iterable if (_.isArray(iterable)) | |||
|
274 | return slice.call(iterable) if (_.isArguments(iterable)) | |||
|
275 | _.values(iterable) | |||
|
276 | ||||
|
277 | ||||
|
278 | # Return the number of elements in an object. | |||
|
279 | _.size = (obj) -> _.toArray(obj).length | |||
|
280 | ||||
|
281 | ||||
|
282 | # Array Functions | |||
|
283 | # --------------- | |||
|
284 | ||||
|
285 | # Get the first element of an array. Passing `n` will return the first N | |||
|
286 | # values in the array. Aliased as **head**. The `guard` check allows it to work | |||
|
287 | # with **map**. | |||
|
288 | _.first = (array, n, guard) -> | |||
|
289 | if n and not guard then slice.call(array, 0, n) else array[0] | |||
|
290 | ||||
|
291 | ||||
|
292 | # Returns everything but the first entry of the array. Aliased as **tail**. | |||
|
293 | # Especially useful on the arguments object. Passing an `index` will return | |||
|
294 | # the rest of the values in the array from that index onward. The `guard` | |||
|
295 | # check allows it to work with **map**. | |||
|
296 | _.rest = (array, index, guard) -> | |||
|
297 | slice.call(array, if _.isUndefined(index) or guard then 1 else index) | |||
|
298 | ||||
|
299 | ||||
|
300 | # Get the last element of an array. | |||
|
301 | _.last = (array) -> array[array.length - 1] | |||
|
302 | ||||
|
303 | ||||
|
304 | # Trim out all falsy values from an array. | |||
|
305 | _.compact = (array) -> item for item in array when item | |||
|
306 | ||||
|
307 | ||||
|
308 | # Return a completely flattened version of an array. | |||
|
309 | _.flatten = (array) -> | |||
|
310 | _.reduce array, (memo, value) -> | |||
|
311 | return memo.concat(_.flatten(value)) if _.isArray value | |||
|
312 | memo.push value | |||
|
313 | memo | |||
|
314 | , [] | |||
|
315 | ||||
|
316 | ||||
|
317 | # Return a version of the array that does not contain the specified value(s). | |||
|
318 | _.without = (array) -> | |||
|
319 | values = _.rest arguments | |||
|
320 | val for val in _.toArray(array) when not _.include values, val | |||
|
321 | ||||
|
322 | ||||
|
323 | # Produce a duplicate-free version of the array. If the array has already | |||
|
324 | # been sorted, you have the option of using a faster algorithm. | |||
|
325 | _.uniq = (array, isSorted) -> | |||
|
326 | memo = [] | |||
|
327 | for el, i in _.toArray array | |||
|
328 | memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el)) | |||
|
329 | memo | |||
|
330 | ||||
|
331 | ||||
|
332 | # Produce an array that contains every item shared between all the | |||
|
333 | # passed-in arrays. | |||
|
334 | _.intersect = (array) -> | |||
|
335 | rest = _.rest arguments | |||
|
336 | _.select _.uniq(array), (item) -> | |||
|
337 | _.all rest, (other) -> | |||
|
338 | _.indexOf(other, item) >= 0 | |||
|
339 | ||||
|
340 | ||||
|
341 | # Zip together multiple lists into a single array -- elements that share | |||
|
342 | # an index go together. | |||
|
343 | _.zip = -> | |||
|
344 | length = _.max _.pluck arguments, 'length' | |||
|
345 | results = new Array length | |||
|
346 | for i in [0...length] | |||
|
347 | results[i] = _.pluck arguments, String i | |||
|
348 | results | |||
|
349 | ||||
|
350 | ||||
|
351 | # If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE), | |||
|
352 | # we need this function. Return the position of the first occurrence of an | |||
|
353 | # item in an array, or -1 if the item is not included in the array. | |||
|
354 | _.indexOf = (array, item) -> | |||
|
355 | return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf | |||
|
356 | i = 0; l = array.length | |||
|
357 | while l - i | |||
|
358 | if array[i] is item then return i else i++ | |||
|
359 | -1 | |||
|
360 | ||||
|
361 | ||||
|
362 | # Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function, | |||
|
363 | # if possible. | |||
|
364 | _.lastIndexOf = (array, item) -> | |||
|
365 | return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf | |||
|
366 | i = array.length | |||
|
367 | while i | |||
|
368 | if array[i] is item then return i else i-- | |||
|
369 | -1 | |||
|
370 | ||||
|
371 | ||||
|
372 | # Generate an integer Array containing an arithmetic progression. A port of | |||
|
373 | # [the native Python **range** function](http://docs.python.org/library/functions.html#range). | |||
|
374 | _.range = (start, stop, step) -> | |||
|
375 | a = arguments | |||
|
376 | solo = a.length <= 1 | |||
|
377 | i = start = if solo then 0 else a[0] | |||
|
378 | stop = if solo then a[0] else a[1] | |||
|
379 | step = a[2] or 1 | |||
|
380 | len = Math.ceil((stop - start) / step) | |||
|
381 | return [] if len <= 0 | |||
|
382 | range = new Array len | |||
|
383 | idx = 0 | |||
|
384 | loop | |||
|
385 | return range if (if step > 0 then i - stop else stop - i) >= 0 | |||
|
386 | range[idx] = i | |||
|
387 | idx++ | |||
|
388 | i+= step | |||
|
389 | ||||
|
390 | ||||
|
391 | # Function Functions | |||
|
392 | # ------------------ | |||
|
393 | ||||
|
394 | # Create a function bound to a given object (assigning `this`, and arguments, | |||
|
395 | # optionally). Binding with arguments is also known as **curry**. | |||
|
396 | _.bind = (func, obj) -> | |||
|
397 | args = _.rest arguments, 2 | |||
|
398 | -> func.apply obj or root, args.concat arguments | |||
|
399 | ||||
|
400 | ||||
|
401 | # Bind all of an object's methods to that object. Useful for ensuring that | |||
|
402 | # all callbacks defined on an object belong to it. | |||
|
403 | _.bindAll = (obj) -> | |||
|
404 | funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj) | |||
|
405 | _.each funcs, (f) -> obj[f] = _.bind obj[f], obj | |||
|
406 | obj | |||
|
407 | ||||
|
408 | ||||
|
409 | # Delays a function for the given number of milliseconds, and then calls | |||
|
410 | # it with the arguments supplied. | |||
|
411 | _.delay = (func, wait) -> | |||
|
412 | args = _.rest arguments, 2 | |||
|
413 | setTimeout((-> func.apply(func, args)), wait) | |||
|
414 | ||||
|
415 | ||||
|
416 | # Memoize an expensive function by storing its results. | |||
|
417 | _.memoize = (func, hasher) -> | |||
|
418 | memo = {} | |||
|
419 | hasher or= _.identity | |||
|
420 | -> | |||
|
421 | key = hasher.apply this, arguments | |||
|
422 | return memo[key] if key of memo | |||
|
423 | memo[key] = func.apply this, arguments | |||
|
424 | ||||
|
425 | ||||
|
426 | # Defers a function, scheduling it to run after the current call stack has | |||
|
427 | # cleared. | |||
|
428 | _.defer = (func) -> | |||
|
429 | _.delay.apply _, [func, 1].concat _.rest arguments | |||
|
430 | ||||
|
431 | ||||
|
432 | # Returns the first function passed as an argument to the second, | |||
|
433 | # allowing you to adjust arguments, run code before and after, and | |||
|
434 | # conditionally execute the original function. | |||
|
435 | _.wrap = (func, wrapper) -> | |||
|
436 | -> wrapper.apply wrapper, [func].concat arguments | |||
|
437 | ||||
|
438 | ||||
|
439 | # Returns a function that is the composition of a list of functions, each | |||
|
440 | # consuming the return value of the function that follows. | |||
|
441 | _.compose = -> | |||
|
442 | funcs = arguments | |||
|
443 | -> | |||
|
444 | args = arguments | |||
|
445 | for i in [funcs.length - 1..0] by -1 | |||
|
446 | args = [funcs[i].apply(this, args)] | |||
|
447 | args[0] | |||
|
448 | ||||
|
449 | ||||
|
450 | # Object Functions | |||
|
451 | # ---------------- | |||
|
452 | ||||
|
453 | # Retrieve the names of an object's properties. | |||
|
454 | _.keys = nativeKeys or (obj) -> | |||
|
455 | return _.range 0, obj.length if _.isArray(obj) | |||
|
456 | key for key, val of obj | |||
|
457 | ||||
|
458 | ||||
|
459 | # Retrieve the values of an object's properties. | |||
|
460 | _.values = (obj) -> | |||
|
461 | _.map obj, _.identity | |||
|
462 | ||||
|
463 | ||||
|
464 | # Return a sorted list of the function names available in Underscore. | |||
|
465 | _.functions = (obj) -> | |||
|
466 | _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort() | |||
|
467 | ||||
|
468 | ||||
|
469 | # Extend a given object with all of the properties in a source object. | |||
|
470 | _.extend = (obj) -> | |||
|
471 | for source in _.rest(arguments) | |||
|
472 | obj[key] = val for key, val of source | |||
|
473 | obj | |||
|
474 | ||||
|
475 | ||||
|
476 | # Create a (shallow-cloned) duplicate of an object. | |||
|
477 | _.clone = (obj) -> | |||
|
478 | return obj.slice 0 if _.isArray obj | |||
|
479 | _.extend {}, obj | |||
|
480 | ||||
|
481 | ||||
|
482 | # Invokes interceptor with the obj, and then returns obj. | |||
|
483 | # The primary purpose of this method is to "tap into" a method chain, | |||
|
484 | # in order to perform operations on intermediate results within | |||
|
485 | the chain. | |||
|
486 | _.tap = (obj, interceptor) -> | |||
|
487 | interceptor obj | |||
|
488 | obj | |||
|
489 | ||||
|
490 | ||||
|
491 | # Perform a deep comparison to check if two objects are equal. | |||
|
492 | _.isEqual = (a, b) -> | |||
|
493 | # Check object identity. | |||
|
494 | return true if a is b | |||
|
495 | # Different types? | |||
|
496 | atype = typeof(a); btype = typeof(b) | |||
|
497 | return false if atype isnt btype | |||
|
498 | # Basic equality test (watch out for coercions). | |||
|
499 | return true if `a == b` | |||
|
500 | # One is falsy and the other truthy. | |||
|
501 | return false if (!a and b) or (a and !b) | |||
|
502 | # One of them implements an `isEqual()`? | |||
|
503 | return a.isEqual(b) if a.isEqual | |||
|
504 | # Check dates' integer values. | |||
|
505 | return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b) | |||
|
506 | # Both are NaN? | |||
|
507 | return false if _.isNaN(a) and _.isNaN(b) | |||
|
508 | # Compare regular expressions. | |||
|
509 | if _.isRegExp(a) and _.isRegExp(b) | |||
|
510 | return a.source is b.source and | |||
|
511 | a.global is b.global and | |||
|
512 | a.ignoreCase is b.ignoreCase and | |||
|
513 | a.multiline is b.multiline | |||
|
514 | # If a is not an object by this point, we can't handle it. | |||
|
515 | return false if atype isnt 'object' | |||
|
516 | # Check for different array lengths before comparing contents. | |||
|
517 | return false if a.length and (a.length isnt b.length) | |||
|
518 | # Nothing else worked, deep compare the contents. | |||
|
519 | aKeys = _.keys(a); bKeys = _.keys(b) | |||
|
520 | # Different object sizes? | |||
|
521 | return false if aKeys.length isnt bKeys.length | |||
|
522 | # Recursive comparison of contents. | |||
|
523 | return false for key, val of a when !(key of b) or !_.isEqual(val, b[key]) | |||
|
524 | true | |||
|
525 | ||||
|
526 | ||||
|
527 | # Is a given array or object empty? | |||
|
528 | _.isEmpty = (obj) -> | |||
|
529 | return obj.length is 0 if _.isArray(obj) or _.isString(obj) | |||
|
530 | return false for own key of obj | |||
|
531 | true | |||
|
532 | ||||
|
533 | ||||
|
534 | # Is a given value a DOM element? | |||
|
535 | _.isElement = (obj) -> obj and obj.nodeType is 1 | |||
|
536 | ||||
|
537 | ||||
|
538 | # Is a given value an array? | |||
|
539 | _.isArray = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee) | |||
|
540 | ||||
|
541 | ||||
|
542 | # Is a given variable an arguments object? | |||
|
543 | _.isArguments = (obj) -> obj and obj.callee | |||
|
544 | ||||
|
545 | ||||
|
546 | # Is the given value a function? | |||
|
547 | _.isFunction = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply) | |||
|
548 | ||||
|
549 | ||||
|
550 | # Is the given value a string? | |||
|
551 | _.isString = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr)) | |||
|
552 | ||||
|
553 | ||||
|
554 | # Is a given value a number? | |||
|
555 | _.isNumber = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]' | |||
|
556 | ||||
|
557 | ||||
|
558 | # Is a given value a boolean? | |||
|
559 | _.isBoolean = (obj) -> obj is true or obj is false | |||
|
560 | ||||
|
561 | ||||
|
562 | # Is a given value a Date? | |||
|
563 | _.isDate = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear) | |||
|
564 | ||||
|
565 | ||||
|
566 | # Is the given value a regular expression? | |||
|
567 | _.isRegExp = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false)) | |||
|
568 | ||||
|
569 | ||||
|
570 | # Is the given value NaN -- this one is interesting. `NaN != NaN`, and | |||
|
571 | # `isNaN(undefined) == true`, so we make sure it's a number first. | |||
|
572 | _.isNaN = (obj) -> _.isNumber(obj) and window.isNaN(obj) | |||
|
573 | ||||
|
574 | ||||
|
575 | # Is a given value equal to null? | |||
|
576 | _.isNull = (obj) -> obj is null | |||
|
577 | ||||
|
578 | ||||
|
579 | # Is a given variable undefined? | |||
|
580 | _.isUndefined = (obj) -> typeof obj is 'undefined' | |||
|
581 | ||||
|
582 | ||||
|
583 | # Utility Functions | |||
|
584 | # ----------------- | |||
|
585 | ||||
|
586 | # Run Underscore.js in noConflict mode, returning the `_` variable to its | |||
|
587 | # previous owner. Returns a reference to the Underscore object. | |||
|
588 | _.noConflict = -> | |||
|
589 | root._ = previousUnderscore | |||
|
590 | this | |||
|
591 | ||||
|
592 | ||||
|
593 | # Keep the identity function around for default iterators. | |||
|
594 | _.identity = (value) -> value | |||
|
595 | ||||
|
596 | ||||
|
597 | # Run a function `n` times. | |||
|
598 | _.times = (n, iterator, context) -> | |||
|
599 | iterator.call context, i for i in [0...n] | |||
|
600 | ||||
|
601 | ||||
|
602 | # Break out of the middle of an iteration. | |||
|
603 | _.breakLoop = -> throw breaker | |||
|
604 | ||||
|
605 | ||||
|
606 | # Add your own custom functions to the Underscore object, ensuring that | |||
|
607 | # they're correctly added to the OOP wrapper as well. | |||
|
608 | _.mixin = (obj) -> | |||
|
609 | for name in _.functions(obj) | |||
|
610 | addToWrapper name, _[name] = obj[name] | |||
|
611 | ||||
|
612 | ||||
|
613 | # Generate a unique integer id (unique within the entire client session). | |||
|
614 | # Useful for temporary DOM ids. | |||
|
615 | idCounter = 0 | |||
|
616 | _.uniqueId = (prefix) -> | |||
|
617 | (prefix or '') + idCounter++ | |||
|
618 | ||||
|
619 | ||||
|
620 | # By default, Underscore uses **ERB**-style template delimiters, change the | |||
|
621 | # following template settings to use alternative delimiters. | |||
|
622 | _.templateSettings = { | |||
|
623 | start: '<%' | |||
|
624 | end: '%>' | |||
|
625 | interpolate: /<%=(.+?)%>/g | |||
|
626 | } | |||
|
627 | ||||
|
628 | ||||
|
629 | # JavaScript templating a-la **ERB**, pilfered from John Resig's | |||
|
630 | # *Secrets of the JavaScript Ninja*, page 83. | |||
|
631 | # Single-quote fix from Rick Strahl. | |||
|
632 | # With alterations for arbitrary delimiters, and to preserve whitespace. | |||
|
633 | _.template = (str, data) -> | |||
|
634 | c = _.templateSettings | |||
|
635 | endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g") | |||
|
636 | fn = new Function 'obj', | |||
|
637 | 'var p=[],print=function(){p.push.apply(p,arguments);};' + | |||
|
638 | 'with(obj||{}){p.push(\'' + | |||
|
639 | str.replace(/\r/g, '\\r') | |||
|
640 | .replace(/\n/g, '\\n') | |||
|
641 | .replace(/\t/g, '\\t') | |||
|
642 | .replace(endMatch,"���") | |||
|
643 | .split("'").join("\\'") | |||
|
644 | .split("���").join("'") | |||
|
645 | .replace(c.interpolate, "',$1,'") | |||
|
646 | .split(c.start).join("');") | |||
|
647 | .split(c.end).join("p.push('") + | |||
|
648 | "');}return p.join('');" | |||
|
649 | if data then fn(data) else fn | |||
|
650 | ||||
|
651 | ||||
|
652 | # Aliases | |||
|
653 | # ------- | |||
|
654 | ||||
|
655 | _.forEach = _.each | |||
|
656 | _.foldl = _.inject = _.reduce | |||
|
657 | _.foldr = _.reduceRight | |||
|
658 | _.select = _.filter | |||
|
659 | _.all = _.every | |||
|
660 | _.any = _.some | |||
|
661 | _.contains = _.include | |||
|
662 | _.head = _.first | |||
|
663 | _.tail = _.rest | |||
|
664 | _.methods = _.functions | |||
|
665 | ||||
|
666 | ||||
|
667 | # Setup the OOP Wrapper | |||
|
668 | # --------------------- | |||
|
669 | ||||
|
670 | # If Underscore is called as a function, it returns a wrapped object that | |||
|
671 | # can be used OO-style. This wrapper holds altered versions of all the | |||
|
672 | # underscore functions. Wrapped objects may be chained. | |||
|
673 | wrapper = (obj) -> | |||
|
674 | this._wrapped = obj | |||
|
675 | this | |||
|
676 | ||||
|
677 | ||||
|
678 | # Helper function to continue chaining intermediate results. | |||
|
679 | result = (obj, chain) -> | |||
|
680 | if chain then _(obj).chain() else obj | |||
|
681 | ||||
|
682 | ||||
|
683 | # A method to easily add functions to the OOP wrapper. | |||
|
684 | addToWrapper = (name, func) -> | |||
|
685 | wrapper.prototype[name] = -> | |||
|
686 | args = _.toArray arguments | |||
|
687 | unshift.call args, this._wrapped | |||
|
688 | result func.apply(_, args), this._chain | |||
|
689 | ||||
|
690 | ||||
|
691 | # Add all ofthe Underscore functions to the wrapper object. | |||
|
692 | _.mixin _ | |||
|
693 | ||||
|
694 | ||||
|
695 | # Add all mutator Array functions to the wrapper. | |||
|
696 | _.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) -> | |||
|
697 | method = Array.prototype[name] | |||
|
698 | wrapper.prototype[name] = -> | |||
|
699 | method.apply(this._wrapped, arguments) | |||
|
700 | result(this._wrapped, this._chain) | |||
|
701 | ||||
|
702 | ||||
|
703 | # Add all accessor Array functions to the wrapper. | |||
|
704 | _.each ['concat', 'join', 'slice'], (name) -> | |||
|
705 | method = Array.prototype[name] | |||
|
706 | wrapper.prototype[name] = -> | |||
|
707 | result(method.apply(this._wrapped, arguments), this._chain) | |||
|
708 | ||||
|
709 | ||||
|
710 | # Start chaining a wrapped Underscore object. | |||
|
711 | wrapper::chain = -> | |||
|
712 | this._chain = true | |||
|
713 | this | |||
|
714 | ||||
|
715 | ||||
|
716 | # Extracts the result from a wrapped and chained object. | |||
|
717 | wrapper::value = -> this._wrapped | |||
|
718 | </textarea></form> | |||
|
719 | <script> | |||
|
720 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | |||
|
721 | </script> | |||
|
722 | ||||
|
723 | <p><strong>MIME types defined:</strong> <code>text/x-coffeescript</code>.</p> | |||
|
724 | ||||
|
725 | <p>The CoffeeScript mode was written by Jeff Pickhardt (<a href="LICENSE">license</a>).</p> | |||
|
726 | ||||
|
727 | </body> | |||
|
728 | </html> |
@@ -0,0 +1,105 b'' | |||||
|
1 | CodeMirror.defineMode("commonlisp", function (config) { | |||
|
2 | var assumeBody = /^with|^def|^do|^prog|case$|^cond$|bind$|when$|unless$/; | |||
|
3 | var numLiteral = /^(?:[+\-]?(?:\d+|\d*\.\d+)(?:[efd][+\-]?\d+)?|[+\-]?\d+(?:\/[+\-]?\d+)?|#b[+\-]?[01]+|#o[+\-]?[0-7]+|#x[+\-]?[\da-f]+)/; | |||
|
4 | var symbol = /[^\s'`,@()\[\]";]/; | |||
|
5 | var type; | |||
|
6 | ||||
|
7 | function readSym(stream) { | |||
|
8 | var ch; | |||
|
9 | while (ch = stream.next()) { | |||
|
10 | if (ch == "\\") stream.next(); | |||
|
11 | else if (!symbol.test(ch)) { stream.backUp(1); break; } | |||
|
12 | } | |||
|
13 | return stream.current(); | |||
|
14 | } | |||
|
15 | ||||
|
16 | function base(stream, state) { | |||
|
17 | if (stream.eatSpace()) {type = "ws"; return null;} | |||
|
18 | if (stream.match(numLiteral)) return "number"; | |||
|
19 | var ch = stream.next(); | |||
|
20 | if (ch == "\\") ch = stream.next(); | |||
|
21 | ||||
|
22 | if (ch == '"') return (state.tokenize = inString)(stream, state); | |||
|
23 | else if (ch == "(") { type = "open"; return "bracket"; } | |||
|
24 | else if (ch == ")" || ch == "]") { type = "close"; return "bracket"; } | |||
|
25 | else if (ch == ";") { stream.skipToEnd(); type = "ws"; return "comment"; } | |||
|
26 | else if (/['`,@]/.test(ch)) return null; | |||
|
27 | else if (ch == "|") { | |||
|
28 | if (stream.skipTo("|")) { stream.next(); return "symbol"; } | |||
|
29 | else { stream.skipToEnd(); return "error"; } | |||
|
30 | } else if (ch == "#") { | |||
|
31 | var ch = stream.next(); | |||
|
32 | if (ch == "[") { type = "open"; return "bracket"; } | |||
|
33 | else if (/[+\-=\.']/.test(ch)) return null; | |||
|
34 | else if (/\d/.test(ch) && stream.match(/^\d*#/)) return null; | |||
|
35 | else if (ch == "|") return (state.tokenize = inComment)(stream, state); | |||
|
36 | else if (ch == ":") { readSym(stream); return "meta"; } | |||
|
37 | else return "error"; | |||
|
38 | } else { | |||
|
39 | var name = readSym(stream); | |||
|
40 | if (name == ".") return null; | |||
|
41 | type = "symbol"; | |||
|
42 | if (name == "nil" || name == "t") return "atom"; | |||
|
43 | if (name.charAt(0) == ":") return "keyword"; | |||
|
44 | if (name.charAt(0) == "&") return "variable-2"; | |||
|
45 | return "variable"; | |||
|
46 | } | |||
|
47 | } | |||
|
48 | ||||
|
49 | function inString(stream, state) { | |||
|
50 | var escaped = false, next; | |||
|
51 | while (next = stream.next()) { | |||
|
52 | if (next == '"' && !escaped) { state.tokenize = base; break; } | |||
|
53 | escaped = !escaped && next == "\\"; | |||
|
54 | } | |||
|
55 | return "string"; | |||
|
56 | } | |||
|
57 | ||||
|
58 | function inComment(stream, state) { | |||
|
59 | var next, last; | |||
|
60 | while (next = stream.next()) { | |||
|
61 | if (next == "#" && last == "|") { state.tokenize = base; break; } | |||
|
62 | last = next; | |||
|
63 | } | |||
|
64 | type = "ws"; | |||
|
65 | return "comment"; | |||
|
66 | } | |||
|
67 | ||||
|
68 | return { | |||
|
69 | startState: function () { | |||
|
70 | return {ctx: {prev: null, start: 0, indentTo: 0}, tokenize: base}; | |||
|
71 | }, | |||
|
72 | ||||
|
73 | token: function (stream, state) { | |||
|
74 | if (stream.sol() && typeof state.ctx.indentTo != "number") | |||
|
75 | state.ctx.indentTo = state.ctx.start + 1; | |||
|
76 | ||||
|
77 | type = null; | |||
|
78 | var style = state.tokenize(stream, state); | |||
|
79 | if (type != "ws") { | |||
|
80 | if (state.ctx.indentTo == null) { | |||
|
81 | if (type == "symbol" && assumeBody.test(stream.current())) | |||
|
82 | state.ctx.indentTo = state.ctx.start + config.indentUnit; | |||
|
83 | else | |||
|
84 | state.ctx.indentTo = "next"; | |||
|
85 | } else if (state.ctx.indentTo == "next") { | |||
|
86 | state.ctx.indentTo = stream.column(); | |||
|
87 | } | |||
|
88 | } | |||
|
89 | if (type == "open") state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null}; | |||
|
90 | else if (type == "close") state.ctx = state.ctx.prev || state.ctx; | |||
|
91 | return style; | |||
|
92 | }, | |||
|
93 | ||||
|
94 | indent: function (state, _textAfter) { | |||
|
95 | var i = state.ctx.indentTo; | |||
|
96 | return typeof i == "number" ? i : state.ctx.start + 1; | |||
|
97 | }, | |||
|
98 | ||||
|
99 | lineComment: ";;", | |||
|
100 | blockCommentStart: "#|", | |||
|
101 | blockCommentEnd: "|#" | |||
|
102 | }; | |||
|
103 | }); | |||
|
104 | ||||
|
105 | CodeMirror.defineMIME("text/x-common-lisp", "commonlisp"); |
@@ -0,0 +1,165 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Common Lisp mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="commonlisp.js"></script> | |||
|
9 | <style>.CodeMirror {background: #f8f8f8;}</style> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Common Lisp mode</h1> | |||
|
14 | <form><textarea id="code" name="code">(in-package :cl-postgres) | |||
|
15 | ||||
|
16 | ;; These are used to synthesize reader and writer names for integer | |||
|
17 | ;; reading/writing functions when the amount of bytes and the | |||
|
18 | ;; signedness is known. Both the macro that creates the functions and | |||
|
19 | ;; some macros that use them create names this way. | |||
|
20 | (eval-when (:compile-toplevel :load-toplevel :execute) | |||
|
21 | (defun integer-reader-name (bytes signed) | |||
|
22 | (intern (with-standard-io-syntax | |||
|
23 | (format nil "~a~a~a~a" '#:read- (if signed "" '#:u) '#:int bytes)))) | |||
|
24 | (defun integer-writer-name (bytes signed) | |||
|
25 | (intern (with-standard-io-syntax | |||
|
26 | (format nil "~a~a~a~a" '#:write- (if signed "" '#:u) '#:int bytes))))) | |||
|
27 | ||||
|
28 | (defmacro integer-reader (bytes) | |||
|
29 | "Create a function to read integers from a binary stream." | |||
|
30 | (let ((bits (* bytes 8))) | |||
|
31 | (labels ((return-form (signed) | |||
|
32 | (if signed | |||
|
33 | `(if (logbitp ,(1- bits) result) | |||
|
34 | (dpb result (byte ,(1- bits) 0) -1) | |||
|
35 | result) | |||
|
36 | `result)) | |||
|
37 | (generate-reader (signed) | |||
|
38 | `(defun ,(integer-reader-name bytes signed) (socket) | |||
|
39 | (declare (type stream socket) | |||
|
40 | #.*optimize*) | |||
|
41 | ,(if (= bytes 1) | |||
|
42 | `(let ((result (the (unsigned-byte 8) (read-byte socket)))) | |||
|
43 | (declare (type (unsigned-byte 8) result)) | |||
|
44 | ,(return-form signed)) | |||
|
45 | `(let ((result 0)) | |||
|
46 | (declare (type (unsigned-byte ,bits) result)) | |||
|
47 | ,@(loop :for byte :from (1- bytes) :downto 0 | |||
|
48 | :collect `(setf (ldb (byte 8 ,(* 8 byte)) result) | |||
|
49 | (the (unsigned-byte 8) (read-byte socket)))) | |||
|
50 | ,(return-form signed)))))) | |||
|
51 | `(progn | |||
|
52 | ;; This causes weird errors on SBCL in some circumstances. Disabled for now. | |||
|
53 | ;; (declaim (inline ,(integer-reader-name bytes t) | |||
|
54 | ;; ,(integer-reader-name bytes nil))) | |||
|
55 | (declaim (ftype (function (t) (signed-byte ,bits)) | |||
|
56 | ,(integer-reader-name bytes t))) | |||
|
57 | ,(generate-reader t) | |||
|
58 | (declaim (ftype (function (t) (unsigned-byte ,bits)) | |||
|
59 | ,(integer-reader-name bytes nil))) | |||
|
60 | ,(generate-reader nil))))) | |||
|
61 | ||||
|
62 | (defmacro integer-writer (bytes) | |||
|
63 | "Create a function to write integers to a binary stream." | |||
|
64 | (let ((bits (* 8 bytes))) | |||
|
65 | `(progn | |||
|
66 | (declaim (inline ,(integer-writer-name bytes t) | |||
|
67 | ,(integer-writer-name bytes nil))) | |||
|
68 | (defun ,(integer-writer-name bytes nil) (socket value) | |||
|
69 | (declare (type stream socket) | |||
|
70 | (type (unsigned-byte ,bits) value) | |||
|
71 | #.*optimize*) | |||
|
72 | ,@(if (= bytes 1) | |||
|
73 | `((write-byte value socket)) | |||
|
74 | (loop :for byte :from (1- bytes) :downto 0 | |||
|
75 | :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value) | |||
|
76 | socket))) | |||
|
77 | (values)) | |||
|
78 | (defun ,(integer-writer-name bytes t) (socket value) | |||
|
79 | (declare (type stream socket) | |||
|
80 | (type (signed-byte ,bits) value) | |||
|
81 | #.*optimize*) | |||
|
82 | ,@(if (= bytes 1) | |||
|
83 | `((write-byte (ldb (byte 8 0) value) socket)) | |||
|
84 | (loop :for byte :from (1- bytes) :downto 0 | |||
|
85 | :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value) | |||
|
86 | socket))) | |||
|
87 | (values))))) | |||
|
88 | ||||
|
89 | ;; All the instances of the above that we need. | |||
|
90 | ||||
|
91 | (integer-reader 1) | |||
|
92 | (integer-reader 2) | |||
|
93 | (integer-reader 4) | |||
|
94 | (integer-reader 8) | |||
|
95 | ||||
|
96 | (integer-writer 1) | |||
|
97 | (integer-writer 2) | |||
|
98 | (integer-writer 4) | |||
|
99 | ||||
|
100 | (defun write-bytes (socket bytes) | |||
|
101 | "Write a byte-array to a stream." | |||
|
102 | (declare (type stream socket) | |||
|
103 | (type (simple-array (unsigned-byte 8)) bytes) | |||
|
104 | #.*optimize*) | |||
|
105 | (write-sequence bytes socket)) | |||
|
106 | ||||
|
107 | (defun write-str (socket string) | |||
|
108 | "Write a null-terminated string to a stream \(encoding it when UTF-8 | |||
|
109 | support is enabled.)." | |||
|
110 | (declare (type stream socket) | |||
|
111 | (type string string) | |||
|
112 | #.*optimize*) | |||
|
113 | (enc-write-string string socket) | |||
|
114 | (write-uint1 socket 0)) | |||
|
115 | ||||
|
116 | (declaim (ftype (function (t unsigned-byte) | |||
|
117 | (simple-array (unsigned-byte 8) (*))) | |||
|
118 | read-bytes)) | |||
|
119 | (defun read-bytes (socket length) | |||
|
120 | "Read a byte array of the given length from a stream." | |||
|
121 | (declare (type stream socket) | |||
|
122 | (type fixnum length) | |||
|
123 | #.*optimize*) | |||
|
124 | (let ((result (make-array length :element-type '(unsigned-byte 8)))) | |||
|
125 | (read-sequence result socket) | |||
|
126 | result)) | |||
|
127 | ||||
|
128 | (declaim (ftype (function (t) string) read-str)) | |||
|
129 | (defun read-str (socket) | |||
|
130 | "Read a null-terminated string from a stream. Takes care of encoding | |||
|
131 | when UTF-8 support is enabled." | |||
|
132 | (declare (type stream socket) | |||
|
133 | #.*optimize*) | |||
|
134 | (enc-read-string socket :null-terminated t)) | |||
|
135 | ||||
|
136 | (defun skip-bytes (socket length) | |||
|
137 | "Skip a given number of bytes in a binary stream." | |||
|
138 | (declare (type stream socket) | |||
|
139 | (type (unsigned-byte 32) length) | |||
|
140 | #.*optimize*) | |||
|
141 | (dotimes (i length) | |||
|
142 | (read-byte socket))) | |||
|
143 | ||||
|
144 | (defun skip-str (socket) | |||
|
145 | "Skip a null-terminated string." | |||
|
146 | (declare (type stream socket) | |||
|
147 | #.*optimize*) | |||
|
148 | (loop :for char :of-type fixnum = (read-byte socket) | |||
|
149 | :until (zerop char))) | |||
|
150 | ||||
|
151 | (defun ensure-socket-is-closed (socket &key abort) | |||
|
152 | (when (open-stream-p socket) | |||
|
153 | (handler-case | |||
|
154 | (close socket :abort abort) | |||
|
155 | (error (error) | |||
|
156 | (warn "Ignoring the error which happened while trying to close PostgreSQL socket: ~A" error))))) | |||
|
157 | </textarea></form> | |||
|
158 | <script> | |||
|
159 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {lineNumbers: true}); | |||
|
160 | </script> | |||
|
161 | ||||
|
162 | <p><strong>MIME types defined:</strong> <code>text/x-common-lisp</code>.</p> | |||
|
163 | ||||
|
164 | </body> | |||
|
165 | </html> |
This diff has been collapsed as it changes many lines, (606 lines changed) Show them Hide them | |||||
@@ -0,0 +1,606 b'' | |||||
|
1 | CodeMirror.defineMode("css", function(config) { | |||
|
2 | return CodeMirror.getMode(config, "text/css"); | |||
|
3 | }); | |||
|
4 | ||||
|
5 | CodeMirror.defineMode("css-base", function(config, parserConfig) { | |||
|
6 | "use strict"; | |||
|
7 | ||||
|
8 | var indentUnit = config.indentUnit, | |||
|
9 | hooks = parserConfig.hooks || {}, | |||
|
10 | atMediaTypes = parserConfig.atMediaTypes || {}, | |||
|
11 | atMediaFeatures = parserConfig.atMediaFeatures || {}, | |||
|
12 | propertyKeywords = parserConfig.propertyKeywords || {}, | |||
|
13 | colorKeywords = parserConfig.colorKeywords || {}, | |||
|
14 | valueKeywords = parserConfig.valueKeywords || {}, | |||
|
15 | allowNested = !!parserConfig.allowNested, | |||
|
16 | type = null; | |||
|
17 | ||||
|
18 | function ret(style, tp) { type = tp; return style; } | |||
|
19 | ||||
|
20 | function tokenBase(stream, state) { | |||
|
21 | var ch = stream.next(); | |||
|
22 | if (hooks[ch]) { | |||
|
23 | // result[0] is style and result[1] is type | |||
|
24 | var result = hooks[ch](stream, state); | |||
|
25 | if (result !== false) return result; | |||
|
26 | } | |||
|
27 | if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("def", stream.current());} | |||
|
28 | else if (ch == "=") ret(null, "compare"); | |||
|
29 | else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare"); | |||
|
30 | else if (ch == "\"" || ch == "'") { | |||
|
31 | state.tokenize = tokenString(ch); | |||
|
32 | return state.tokenize(stream, state); | |||
|
33 | } | |||
|
34 | else if (ch == "#") { | |||
|
35 | stream.eatWhile(/[\w\\\-]/); | |||
|
36 | return ret("atom", "hash"); | |||
|
37 | } | |||
|
38 | else if (ch == "!") { | |||
|
39 | stream.match(/^\s*\w*/); | |||
|
40 | return ret("keyword", "important"); | |||
|
41 | } | |||
|
42 | else if (/\d/.test(ch)) { | |||
|
43 | stream.eatWhile(/[\w.%]/); | |||
|
44 | return ret("number", "unit"); | |||
|
45 | } | |||
|
46 | else if (ch === "-") { | |||
|
47 | if (/\d/.test(stream.peek())) { | |||
|
48 | stream.eatWhile(/[\w.%]/); | |||
|
49 | return ret("number", "unit"); | |||
|
50 | } else if (stream.match(/^[^-]+-/)) { | |||
|
51 | return ret("meta", "meta"); | |||
|
52 | } | |||
|
53 | } | |||
|
54 | else if (/[,+>*\/]/.test(ch)) { | |||
|
55 | return ret(null, "select-op"); | |||
|
56 | } | |||
|
57 | else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) { | |||
|
58 | return ret("qualifier", "qualifier"); | |||
|
59 | } | |||
|
60 | else if (ch == ":") { | |||
|
61 | return ret("operator", ch); | |||
|
62 | } | |||
|
63 | else if (/[;{}\[\]\(\)]/.test(ch)) { | |||
|
64 | return ret(null, ch); | |||
|
65 | } | |||
|
66 | else if (ch == "u" && stream.match("rl(")) { | |||
|
67 | stream.backUp(1); | |||
|
68 | state.tokenize = tokenParenthesized; | |||
|
69 | return ret("property", "variable"); | |||
|
70 | } | |||
|
71 | else { | |||
|
72 | stream.eatWhile(/[\w\\\-]/); | |||
|
73 | return ret("property", "variable"); | |||
|
74 | } | |||
|
75 | } | |||
|
76 | ||||
|
77 | function tokenString(quote, nonInclusive) { | |||
|
78 | return function(stream, state) { | |||
|
79 | var escaped = false, ch; | |||
|
80 | while ((ch = stream.next()) != null) { | |||
|
81 | if (ch == quote && !escaped) | |||
|
82 | break; | |||
|
83 | escaped = !escaped && ch == "\\"; | |||
|
84 | } | |||
|
85 | if (!escaped) { | |||
|
86 | if (nonInclusive) stream.backUp(1); | |||
|
87 | state.tokenize = tokenBase; | |||
|
88 | } | |||
|
89 | return ret("string", "string"); | |||
|
90 | }; | |||
|
91 | } | |||
|
92 | ||||
|
93 | function tokenParenthesized(stream, state) { | |||
|
94 | stream.next(); // Must be '(' | |||
|
95 | if (!stream.match(/\s*[\"\']/, false)) | |||
|
96 | state.tokenize = tokenString(")", true); | |||
|
97 | else | |||
|
98 | state.tokenize = tokenBase; | |||
|
99 | return ret(null, "("); | |||
|
100 | } | |||
|
101 | ||||
|
102 | return { | |||
|
103 | startState: function(base) { | |||
|
104 | return {tokenize: tokenBase, | |||
|
105 | baseIndent: base || 0, | |||
|
106 | stack: []}; | |||
|
107 | }, | |||
|
108 | ||||
|
109 | token: function(stream, state) { | |||
|
110 | ||||
|
111 | // Use these terms when applicable (see http://www.xanthir.com/blog/b4E50) | |||
|
112 | // | |||
|
113 | // rule** or **ruleset: | |||
|
114 | // A selector + braces combo, or an at-rule. | |||
|
115 | // | |||
|
116 | // declaration block: | |||
|
117 | // A sequence of declarations. | |||
|
118 | // | |||
|
119 | // declaration: | |||
|
120 | // A property + colon + value combo. | |||
|
121 | // | |||
|
122 | // property value: | |||
|
123 | // The entire value of a property. | |||
|
124 | // | |||
|
125 | // component value: | |||
|
126 | // A single piece of a property value. Like the 5px in | |||
|
127 | // text-shadow: 0 0 5px blue;. Can also refer to things that are | |||
|
128 | // multiple terms, like the 1-4 terms that make up the background-size | |||
|
129 | // portion of the background shorthand. | |||
|
130 | // | |||
|
131 | // term: | |||
|
132 | // The basic unit of author-facing CSS, like a single number (5), | |||
|
133 | // dimension (5px), string ("foo"), or function. Officially defined | |||
|
134 | // by the CSS 2.1 grammar (look for the 'term' production) | |||
|
135 | // | |||
|
136 | // | |||
|
137 | // simple selector: | |||
|
138 | // A single atomic selector, like a type selector, an attr selector, a | |||
|
139 | // class selector, etc. | |||
|
140 | // | |||
|
141 | // compound selector: | |||
|
142 | // One or more simple selectors without a combinator. div.example is | |||
|
143 | // compound, div > .example is not. | |||
|
144 | // | |||
|
145 | // complex selector: | |||
|
146 | // One or more compound selectors chained with combinators. | |||
|
147 | // | |||
|
148 | // combinator: | |||
|
149 | // The parts of selectors that express relationships. There are four | |||
|
150 | // currently - the space (descendant combinator), the greater-than | |||
|
151 | // bracket (child combinator), the plus sign (next sibling combinator), | |||
|
152 | // and the tilda (following sibling combinator). | |||
|
153 | // | |||
|
154 | // sequence of selectors: | |||
|
155 | // One or more of the named type of selector chained with commas. | |||
|
156 | ||||
|
157 | state.tokenize = state.tokenize || tokenBase; | |||
|
158 | if (state.tokenize == tokenBase && stream.eatSpace()) return null; | |||
|
159 | var style = state.tokenize(stream, state); | |||
|
160 | if (style && typeof style != "string") style = ret(style[0], style[1]); | |||
|
161 | ||||
|
162 | // Changing style returned based on context | |||
|
163 | var context = state.stack[state.stack.length-1]; | |||
|
164 | if (style == "variable") { | |||
|
165 | if (type == "variable-definition") state.stack.push("propertyValue"); | |||
|
166 | return "variable-2"; | |||
|
167 | } else if (style == "property") { | |||
|
168 | var word = stream.current().toLowerCase(); | |||
|
169 | if (context == "propertyValue") { | |||
|
170 | if (valueKeywords.hasOwnProperty(word)) { | |||
|
171 | style = "string-2"; | |||
|
172 | } else if (colorKeywords.hasOwnProperty(word)) { | |||
|
173 | style = "keyword"; | |||
|
174 | } else { | |||
|
175 | style = "variable-2"; | |||
|
176 | } | |||
|
177 | } else if (context == "rule") { | |||
|
178 | if (!propertyKeywords.hasOwnProperty(word)) { | |||
|
179 | style += " error"; | |||
|
180 | } | |||
|
181 | } else if (context == "block") { | |||
|
182 | // if a value is present in both property, value, or color, the order | |||
|
183 | // of preference is property -> color -> value | |||
|
184 | if (propertyKeywords.hasOwnProperty(word)) { | |||
|
185 | style = "property"; | |||
|
186 | } else if (colorKeywords.hasOwnProperty(word)) { | |||
|
187 | style = "keyword"; | |||
|
188 | } else if (valueKeywords.hasOwnProperty(word)) { | |||
|
189 | style = "string-2"; | |||
|
190 | } else { | |||
|
191 | style = "tag"; | |||
|
192 | } | |||
|
193 | } else if (!context || context == "@media{") { | |||
|
194 | style = "tag"; | |||
|
195 | } else if (context == "@media") { | |||
|
196 | if (atMediaTypes[stream.current()]) { | |||
|
197 | style = "attribute"; // Known attribute | |||
|
198 | } else if (/^(only|not)$/.test(word)) { | |||
|
199 | style = "keyword"; | |||
|
200 | } else if (word == "and") { | |||
|
201 | style = "error"; // "and" is only allowed in @mediaType | |||
|
202 | } else if (atMediaFeatures.hasOwnProperty(word)) { | |||
|
203 | style = "error"; // Known property, should be in @mediaType( | |||
|
204 | } else { | |||
|
205 | // Unknown, expecting keyword or attribute, assuming attribute | |||
|
206 | style = "attribute error"; | |||
|
207 | } | |||
|
208 | } else if (context == "@mediaType") { | |||
|
209 | if (atMediaTypes.hasOwnProperty(word)) { | |||
|
210 | style = "attribute"; | |||
|
211 | } else if (word == "and") { | |||
|
212 | style = "operator"; | |||
|
213 | } else if (/^(only|not)$/.test(word)) { | |||
|
214 | style = "error"; // Only allowed in @media | |||
|
215 | } else { | |||
|
216 | // Unknown attribute or property, but expecting property (preceded | |||
|
217 | // by "and"). Should be in parentheses | |||
|
218 | style = "error"; | |||
|
219 | } | |||
|
220 | } else if (context == "@mediaType(") { | |||
|
221 | if (propertyKeywords.hasOwnProperty(word)) { | |||
|
222 | // do nothing, remains "property" | |||
|
223 | } else if (atMediaTypes.hasOwnProperty(word)) { | |||
|
224 | style = "error"; // Known property, should be in parentheses | |||
|
225 | } else if (word == "and") { | |||
|
226 | style = "operator"; | |||
|
227 | } else if (/^(only|not)$/.test(word)) { | |||
|
228 | style = "error"; // Only allowed in @media | |||
|
229 | } else { | |||
|
230 | style += " error"; | |||
|
231 | } | |||
|
232 | } else if (context == "@import") { | |||
|
233 | style = "tag"; | |||
|
234 | } else { | |||
|
235 | style = "error"; | |||
|
236 | } | |||
|
237 | } else if (style == "atom") { | |||
|
238 | if(!context || context == "@media{" || context == "block") { | |||
|
239 | style = "builtin"; | |||
|
240 | } else if (context == "propertyValue") { | |||
|
241 | if (!/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) { | |||
|
242 | style += " error"; | |||
|
243 | } | |||
|
244 | } else { | |||
|
245 | style = "error"; | |||
|
246 | } | |||
|
247 | } else if (context == "@media" && type == "{") { | |||
|
248 | style = "error"; | |||
|
249 | } | |||
|
250 | ||||
|
251 | // Push/pop context stack | |||
|
252 | if (type == "{") { | |||
|
253 | if (context == "@media" || context == "@mediaType") { | |||
|
254 | state.stack.pop(); | |||
|
255 | state.stack[state.stack.length-1] = "@media{"; | |||
|
256 | } | |||
|
257 | else { | |||
|
258 | var newContext = allowNested ? "block" : "rule"; | |||
|
259 | state.stack.push(newContext); | |||
|
260 | } | |||
|
261 | } | |||
|
262 | else if (type == "}") { | |||
|
263 | var lastState = state.stack[state.stack.length - 1]; | |||
|
264 | if (lastState == "interpolation") style = "operator"; | |||
|
265 | state.stack.pop(); | |||
|
266 | if (context == "propertyValue") state.stack.pop(); | |||
|
267 | } | |||
|
268 | else if (type == "interpolation") state.stack.push("interpolation"); | |||
|
269 | else if (type == "@media") state.stack.push("@media"); | |||
|
270 | else if (type == "@import") state.stack.push("@import"); | |||
|
271 | else if (context == "@media" && /\b(keyword|attribute)\b/.test(style)) | |||
|
272 | state.stack.push("@mediaType"); | |||
|
273 | else if (context == "@mediaType" && stream.current() == ",") state.stack.pop(); | |||
|
274 | else if (context == "@mediaType" && type == "(") state.stack.push("@mediaType("); | |||
|
275 | else if (context == "@mediaType(" && type == ")") state.stack.pop(); | |||
|
276 | else if ((context == "rule" || context == "block") && type == ":") state.stack.push("propertyValue"); | |||
|
277 | else if (context == "propertyValue" && type == ";") state.stack.pop(); | |||
|
278 | else if (context == "@import" && type == ";") state.stack.pop(); | |||
|
279 | return style; | |||
|
280 | }, | |||
|
281 | ||||
|
282 | indent: function(state, textAfter) { | |||
|
283 | var n = state.stack.length; | |||
|
284 | if (/^\}/.test(textAfter)) | |||
|
285 | n -= state.stack[state.stack.length-1] == "propertyValue" ? 2 : 1; | |||
|
286 | return state.baseIndent + n * indentUnit; | |||
|
287 | }, | |||
|
288 | ||||
|
289 | electricChars: "}", | |||
|
290 | blockCommentStart: "/*", | |||
|
291 | blockCommentEnd: "*/" | |||
|
292 | }; | |||
|
293 | }); | |||
|
294 | ||||
|
295 | (function() { | |||
|
296 | function keySet(array) { | |||
|
297 | var keys = {}; | |||
|
298 | for (var i = 0; i < array.length; ++i) { | |||
|
299 | keys[array[i]] = true; | |||
|
300 | } | |||
|
301 | return keys; | |||
|
302 | } | |||
|
303 | ||||
|
304 | var atMediaTypes = keySet([ | |||
|
305 | "all", "aural", "braille", "handheld", "print", "projection", "screen", | |||
|
306 | "tty", "tv", "embossed" | |||
|
307 | ]); | |||
|
308 | ||||
|
309 | var atMediaFeatures = keySet([ | |||
|
310 | "width", "min-width", "max-width", "height", "min-height", "max-height", | |||
|
311 | "device-width", "min-device-width", "max-device-width", "device-height", | |||
|
312 | "min-device-height", "max-device-height", "aspect-ratio", | |||
|
313 | "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio", | |||
|
314 | "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color", | |||
|
315 | "max-color", "color-index", "min-color-index", "max-color-index", | |||
|
316 | "monochrome", "min-monochrome", "max-monochrome", "resolution", | |||
|
317 | "min-resolution", "max-resolution", "scan", "grid" | |||
|
318 | ]); | |||
|
319 | ||||
|
320 | var propertyKeywords = keySet([ | |||
|
321 | "align-content", "align-items", "align-self", "alignment-adjust", | |||
|
322 | "alignment-baseline", "anchor-point", "animation", "animation-delay", | |||
|
323 | "animation-direction", "animation-duration", "animation-iteration-count", | |||
|
324 | "animation-name", "animation-play-state", "animation-timing-function", | |||
|
325 | "appearance", "azimuth", "backface-visibility", "background", | |||
|
326 | "background-attachment", "background-clip", "background-color", | |||
|
327 | "background-image", "background-origin", "background-position", | |||
|
328 | "background-repeat", "background-size", "baseline-shift", "binding", | |||
|
329 | "bleed", "bookmark-label", "bookmark-level", "bookmark-state", | |||
|
330 | "bookmark-target", "border", "border-bottom", "border-bottom-color", | |||
|
331 | "border-bottom-left-radius", "border-bottom-right-radius", | |||
|
332 | "border-bottom-style", "border-bottom-width", "border-collapse", | |||
|
333 | "border-color", "border-image", "border-image-outset", | |||
|
334 | "border-image-repeat", "border-image-slice", "border-image-source", | |||
|
335 | "border-image-width", "border-left", "border-left-color", | |||
|
336 | "border-left-style", "border-left-width", "border-radius", "border-right", | |||
|
337 | "border-right-color", "border-right-style", "border-right-width", | |||
|
338 | "border-spacing", "border-style", "border-top", "border-top-color", | |||
|
339 | "border-top-left-radius", "border-top-right-radius", "border-top-style", | |||
|
340 | "border-top-width", "border-width", "bottom", "box-decoration-break", | |||
|
341 | "box-shadow", "box-sizing", "break-after", "break-before", "break-inside", | |||
|
342 | "caption-side", "clear", "clip", "color", "color-profile", "column-count", | |||
|
343 | "column-fill", "column-gap", "column-rule", "column-rule-color", | |||
|
344 | "column-rule-style", "column-rule-width", "column-span", "column-width", | |||
|
345 | "columns", "content", "counter-increment", "counter-reset", "crop", "cue", | |||
|
346 | "cue-after", "cue-before", "cursor", "direction", "display", | |||
|
347 | "dominant-baseline", "drop-initial-after-adjust", | |||
|
348 | "drop-initial-after-align", "drop-initial-before-adjust", | |||
|
349 | "drop-initial-before-align", "drop-initial-size", "drop-initial-value", | |||
|
350 | "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis", | |||
|
351 | "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap", | |||
|
352 | "float", "float-offset", "font", "font-feature-settings", "font-family", | |||
|
353 | "font-kerning", "font-language-override", "font-size", "font-size-adjust", | |||
|
354 | "font-stretch", "font-style", "font-synthesis", "font-variant", | |||
|
355 | "font-variant-alternates", "font-variant-caps", "font-variant-east-asian", | |||
|
356 | "font-variant-ligatures", "font-variant-numeric", "font-variant-position", | |||
|
357 | "font-weight", "grid-cell", "grid-column", "grid-column-align", | |||
|
358 | "grid-column-sizing", "grid-column-span", "grid-columns", "grid-flow", | |||
|
359 | "grid-row", "grid-row-align", "grid-row-sizing", "grid-row-span", | |||
|
360 | "grid-rows", "grid-template", "hanging-punctuation", "height", "hyphens", | |||
|
361 | "icon", "image-orientation", "image-rendering", "image-resolution", | |||
|
362 | "inline-box-align", "justify-content", "left", "letter-spacing", | |||
|
363 | "line-break", "line-height", "line-stacking", "line-stacking-ruby", | |||
|
364 | "line-stacking-shift", "line-stacking-strategy", "list-style", | |||
|
365 | "list-style-image", "list-style-position", "list-style-type", "margin", | |||
|
366 | "margin-bottom", "margin-left", "margin-right", "margin-top", | |||
|
367 | "marker-offset", "marks", "marquee-direction", "marquee-loop", | |||
|
368 | "marquee-play-count", "marquee-speed", "marquee-style", "max-height", | |||
|
369 | "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index", | |||
|
370 | "nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline", | |||
|
371 | "outline-color", "outline-offset", "outline-style", "outline-width", | |||
|
372 | "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y", | |||
|
373 | "padding", "padding-bottom", "padding-left", "padding-right", "padding-top", | |||
|
374 | "page", "page-break-after", "page-break-before", "page-break-inside", | |||
|
375 | "page-policy", "pause", "pause-after", "pause-before", "perspective", | |||
|
376 | "perspective-origin", "pitch", "pitch-range", "play-during", "position", | |||
|
377 | "presentation-level", "punctuation-trim", "quotes", "rendering-intent", | |||
|
378 | "resize", "rest", "rest-after", "rest-before", "richness", "right", | |||
|
379 | "rotation", "rotation-point", "ruby-align", "ruby-overhang", | |||
|
380 | "ruby-position", "ruby-span", "size", "speak", "speak-as", "speak-header", | |||
|
381 | "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set", | |||
|
382 | "tab-size", "table-layout", "target", "target-name", "target-new", | |||
|
383 | "target-position", "text-align", "text-align-last", "text-decoration", | |||
|
384 | "text-decoration-color", "text-decoration-line", "text-decoration-skip", | |||
|
385 | "text-decoration-style", "text-emphasis", "text-emphasis-color", | |||
|
386 | "text-emphasis-position", "text-emphasis-style", "text-height", | |||
|
387 | "text-indent", "text-justify", "text-outline", "text-shadow", | |||
|
388 | "text-space-collapse", "text-transform", "text-underline-position", | |||
|
389 | "text-wrap", "top", "transform", "transform-origin", "transform-style", | |||
|
390 | "transition", "transition-delay", "transition-duration", | |||
|
391 | "transition-property", "transition-timing-function", "unicode-bidi", | |||
|
392 | "vertical-align", "visibility", "voice-balance", "voice-duration", | |||
|
393 | "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress", | |||
|
394 | "voice-volume", "volume", "white-space", "widows", "width", "word-break", | |||
|
395 | "word-spacing", "word-wrap", "z-index", | |||
|
396 | // SVG-specific | |||
|
397 | "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color", | |||
|
398 | "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events", | |||
|
399 | "color-interpolation", "color-interpolation-filters", "color-profile", | |||
|
400 | "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering", | |||
|
401 | "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke", | |||
|
402 | "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", | |||
|
403 | "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering", | |||
|
404 | "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal", | |||
|
405 | "glyph-orientation-vertical", "kerning", "text-anchor", "writing-mode" | |||
|
406 | ]); | |||
|
407 | ||||
|
408 | var colorKeywords = keySet([ | |||
|
409 | "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", | |||
|
410 | "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", | |||
|
411 | "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", | |||
|
412 | "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", | |||
|
413 | "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", | |||
|
414 | "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", | |||
|
415 | "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", | |||
|
416 | "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", | |||
|
417 | "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", | |||
|
418 | "gold", "goldenrod", "gray", "green", "greenyellow", "honeydew", | |||
|
419 | "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", | |||
|
420 | "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", | |||
|
421 | "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink", | |||
|
422 | "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", | |||
|
423 | "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", | |||
|
424 | "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", | |||
|
425 | "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", | |||
|
426 | "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", | |||
|
427 | "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", | |||
|
428 | "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", | |||
|
429 | "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", | |||
|
430 | "purple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", | |||
|
431 | "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", | |||
|
432 | "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", | |||
|
433 | "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", | |||
|
434 | "whitesmoke", "yellow", "yellowgreen" | |||
|
435 | ]); | |||
|
436 | ||||
|
437 | var valueKeywords = keySet([ | |||
|
438 | "above", "absolute", "activeborder", "activecaption", "afar", | |||
|
439 | "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate", | |||
|
440 | "always", "amharic", "amharic-abegede", "antialiased", "appworkspace", | |||
|
441 | "arabic-indic", "armenian", "asterisks", "auto", "avoid", "background", | |||
|
442 | "backwards", "baseline", "below", "bidi-override", "binary", "bengali", | |||
|
443 | "blink", "block", "block-axis", "bold", "bolder", "border", "border-box", | |||
|
444 | "both", "bottom", "break-all", "break-word", "button", "button-bevel", | |||
|
445 | "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian", | |||
|
446 | "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret", | |||
|
447 | "cell", "center", "checkbox", "circle", "cjk-earthly-branch", | |||
|
448 | "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote", | |||
|
449 | "col-resize", "collapse", "compact", "condensed", "contain", "content", | |||
|
450 | "content-box", "context-menu", "continuous", "copy", "cover", "crop", | |||
|
451 | "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal", | |||
|
452 | "decimal-leading-zero", "default", "default-button", "destination-atop", | |||
|
453 | "destination-in", "destination-out", "destination-over", "devanagari", | |||
|
454 | "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted", | |||
|
455 | "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", | |||
|
456 | "element", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", | |||
|
457 | "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er", | |||
|
458 | "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", | |||
|
459 | "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et", | |||
|
460 | "ethiopic-halehame-gez", "ethiopic-halehame-om-et", | |||
|
461 | "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et", | |||
|
462 | "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", | |||
|
463 | "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed", | |||
|
464 | "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes", | |||
|
465 | "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove", | |||
|
466 | "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", | |||
|
467 | "help", "hidden", "hide", "higher", "highlight", "highlighttext", | |||
|
468 | "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore", | |||
|
469 | "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", | |||
|
470 | "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis", | |||
|
471 | "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert", | |||
|
472 | "italic", "justify", "kannada", "katakana", "katakana-iroha", "khmer", | |||
|
473 | "landscape", "lao", "large", "larger", "left", "level", "lighter", | |||
|
474 | "line-through", "linear", "lines", "list-item", "listbox", "listitem", | |||
|
475 | "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", | |||
|
476 | "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian", | |||
|
477 | "lower-roman", "lowercase", "ltr", "malayalam", "match", | |||
|
478 | "media-controls-background", "media-current-time-display", | |||
|
479 | "media-fullscreen-button", "media-mute-button", "media-play-button", | |||
|
480 | "media-return-to-realtime-button", "media-rewind-button", | |||
|
481 | "media-seek-back-button", "media-seek-forward-button", "media-slider", | |||
|
482 | "media-sliderthumb", "media-time-remaining-display", "media-volume-slider", | |||
|
483 | "media-volume-slider-container", "media-volume-sliderthumb", "medium", | |||
|
484 | "menu", "menulist", "menulist-button", "menulist-text", | |||
|
485 | "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", | |||
|
486 | "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize", | |||
|
487 | "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", | |||
|
488 | "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", | |||
|
489 | "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote", | |||
|
490 | "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset", | |||
|
491 | "outside", "overlay", "overline", "padding", "padding-box", "painted", | |||
|
492 | "paused", "persian", "plus-darker", "plus-lighter", "pointer", "portrait", | |||
|
493 | "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button", | |||
|
494 | "radio", "read-only", "read-write", "read-write-plaintext-only", "relative", | |||
|
495 | "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba", | |||
|
496 | "ridge", "right", "round", "row-resize", "rtl", "run-in", "running", | |||
|
497 | "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield", | |||
|
498 | "searchfield-cancel-button", "searchfield-decoration", | |||
|
499 | "searchfield-results-button", "searchfield-results-decoration", | |||
|
500 | "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", | |||
|
501 | "single", "skip-white-space", "slide", "slider-horizontal", | |||
|
502 | "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow", | |||
|
503 | "small", "small-caps", "small-caption", "smaller", "solid", "somali", | |||
|
504 | "source-atop", "source-in", "source-out", "source-over", "space", "square", | |||
|
505 | "square-button", "start", "static", "status-bar", "stretch", "stroke", | |||
|
506 | "sub", "subpixel-antialiased", "super", "sw-resize", "table", | |||
|
507 | "table-caption", "table-cell", "table-column", "table-column-group", | |||
|
508 | "table-footer-group", "table-header-group", "table-row", "table-row-group", | |||
|
509 | "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", | |||
|
510 | "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight", | |||
|
511 | "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", | |||
|
512 | "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top", | |||
|
513 | "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", | |||
|
514 | "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal", | |||
|
515 | "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", | |||
|
516 | "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted", | |||
|
517 | "visibleStroke", "visual", "w-resize", "wait", "wave", "wider", | |||
|
518 | "window", "windowframe", "windowtext", "x-large", "x-small", "xor", | |||
|
519 | "xx-large", "xx-small" | |||
|
520 | ]); | |||
|
521 | ||||
|
522 | function tokenCComment(stream, state) { | |||
|
523 | var maybeEnd = false, ch; | |||
|
524 | while ((ch = stream.next()) != null) { | |||
|
525 | if (maybeEnd && ch == "/") { | |||
|
526 | state.tokenize = null; | |||
|
527 | break; | |||
|
528 | } | |||
|
529 | maybeEnd = (ch == "*"); | |||
|
530 | } | |||
|
531 | return ["comment", "comment"]; | |||
|
532 | } | |||
|
533 | ||||
|
534 | CodeMirror.defineMIME("text/css", { | |||
|
535 | atMediaTypes: atMediaTypes, | |||
|
536 | atMediaFeatures: atMediaFeatures, | |||
|
537 | propertyKeywords: propertyKeywords, | |||
|
538 | colorKeywords: colorKeywords, | |||
|
539 | valueKeywords: valueKeywords, | |||
|
540 | hooks: { | |||
|
541 | "<": function(stream, state) { | |||
|
542 | function tokenSGMLComment(stream, state) { | |||
|
543 | var dashes = 0, ch; | |||
|
544 | while ((ch = stream.next()) != null) { | |||
|
545 | if (dashes >= 2 && ch == ">") { | |||
|
546 | state.tokenize = null; | |||
|
547 | break; | |||
|
548 | } | |||
|
549 | dashes = (ch == "-") ? dashes + 1 : 0; | |||
|
550 | } | |||
|
551 | return ["comment", "comment"]; | |||
|
552 | } | |||
|
553 | if (stream.eat("!")) { | |||
|
554 | state.tokenize = tokenSGMLComment; | |||
|
555 | return tokenSGMLComment(stream, state); | |||
|
556 | } | |||
|
557 | }, | |||
|
558 | "/": function(stream, state) { | |||
|
559 | if (stream.eat("*")) { | |||
|
560 | state.tokenize = tokenCComment; | |||
|
561 | return tokenCComment(stream, state); | |||
|
562 | } | |||
|
563 | return false; | |||
|
564 | } | |||
|
565 | }, | |||
|
566 | name: "css-base" | |||
|
567 | }); | |||
|
568 | ||||
|
569 | CodeMirror.defineMIME("text/x-scss", { | |||
|
570 | atMediaTypes: atMediaTypes, | |||
|
571 | atMediaFeatures: atMediaFeatures, | |||
|
572 | propertyKeywords: propertyKeywords, | |||
|
573 | colorKeywords: colorKeywords, | |||
|
574 | valueKeywords: valueKeywords, | |||
|
575 | allowNested: true, | |||
|
576 | hooks: { | |||
|
577 | "$": function(stream) { | |||
|
578 | stream.match(/^[\w-]+/); | |||
|
579 | if (stream.peek() == ":") { | |||
|
580 | return ["variable", "variable-definition"]; | |||
|
581 | } | |||
|
582 | return ["variable", "variable"]; | |||
|
583 | }, | |||
|
584 | "/": function(stream, state) { | |||
|
585 | if (stream.eat("/")) { | |||
|
586 | stream.skipToEnd(); | |||
|
587 | return ["comment", "comment"]; | |||
|
588 | } else if (stream.eat("*")) { | |||
|
589 | state.tokenize = tokenCComment; | |||
|
590 | return tokenCComment(stream, state); | |||
|
591 | } else { | |||
|
592 | return ["operator", "operator"]; | |||
|
593 | } | |||
|
594 | }, | |||
|
595 | "#": function(stream) { | |||
|
596 | if (stream.eat("{")) { | |||
|
597 | return ["operator", "interpolation"]; | |||
|
598 | } else { | |||
|
599 | stream.eatWhile(/[\w\\\-]/); | |||
|
600 | return ["atom", "hash"]; | |||
|
601 | } | |||
|
602 | } | |||
|
603 | }, | |||
|
604 | name: "css-base" | |||
|
605 | }); | |||
|
606 | })(); |
@@ -0,0 +1,58 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: CSS mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="css.js"></script> | |||
|
9 | <style>.CodeMirror {background: #f8f8f8;}</style> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: CSS mode</h1> | |||
|
14 | <form><textarea id="code" name="code"> | |||
|
15 | /* Some example CSS */ | |||
|
16 | ||||
|
17 | @import url("something.css"); | |||
|
18 | ||||
|
19 | body { | |||
|
20 | margin: 0; | |||
|
21 | padding: 3em 6em; | |||
|
22 | font-family: tahoma, arial, sans-serif; | |||
|
23 | color: #000; | |||
|
24 | } | |||
|
25 | ||||
|
26 | #navigation a { | |||
|
27 | font-weight: bold; | |||
|
28 | text-decoration: none !important; | |||
|
29 | } | |||
|
30 | ||||
|
31 | h1 { | |||
|
32 | font-size: 2.5em; | |||
|
33 | } | |||
|
34 | ||||
|
35 | h2 { | |||
|
36 | font-size: 1.7em; | |||
|
37 | } | |||
|
38 | ||||
|
39 | h1:before, h2:before { | |||
|
40 | content: "::"; | |||
|
41 | } | |||
|
42 | ||||
|
43 | code { | |||
|
44 | font-family: courier, monospace; | |||
|
45 | font-size: 80%; | |||
|
46 | color: #418A8A; | |||
|
47 | } | |||
|
48 | </textarea></form> | |||
|
49 | <script> | |||
|
50 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | |||
|
51 | </script> | |||
|
52 | ||||
|
53 | <p><strong>MIME types defined:</strong> <code>text/css</code>.</p> | |||
|
54 | ||||
|
55 | <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#css_*">normal</a>, <a href="../../test/index.html#verbose,css_*">verbose</a>.</p> | |||
|
56 | ||||
|
57 | </body> | |||
|
58 | </html> |
@@ -0,0 +1,145 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: SCSS mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="css.js"></script> | |||
|
9 | <style>.CodeMirror {background: #f8f8f8;}</style> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: SCSS mode</h1> | |||
|
14 | <form><textarea id="code" name="code"> | |||
|
15 | /* Some example SCSS */ | |||
|
16 | ||||
|
17 | @import "compass/css3"; | |||
|
18 | $variable: #333; | |||
|
19 | ||||
|
20 | $blue: #3bbfce; | |||
|
21 | $margin: 16px; | |||
|
22 | ||||
|
23 | .content-navigation { | |||
|
24 | #nested { | |||
|
25 | background-color: black; | |||
|
26 | } | |||
|
27 | border-color: $blue; | |||
|
28 | color: | |||
|
29 | darken($blue, 9%); | |||
|
30 | } | |||
|
31 | ||||
|
32 | .border { | |||
|
33 | padding: $margin / 2; | |||
|
34 | margin: $margin / 2; | |||
|
35 | border-color: $blue; | |||
|
36 | } | |||
|
37 | ||||
|
38 | @mixin table-base { | |||
|
39 | th { | |||
|
40 | text-align: center; | |||
|
41 | font-weight: bold; | |||
|
42 | } | |||
|
43 | td, th {padding: 2px} | |||
|
44 | } | |||
|
45 | ||||
|
46 | table.hl { | |||
|
47 | margin: 2em 0; | |||
|
48 | td.ln { | |||
|
49 | text-align: right; | |||
|
50 | } | |||
|
51 | } | |||
|
52 | ||||
|
53 | li { | |||
|
54 | font: { | |||
|
55 | family: serif; | |||
|
56 | weight: bold; | |||
|
57 | size: 1.2em; | |||
|
58 | } | |||
|
59 | } | |||
|
60 | ||||
|
61 | @mixin left($dist) { | |||
|
62 | float: left; | |||
|
63 | margin-left: $dist; | |||
|
64 | } | |||
|
65 | ||||
|
66 | #data { | |||
|
67 | @include left(10px); | |||
|
68 | @include table-base; | |||
|
69 | } | |||
|
70 | ||||
|
71 | .source { | |||
|
72 | @include flow-into(target); | |||
|
73 | border: 10px solid green; | |||
|
74 | margin: 20px; | |||
|
75 | width: 200px; } | |||
|
76 | ||||
|
77 | .new-container { | |||
|
78 | @include flow-from(target); | |||
|
79 | border: 10px solid red; | |||
|
80 | margin: 20px; | |||
|
81 | width: 200px; } | |||
|
82 | ||||
|
83 | body { | |||
|
84 | margin: 0; | |||
|
85 | padding: 3em 6em; | |||
|
86 | font-family: tahoma, arial, sans-serif; | |||
|
87 | color: #000; | |||
|
88 | } | |||
|
89 | ||||
|
90 | @mixin yellow() { | |||
|
91 | background: yellow; | |||
|
92 | } | |||
|
93 | ||||
|
94 | .big { | |||
|
95 | font-size: 14px; | |||
|
96 | } | |||
|
97 | ||||
|
98 | .nested { | |||
|
99 | @include border-radius(3px); | |||
|
100 | @extend .big; | |||
|
101 | p { | |||
|
102 | background: whitesmoke; | |||
|
103 | a { | |||
|
104 | color: red; | |||
|
105 | } | |||
|
106 | } | |||
|
107 | } | |||
|
108 | ||||
|
109 | #navigation a { | |||
|
110 | font-weight: bold; | |||
|
111 | text-decoration: none !important; | |||
|
112 | } | |||
|
113 | ||||
|
114 | h1 { | |||
|
115 | font-size: 2.5em; | |||
|
116 | } | |||
|
117 | ||||
|
118 | h2 { | |||
|
119 | font-size: 1.7em; | |||
|
120 | } | |||
|
121 | ||||
|
122 | h1:before, h2:before { | |||
|
123 | content: "::"; | |||
|
124 | } | |||
|
125 | ||||
|
126 | code { | |||
|
127 | font-family: courier, monospace; | |||
|
128 | font-size: 80%; | |||
|
129 | color: #418A8A; | |||
|
130 | } | |||
|
131 | </textarea></form> | |||
|
132 | <script> | |||
|
133 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
134 | lineNumbers: true, | |||
|
135 | matchBrackets: true, | |||
|
136 | mode: "text/x-scss" | |||
|
137 | }); | |||
|
138 | </script> | |||
|
139 | ||||
|
140 | <p><strong>MIME types defined:</strong> <code>text/scss</code>.</p> | |||
|
141 | ||||
|
142 | <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#scss_*">normal</a>, <a href="../../test/index.html#verbose,scss_*">verbose</a>.</p> | |||
|
143 | ||||
|
144 | </body> | |||
|
145 | </html> |
@@ -0,0 +1,80 b'' | |||||
|
1 | (function() { | |||
|
2 | var mode = CodeMirror.getMode({tabSize: 4}, "text/x-scss"); | |||
|
3 | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1), "scss"); } | |||
|
4 | ||||
|
5 | MT('url_with_quotation', | |||
|
6 | "[tag foo] { [property background][operator :][string-2 url]([string test.jpg]) }"); | |||
|
7 | ||||
|
8 | MT('url_with_double_quotes', | |||
|
9 | "[tag foo] { [property background][operator :][string-2 url]([string \"test.jpg\"]) }"); | |||
|
10 | ||||
|
11 | MT('url_with_single_quotes', | |||
|
12 | "[tag foo] { [property background][operator :][string-2 url]([string \'test.jpg\']) }"); | |||
|
13 | ||||
|
14 | MT('string', | |||
|
15 | "[def @import] [string \"compass/css3\"]"); | |||
|
16 | ||||
|
17 | MT('important_keyword', | |||
|
18 | "[tag foo] { [property background][operator :][string-2 url]([string \'test.jpg\']) [keyword !important] }"); | |||
|
19 | ||||
|
20 | MT('variable', | |||
|
21 | "[variable-2 $blue][operator :][atom #333]"); | |||
|
22 | ||||
|
23 | MT('variable_as_attribute', | |||
|
24 | "[tag foo] { [property color][operator :][variable-2 $blue] }"); | |||
|
25 | ||||
|
26 | MT('numbers', | |||
|
27 | "[tag foo] { [property padding][operator :][number 10px] [number 10] [number 10em] [number 8in] }"); | |||
|
28 | ||||
|
29 | MT('number_percentage', | |||
|
30 | "[tag foo] { [property width][operator :][number 80%] }"); | |||
|
31 | ||||
|
32 | MT('selector', | |||
|
33 | "[builtin #hello][qualifier .world]{}"); | |||
|
34 | ||||
|
35 | MT('singleline_comment', | |||
|
36 | "[comment // this is a comment]"); | |||
|
37 | ||||
|
38 | MT('multiline_comment', | |||
|
39 | "[comment /*foobar*/]"); | |||
|
40 | ||||
|
41 | MT('attribute_with_hyphen', | |||
|
42 | "[tag foo] { [property font-size][operator :][number 10px] }"); | |||
|
43 | ||||
|
44 | MT('string_after_attribute', | |||
|
45 | "[tag foo] { [property content][operator :][string \"::\"] }"); | |||
|
46 | ||||
|
47 | MT('directives', | |||
|
48 | "[def @include] [qualifier .mixin]"); | |||
|
49 | ||||
|
50 | MT('basic_structure', | |||
|
51 | "[tag p] { [property background][operator :][keyword red]; }"); | |||
|
52 | ||||
|
53 | MT('nested_structure', | |||
|
54 | "[tag p] { [tag a] { [property color][operator :][keyword red]; } }"); | |||
|
55 | ||||
|
56 | MT('mixin', | |||
|
57 | "[def @mixin] [tag table-base] {}"); | |||
|
58 | ||||
|
59 | MT('number_without_semicolon', | |||
|
60 | "[tag p] {[property width][operator :][number 12]}", | |||
|
61 | "[tag a] {[property color][operator :][keyword red];}"); | |||
|
62 | ||||
|
63 | MT('atom_in_nested_block', | |||
|
64 | "[tag p] { [tag a] { [property color][operator :][atom #000]; } }"); | |||
|
65 | ||||
|
66 | MT('interpolation_in_property', | |||
|
67 | "[tag foo] { [operator #{][variable-2 $hello][operator }:][atom #000]; }"); | |||
|
68 | ||||
|
69 | MT('interpolation_in_selector', | |||
|
70 | "[tag foo][operator #{][variable-2 $hello][operator }] { [property color][operator :][atom #000]; }"); | |||
|
71 | ||||
|
72 | MT('interpolation_error', | |||
|
73 | "[tag foo][operator #{][error foo][operator }] { [property color][operator :][atom #000]; }"); | |||
|
74 | ||||
|
75 | MT("divide_operator", | |||
|
76 | "[tag foo] { [property width][operator :][number 4] [operator /] [number 2] }"); | |||
|
77 | ||||
|
78 | MT('nested_structure_with_id_selector', | |||
|
79 | "[tag p] { [builtin #hello] { [property color][operator :][keyword red]; } }"); | |||
|
80 | })(); |
@@ -0,0 +1,113 b'' | |||||
|
1 | (function() { | |||
|
2 | var mode = CodeMirror.getMode({tabSize: 4}, "css"); | |||
|
3 | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | |||
|
4 | ||||
|
5 | // Requires at least one media query | |||
|
6 | MT("atMediaEmpty", | |||
|
7 | "[def @media] [error {] }"); | |||
|
8 | ||||
|
9 | MT("atMediaMultiple", | |||
|
10 | "[def @media] [keyword not] [attribute screen] [operator and] ([property color]), [keyword not] [attribute print] [operator and] ([property color]) { }"); | |||
|
11 | ||||
|
12 | MT("atMediaCheckStack", | |||
|
13 | "[def @media] [attribute screen] { } [tag foo] { }"); | |||
|
14 | ||||
|
15 | MT("atMediaCheckStack", | |||
|
16 | "[def @media] [attribute screen] ([property color]) { } [tag foo] { }"); | |||
|
17 | ||||
|
18 | MT("atMediaCheckStackInvalidAttribute", | |||
|
19 | "[def @media] [attribute&error foobarhello] { } [tag foo] { }"); | |||
|
20 | ||||
|
21 | // Error, because "and" is only allowed immediately preceding a media expression | |||
|
22 | MT("atMediaInvalidAttribute", | |||
|
23 | "[def @media] [attribute&error foobarhello] { }"); | |||
|
24 | ||||
|
25 | // Error, because "and" is only allowed immediately preceding a media expression | |||
|
26 | MT("atMediaInvalidAnd", | |||
|
27 | "[def @media] [error and] [attribute screen] { }"); | |||
|
28 | ||||
|
29 | // Error, because "not" is only allowed as the first item in each media query | |||
|
30 | MT("atMediaInvalidNot", | |||
|
31 | "[def @media] [attribute screen] [error not] ([error not]) { }"); | |||
|
32 | ||||
|
33 | // Error, because "only" is only allowed as the first item in each media query | |||
|
34 | MT("atMediaInvalidOnly", | |||
|
35 | "[def @media] [attribute screen] [error only] ([error only]) { }"); | |||
|
36 | ||||
|
37 | // Error, because "foobarhello" is neither a known type or property, but | |||
|
38 | // property was expected (after "and"), and it should be in parenthese. | |||
|
39 | MT("atMediaUnknownType", | |||
|
40 | "[def @media] [attribute screen] [operator and] [error foobarhello] { }"); | |||
|
41 | ||||
|
42 | // Error, because "color" is not a known type, but is a known property, and | |||
|
43 | // should be in parentheses. | |||
|
44 | MT("atMediaInvalidType", | |||
|
45 | "[def @media] [attribute screen] [operator and] [error color] { }"); | |||
|
46 | ||||
|
47 | // Error, because "print" is not a known property, but is a known type, | |||
|
48 | // and should not be in parenthese. | |||
|
49 | MT("atMediaInvalidProperty", | |||
|
50 | "[def @media] [attribute screen] [operator and] ([error print]) { }"); | |||
|
51 | ||||
|
52 | // Soft error, because "foobarhello" is not a known property or type. | |||
|
53 | MT("atMediaUnknownProperty", | |||
|
54 | "[def @media] [attribute screen] [operator and] ([property&error foobarhello]) { }"); | |||
|
55 | ||||
|
56 | MT("tagSelector", | |||
|
57 | "[tag foo] { }"); | |||
|
58 | ||||
|
59 | MT("classSelector", | |||
|
60 | "[qualifier .foo-bar_hello] { }"); | |||
|
61 | ||||
|
62 | MT("idSelector", | |||
|
63 | "[builtin #foo] { [error #foo] }"); | |||
|
64 | ||||
|
65 | MT("tagSelectorUnclosed", | |||
|
66 | "[tag foo] { [property margin][operator :] [number 0] } [tag bar] { }"); | |||
|
67 | ||||
|
68 | MT("tagStringNoQuotes", | |||
|
69 | "[tag foo] { [property font-family][operator :] [variable-2 hello] [variable-2 world]; }"); | |||
|
70 | ||||
|
71 | MT("tagStringDouble", | |||
|
72 | "[tag foo] { [property font-family][operator :] [string \"hello world\"]; }"); | |||
|
73 | ||||
|
74 | MT("tagStringSingle", | |||
|
75 | "[tag foo] { [property font-family][operator :] [string 'hello world']; }"); | |||
|
76 | ||||
|
77 | MT("tagColorKeyword", | |||
|
78 | "[tag foo] {" + | |||
|
79 | "[property color][operator :] [keyword black];" + | |||
|
80 | "[property color][operator :] [keyword navy];" + | |||
|
81 | "[property color][operator :] [keyword yellow];" + | |||
|
82 | "}"); | |||
|
83 | ||||
|
84 | MT("tagColorHex3", | |||
|
85 | "[tag foo] { [property background][operator :] [atom #fff]; }"); | |||
|
86 | ||||
|
87 | MT("tagColorHex6", | |||
|
88 | "[tag foo] { [property background][operator :] [atom #ffffff]; }"); | |||
|
89 | ||||
|
90 | MT("tagColorHex4", | |||
|
91 | "[tag foo] { [property background][operator :] [atom&error #ffff]; }"); | |||
|
92 | ||||
|
93 | MT("tagColorHexInvalid", | |||
|
94 | "[tag foo] { [property background][operator :] [atom&error #ffg]; }"); | |||
|
95 | ||||
|
96 | MT("tagNegativeNumber", | |||
|
97 | "[tag foo] { [property margin][operator :] [number -5px]; }"); | |||
|
98 | ||||
|
99 | MT("tagPositiveNumber", | |||
|
100 | "[tag foo] { [property padding][operator :] [number 5px]; }"); | |||
|
101 | ||||
|
102 | MT("tagVendor", | |||
|
103 | "[tag foo] { [meta -foo-][property box-sizing][operator :] [meta -foo-][string-2 border-box]; }"); | |||
|
104 | ||||
|
105 | MT("tagBogusProperty", | |||
|
106 | "[tag foo] { [property&error barhelloworld][operator :] [number 0]; }"); | |||
|
107 | ||||
|
108 | MT("tagTwoProperties", | |||
|
109 | "[tag foo] { [property margin][operator :] [number 0]; [property padding][operator :] [number 0]; }"); | |||
|
110 | ||||
|
111 | MT("commentSGML", | |||
|
112 | "[comment <!--comment-->]"); | |||
|
113 | })(); |
@@ -0,0 +1,205 b'' | |||||
|
1 | CodeMirror.defineMode("d", function(config, parserConfig) { | |||
|
2 | var indentUnit = config.indentUnit, | |||
|
3 | statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, | |||
|
4 | keywords = parserConfig.keywords || {}, | |||
|
5 | builtin = parserConfig.builtin || {}, | |||
|
6 | blockKeywords = parserConfig.blockKeywords || {}, | |||
|
7 | atoms = parserConfig.atoms || {}, | |||
|
8 | hooks = parserConfig.hooks || {}, | |||
|
9 | multiLineStrings = parserConfig.multiLineStrings; | |||
|
10 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | |||
|
11 | ||||
|
12 | var curPunc; | |||
|
13 | ||||
|
14 | function tokenBase(stream, state) { | |||
|
15 | var ch = stream.next(); | |||
|
16 | if (hooks[ch]) { | |||
|
17 | var result = hooks[ch](stream, state); | |||
|
18 | if (result !== false) return result; | |||
|
19 | } | |||
|
20 | if (ch == '"' || ch == "'" || ch == "`") { | |||
|
21 | state.tokenize = tokenString(ch); | |||
|
22 | return state.tokenize(stream, state); | |||
|
23 | } | |||
|
24 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |||
|
25 | curPunc = ch; | |||
|
26 | return null; | |||
|
27 | } | |||
|
28 | if (/\d/.test(ch)) { | |||
|
29 | stream.eatWhile(/[\w\.]/); | |||
|
30 | return "number"; | |||
|
31 | } | |||
|
32 | if (ch == "/") { | |||
|
33 | if (stream.eat("+")) { | |||
|
34 | state.tokenize = tokenComment; | |||
|
35 | return tokenNestedComment(stream, state); | |||
|
36 | } | |||
|
37 | if (stream.eat("*")) { | |||
|
38 | state.tokenize = tokenComment; | |||
|
39 | return tokenComment(stream, state); | |||
|
40 | } | |||
|
41 | if (stream.eat("/")) { | |||
|
42 | stream.skipToEnd(); | |||
|
43 | return "comment"; | |||
|
44 | } | |||
|
45 | } | |||
|
46 | if (isOperatorChar.test(ch)) { | |||
|
47 | stream.eatWhile(isOperatorChar); | |||
|
48 | return "operator"; | |||
|
49 | } | |||
|
50 | stream.eatWhile(/[\w\$_]/); | |||
|
51 | var cur = stream.current(); | |||
|
52 | if (keywords.propertyIsEnumerable(cur)) { | |||
|
53 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
54 | return "keyword"; | |||
|
55 | } | |||
|
56 | if (builtin.propertyIsEnumerable(cur)) { | |||
|
57 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
58 | return "builtin"; | |||
|
59 | } | |||
|
60 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | |||
|
61 | return "variable"; | |||
|
62 | } | |||
|
63 | ||||
|
64 | function tokenString(quote) { | |||
|
65 | return function(stream, state) { | |||
|
66 | var escaped = false, next, end = false; | |||
|
67 | while ((next = stream.next()) != null) { | |||
|
68 | if (next == quote && !escaped) {end = true; break;} | |||
|
69 | escaped = !escaped && next == "\\"; | |||
|
70 | } | |||
|
71 | if (end || !(escaped || multiLineStrings)) | |||
|
72 | state.tokenize = null; | |||
|
73 | return "string"; | |||
|
74 | }; | |||
|
75 | } | |||
|
76 | ||||
|
77 | function tokenComment(stream, state) { | |||
|
78 | var maybeEnd = false, ch; | |||
|
79 | while (ch = stream.next()) { | |||
|
80 | if (ch == "/" && maybeEnd) { | |||
|
81 | state.tokenize = null; | |||
|
82 | break; | |||
|
83 | } | |||
|
84 | maybeEnd = (ch == "*"); | |||
|
85 | } | |||
|
86 | return "comment"; | |||
|
87 | } | |||
|
88 | ||||
|
89 | function tokenNestedComment(stream, state) { | |||
|
90 | var maybeEnd = false, ch; | |||
|
91 | while (ch = stream.next()) { | |||
|
92 | if (ch == "/" && maybeEnd) { | |||
|
93 | state.tokenize = null; | |||
|
94 | break; | |||
|
95 | } | |||
|
96 | maybeEnd = (ch == "+"); | |||
|
97 | } | |||
|
98 | return "comment"; | |||
|
99 | } | |||
|
100 | ||||
|
101 | function Context(indented, column, type, align, prev) { | |||
|
102 | this.indented = indented; | |||
|
103 | this.column = column; | |||
|
104 | this.type = type; | |||
|
105 | this.align = align; | |||
|
106 | this.prev = prev; | |||
|
107 | } | |||
|
108 | function pushContext(state, col, type) { | |||
|
109 | var indent = state.indented; | |||
|
110 | if (state.context && state.context.type == "statement") | |||
|
111 | indent = state.context.indented; | |||
|
112 | return state.context = new Context(indent, col, type, null, state.context); | |||
|
113 | } | |||
|
114 | function popContext(state) { | |||
|
115 | var t = state.context.type; | |||
|
116 | if (t == ")" || t == "]" || t == "}") | |||
|
117 | state.indented = state.context.indented; | |||
|
118 | return state.context = state.context.prev; | |||
|
119 | } | |||
|
120 | ||||
|
121 | // Interface | |||
|
122 | ||||
|
123 | return { | |||
|
124 | startState: function(basecolumn) { | |||
|
125 | return { | |||
|
126 | tokenize: null, | |||
|
127 | context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | |||
|
128 | indented: 0, | |||
|
129 | startOfLine: true | |||
|
130 | }; | |||
|
131 | }, | |||
|
132 | ||||
|
133 | token: function(stream, state) { | |||
|
134 | var ctx = state.context; | |||
|
135 | if (stream.sol()) { | |||
|
136 | if (ctx.align == null) ctx.align = false; | |||
|
137 | state.indented = stream.indentation(); | |||
|
138 | state.startOfLine = true; | |||
|
139 | } | |||
|
140 | if (stream.eatSpace()) return null; | |||
|
141 | curPunc = null; | |||
|
142 | var style = (state.tokenize || tokenBase)(stream, state); | |||
|
143 | if (style == "comment" || style == "meta") return style; | |||
|
144 | if (ctx.align == null) ctx.align = true; | |||
|
145 | ||||
|
146 | if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state); | |||
|
147 | else if (curPunc == "{") pushContext(state, stream.column(), "}"); | |||
|
148 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); | |||
|
149 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); | |||
|
150 | else if (curPunc == "}") { | |||
|
151 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
152 | if (ctx.type == "}") ctx = popContext(state); | |||
|
153 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
154 | } | |||
|
155 | else if (curPunc == ctx.type) popContext(state); | |||
|
156 | else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement")) | |||
|
157 | pushContext(state, stream.column(), "statement"); | |||
|
158 | state.startOfLine = false; | |||
|
159 | return style; | |||
|
160 | }, | |||
|
161 | ||||
|
162 | indent: function(state, textAfter) { | |||
|
163 | if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass; | |||
|
164 | var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); | |||
|
165 | if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; | |||
|
166 | var closing = firstChar == ctx.type; | |||
|
167 | if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit); | |||
|
168 | else if (ctx.align) return ctx.column + (closing ? 0 : 1); | |||
|
169 | else return ctx.indented + (closing ? 0 : indentUnit); | |||
|
170 | }, | |||
|
171 | ||||
|
172 | electricChars: "{}" | |||
|
173 | }; | |||
|
174 | }); | |||
|
175 | ||||
|
176 | (function() { | |||
|
177 | function words(str) { | |||
|
178 | var obj = {}, words = str.split(" "); | |||
|
179 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | |||
|
180 | return obj; | |||
|
181 | } | |||
|
182 | ||||
|
183 | var blockKeywords = "body catch class do else enum for foreach foreach_reverse if in interface mixin " + | |||
|
184 | "out scope struct switch try union unittest version while with"; | |||
|
185 | ||||
|
186 | CodeMirror.defineMIME("text/x-d", { | |||
|
187 | name: "d", | |||
|
188 | keywords: words("abstract alias align asm assert auto break case cast cdouble cent cfloat const continue " + | |||
|
189 | "debug default delegate delete deprecated export extern final finally function goto immutable " + | |||
|
190 | "import inout invariant is lazy macro module new nothrow override package pragma private " + | |||
|
191 | "protected public pure ref return shared short static super synchronized template this " + | |||
|
192 | "throw typedef typeid typeof volatile __FILE__ __LINE__ __gshared __traits __vector __parameters " + | |||
|
193 | blockKeywords), | |||
|
194 | blockKeywords: words(blockKeywords), | |||
|
195 | builtin: words("bool byte char creal dchar double float idouble ifloat int ireal long real short ubyte " + | |||
|
196 | "ucent uint ulong ushort wchar wstring void size_t sizediff_t"), | |||
|
197 | atoms: words("exit failure success true false null"), | |||
|
198 | hooks: { | |||
|
199 | "@": function(stream, _state) { | |||
|
200 | stream.eatWhile(/[\w\$_]/); | |||
|
201 | return "meta"; | |||
|
202 | } | |||
|
203 | } | |||
|
204 | }); | |||
|
205 | }()); |
@@ -0,0 +1,262 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: D mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="d.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | <style>.CodeMirror {border: 2px inset #dee;}</style> | |||
|
12 | </head> | |||
|
13 | <body> | |||
|
14 | <h1>CodeMirror: D mode</h1> | |||
|
15 | ||||
|
16 | <form><textarea id="code" name="code"> | |||
|
17 | /* D demo code // copied from phobos/sd/metastrings.d */ | |||
|
18 | // Written in the D programming language. | |||
|
19 | ||||
|
20 | /** | |||
|
21 | Templates with which to do compile-time manipulation of strings. | |||
|
22 | ||||
|
23 | Macros: | |||
|
24 | WIKI = Phobos/StdMetastrings | |||
|
25 | ||||
|
26 | Copyright: Copyright Digital Mars 2007 - 2009. | |||
|
27 | License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. | |||
|
28 | Authors: $(WEB digitalmars.com, Walter Bright), | |||
|
29 | Don Clugston | |||
|
30 | Source: $(PHOBOSSRC std/_metastrings.d) | |||
|
31 | */ | |||
|
32 | /* | |||
|
33 | Copyright Digital Mars 2007 - 2009. | |||
|
34 | Distributed under the Boost Software License, Version 1.0. | |||
|
35 | (See accompanying file LICENSE_1_0.txt or copy at | |||
|
36 | http://www.boost.org/LICENSE_1_0.txt) | |||
|
37 | */ | |||
|
38 | module std.metastrings; | |||
|
39 | ||||
|
40 | /** | |||
|
41 | Formats constants into a string at compile time. Analogous to $(XREF | |||
|
42 | string,format). | |||
|
43 | ||||
|
44 | Parameters: | |||
|
45 | ||||
|
46 | A = tuple of constants, which can be strings, characters, or integral | |||
|
47 | values. | |||
|
48 | ||||
|
49 | Formats: | |||
|
50 | * The formats supported are %s for strings, and %% | |||
|
51 | * for the % character. | |||
|
52 | Example: | |||
|
53 | --- | |||
|
54 | import std.metastrings; | |||
|
55 | import std.stdio; | |||
|
56 | ||||
|
57 | void main() | |||
|
58 | { | |||
|
59 | string s = Format!("Arg %s = %s", "foo", 27); | |||
|
60 | writefln(s); // "Arg foo = 27" | |||
|
61 | } | |||
|
62 | * --- | |||
|
63 | */ | |||
|
64 | ||||
|
65 | template Format(A...) | |||
|
66 | { | |||
|
67 | static if (A.length == 0) | |||
|
68 | enum Format = ""; | |||
|
69 | else static if (is(typeof(A[0]) : const(char)[])) | |||
|
70 | enum Format = FormatString!(A[0], A[1..$]); | |||
|
71 | else | |||
|
72 | enum Format = toStringNow!(A[0]) ~ Format!(A[1..$]); | |||
|
73 | } | |||
|
74 | ||||
|
75 | template FormatString(const(char)[] F, A...) | |||
|
76 | { | |||
|
77 | static if (F.length == 0) | |||
|
78 | enum FormatString = Format!(A); | |||
|
79 | else static if (F.length == 1) | |||
|
80 | enum FormatString = F[0] ~ Format!(A); | |||
|
81 | else static if (F[0..2] == "%s") | |||
|
82 | enum FormatString | |||
|
83 | = toStringNow!(A[0]) ~ FormatString!(F[2..$],A[1..$]); | |||
|
84 | else static if (F[0..2] == "%%") | |||
|
85 | enum FormatString = "%" ~ FormatString!(F[2..$],A); | |||
|
86 | else | |||
|
87 | { | |||
|
88 | static assert(F[0] != '%', "unrecognized format %" ~ F[1]); | |||
|
89 | enum FormatString = F[0] ~ FormatString!(F[1..$],A); | |||
|
90 | } | |||
|
91 | } | |||
|
92 | ||||
|
93 | unittest | |||
|
94 | { | |||
|
95 | auto s = Format!("hel%slo", "world", -138, 'c', true); | |||
|
96 | assert(s == "helworldlo-138ctrue", "[" ~ s ~ "]"); | |||
|
97 | } | |||
|
98 | ||||
|
99 | /** | |||
|
100 | * Convert constant argument to a string. | |||
|
101 | */ | |||
|
102 | ||||
|
103 | template toStringNow(ulong v) | |||
|
104 | { | |||
|
105 | static if (v < 10) | |||
|
106 | enum toStringNow = "" ~ cast(char)(v + '0'); | |||
|
107 | else | |||
|
108 | enum toStringNow = toStringNow!(v / 10) ~ toStringNow!(v % 10); | |||
|
109 | } | |||
|
110 | ||||
|
111 | unittest | |||
|
112 | { | |||
|
113 | static assert(toStringNow!(1uL << 62) == "4611686018427387904"); | |||
|
114 | } | |||
|
115 | ||||
|
116 | /// ditto | |||
|
117 | template toStringNow(long v) | |||
|
118 | { | |||
|
119 | static if (v < 0) | |||
|
120 | enum toStringNow = "-" ~ toStringNow!(cast(ulong) -v); | |||
|
121 | else | |||
|
122 | enum toStringNow = toStringNow!(cast(ulong) v); | |||
|
123 | } | |||
|
124 | ||||
|
125 | unittest | |||
|
126 | { | |||
|
127 | static assert(toStringNow!(0x100000000) == "4294967296"); | |||
|
128 | static assert(toStringNow!(-138L) == "-138"); | |||
|
129 | } | |||
|
130 | ||||
|
131 | /// ditto | |||
|
132 | template toStringNow(uint U) | |||
|
133 | { | |||
|
134 | enum toStringNow = toStringNow!(cast(ulong)U); | |||
|
135 | } | |||
|
136 | ||||
|
137 | /// ditto | |||
|
138 | template toStringNow(int I) | |||
|
139 | { | |||
|
140 | enum toStringNow = toStringNow!(cast(long)I); | |||
|
141 | } | |||
|
142 | ||||
|
143 | /// ditto | |||
|
144 | template toStringNow(bool B) | |||
|
145 | { | |||
|
146 | enum toStringNow = B ? "true" : "false"; | |||
|
147 | } | |||
|
148 | ||||
|
149 | /// ditto | |||
|
150 | template toStringNow(string S) | |||
|
151 | { | |||
|
152 | enum toStringNow = S; | |||
|
153 | } | |||
|
154 | ||||
|
155 | /// ditto | |||
|
156 | template toStringNow(char C) | |||
|
157 | { | |||
|
158 | enum toStringNow = "" ~ C; | |||
|
159 | } | |||
|
160 | ||||
|
161 | ||||
|
162 | /******** | |||
|
163 | * Parse unsigned integer literal from the start of string s. | |||
|
164 | * returns: | |||
|
165 | * .value = the integer literal as a string, | |||
|
166 | * .rest = the string following the integer literal | |||
|
167 | * Otherwise: | |||
|
168 | * .value = null, | |||
|
169 | * .rest = s | |||
|
170 | */ | |||
|
171 | ||||
|
172 | template parseUinteger(const(char)[] s) | |||
|
173 | { | |||
|
174 | static if (s.length == 0) | |||
|
175 | { | |||
|
176 | enum value = ""; | |||
|
177 | enum rest = ""; | |||
|
178 | } | |||
|
179 | else static if (s[0] >= '0' && s[0] <= '9') | |||
|
180 | { | |||
|
181 | enum value = s[0] ~ parseUinteger!(s[1..$]).value; | |||
|
182 | enum rest = parseUinteger!(s[1..$]).rest; | |||
|
183 | } | |||
|
184 | else | |||
|
185 | { | |||
|
186 | enum value = ""; | |||
|
187 | enum rest = s; | |||
|
188 | } | |||
|
189 | } | |||
|
190 | ||||
|
191 | /******** | |||
|
192 | Parse integer literal optionally preceded by $(D '-') from the start | |||
|
193 | of string $(D s). | |||
|
194 | ||||
|
195 | Returns: | |||
|
196 | .value = the integer literal as a string, | |||
|
197 | .rest = the string following the integer literal | |||
|
198 | ||||
|
199 | Otherwise: | |||
|
200 | .value = null, | |||
|
201 | .rest = s | |||
|
202 | */ | |||
|
203 | ||||
|
204 | template parseInteger(const(char)[] s) | |||
|
205 | { | |||
|
206 | static if (s.length == 0) | |||
|
207 | { | |||
|
208 | enum value = ""; | |||
|
209 | enum rest = ""; | |||
|
210 | } | |||
|
211 | else static if (s[0] >= '0' && s[0] <= '9') | |||
|
212 | { | |||
|
213 | enum value = s[0] ~ parseUinteger!(s[1..$]).value; | |||
|
214 | enum rest = parseUinteger!(s[1..$]).rest; | |||
|
215 | } | |||
|
216 | else static if (s.length >= 2 && | |||
|
217 | s[0] == '-' && s[1] >= '0' && s[1] <= '9') | |||
|
218 | { | |||
|
219 | enum value = s[0..2] ~ parseUinteger!(s[2..$]).value; | |||
|
220 | enum rest = parseUinteger!(s[2..$]).rest; | |||
|
221 | } | |||
|
222 | else | |||
|
223 | { | |||
|
224 | enum value = ""; | |||
|
225 | enum rest = s; | |||
|
226 | } | |||
|
227 | } | |||
|
228 | ||||
|
229 | unittest | |||
|
230 | { | |||
|
231 | assert(parseUinteger!("1234abc").value == "1234"); | |||
|
232 | assert(parseUinteger!("1234abc").rest == "abc"); | |||
|
233 | assert(parseInteger!("-1234abc").value == "-1234"); | |||
|
234 | assert(parseInteger!("-1234abc").rest == "abc"); | |||
|
235 | } | |||
|
236 | ||||
|
237 | /** | |||
|
238 | Deprecated aliases held for backward compatibility. | |||
|
239 | */ | |||
|
240 | deprecated alias toStringNow ToString; | |||
|
241 | /// Ditto | |||
|
242 | deprecated alias parseUinteger ParseUinteger; | |||
|
243 | /// Ditto | |||
|
244 | deprecated alias parseUinteger ParseInteger; | |||
|
245 | ||||
|
246 | </textarea></form> | |||
|
247 | ||||
|
248 | <script> | |||
|
249 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
250 | lineNumbers: true, | |||
|
251 | matchBrackets: true, | |||
|
252 | indentUnit: 4, | |||
|
253 | mode: "text/x-d" | |||
|
254 | }); | |||
|
255 | </script> | |||
|
256 | ||||
|
257 | <p>Simple mode that handle D-Syntax (<a href="http://www.dlang.org">DLang Homepage</a>).</p> | |||
|
258 | ||||
|
259 | <p><strong>MIME types defined:</strong> <code>text/x-d</code> | |||
|
260 | .</p> | |||
|
261 | </body> | |||
|
262 | </html> |
@@ -0,0 +1,32 b'' | |||||
|
1 | CodeMirror.defineMode("diff", function() { | |||
|
2 | ||||
|
3 | var TOKEN_NAMES = { | |||
|
4 | '+': 'positive', | |||
|
5 | '-': 'negative', | |||
|
6 | '@': 'meta' | |||
|
7 | }; | |||
|
8 | ||||
|
9 | return { | |||
|
10 | token: function(stream) { | |||
|
11 | var tw_pos = stream.string.search(/[\t ]+?$/); | |||
|
12 | ||||
|
13 | if (!stream.sol() || tw_pos === 0) { | |||
|
14 | stream.skipToEnd(); | |||
|
15 | return ("error " + ( | |||
|
16 | TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, ''); | |||
|
17 | } | |||
|
18 | ||||
|
19 | var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd(); | |||
|
20 | ||||
|
21 | if (tw_pos === -1) { | |||
|
22 | stream.skipToEnd(); | |||
|
23 | } else { | |||
|
24 | stream.pos = tw_pos; | |||
|
25 | } | |||
|
26 | ||||
|
27 | return token_name; | |||
|
28 | } | |||
|
29 | }; | |||
|
30 | }); | |||
|
31 | ||||
|
32 | CodeMirror.defineMIME("text/x-diff", "diff"); |
@@ -0,0 +1,105 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Diff mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="diff.js"></script> | |||
|
9 | <style> | |||
|
10 | .CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;} | |||
|
11 | span.cm-meta {color: #a0b !important;} | |||
|
12 | span.cm-error { background-color: black; opacity: 0.4;} | |||
|
13 | span.cm-error.cm-string { background-color: red; } | |||
|
14 | span.cm-error.cm-tag { background-color: #2b2; } | |||
|
15 | </style> | |||
|
16 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
17 | </head> | |||
|
18 | <body> | |||
|
19 | <h1>CodeMirror: Diff mode</h1> | |||
|
20 | <form><textarea id="code" name="code"> | |||
|
21 | diff --git a/index.html b/index.html | |||
|
22 | index c1d9156..7764744 100644 | |||
|
23 | --- a/index.html | |||
|
24 | +++ b/index.html | |||
|
25 | @@ -95,7 +95,8 @@ StringStream.prototype = { | |||
|
26 | <script> | |||
|
27 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
28 | lineNumbers: true, | |||
|
29 | - autoMatchBrackets: true | |||
|
30 | + autoMatchBrackets: true, | |||
|
31 | + onGutterClick: function(x){console.log(x);} | |||
|
32 | }); | |||
|
33 | </script> | |||
|
34 | </body> | |||
|
35 | diff --git a/lib/codemirror.js b/lib/codemirror.js | |||
|
36 | index 04646a9..9a39cc7 100644 | |||
|
37 | --- a/lib/codemirror.js | |||
|
38 | +++ b/lib/codemirror.js | |||
|
39 | @@ -399,10 +399,16 @@ var CodeMirror = (function() { | |||
|
40 | } | |||
|
41 | ||||
|
42 | function onMouseDown(e) { | |||
|
43 | - var start = posFromMouse(e), last = start; | |||
|
44 | + var start = posFromMouse(e), last = start, target = e.target(); | |||
|
45 | if (!start) return; | |||
|
46 | setCursor(start.line, start.ch, false); | |||
|
47 | if (e.button() != 1) return; | |||
|
48 | + if (target.parentNode == gutter) { | |||
|
49 | + if (options.onGutterClick) | |||
|
50 | + options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom); | |||
|
51 | + return; | |||
|
52 | + } | |||
|
53 | + | |||
|
54 | if (!focused) onFocus(); | |||
|
55 | ||||
|
56 | e.stop(); | |||
|
57 | @@ -808,7 +814,7 @@ var CodeMirror = (function() { | |||
|
58 | for (var i = showingFrom; i < showingTo; ++i) { | |||
|
59 | var marker = lines[i].gutterMarker; | |||
|
60 | if (marker) html.push('<div class="' + marker.style + '">' + htmlEscape(marker.text) + '</div>'); | |||
|
61 | - else html.push("<div>" + (options.lineNumbers ? i + 1 : "\u00a0") + "</div>"); | |||
|
62 | + else html.push("<div>" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "</div>"); | |||
|
63 | } | |||
|
64 | gutter.style.display = "none"; // TODO test whether this actually helps | |||
|
65 | gutter.innerHTML = html.join(""); | |||
|
66 | @@ -1371,10 +1377,8 @@ var CodeMirror = (function() { | |||
|
67 | if (option == "parser") setParser(value); | |||
|
68 | else if (option === "lineNumbers") setLineNumbers(value); | |||
|
69 | else if (option === "gutter") setGutter(value); | |||
|
70 | - else if (option === "readOnly") options.readOnly = value; | |||
|
71 | - else if (option === "indentUnit") {options.indentUnit = indentUnit = value; setParser(options.parser);} | |||
|
72 | - else if (/^(?:enterMode|tabMode|indentWithTabs|readOnly|autoMatchBrackets|undoDepth)$/.test(option)) options[option] = value; | |||
|
73 | - else throw new Error("Can't set option " + option); | |||
|
74 | + else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);} | |||
|
75 | + else options[option] = value; | |||
|
76 | }, | |||
|
77 | cursorCoords: cursorCoords, | |||
|
78 | undo: operation(undo), | |||
|
79 | @@ -1402,7 +1406,8 @@ var CodeMirror = (function() { | |||
|
80 | replaceRange: operation(replaceRange), | |||
|
81 | ||||
|
82 | operation: function(f){return operation(f)();}, | |||
|
83 | - refresh: function(){updateDisplay([{from: 0, to: lines.length}]);} | |||
|
84 | + refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}, | |||
|
85 | + getInputField: function(){return input;} | |||
|
86 | }; | |||
|
87 | return instance; | |||
|
88 | } | |||
|
89 | @@ -1420,6 +1425,7 @@ var CodeMirror = (function() { | |||
|
90 | readOnly: false, | |||
|
91 | onChange: null, | |||
|
92 | onCursorActivity: null, | |||
|
93 | + onGutterClick: null, | |||
|
94 | autoMatchBrackets: false, | |||
|
95 | workTime: 200, | |||
|
96 | workDelay: 300, | |||
|
97 | </textarea></form> | |||
|
98 | <script> | |||
|
99 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | |||
|
100 | </script> | |||
|
101 | ||||
|
102 | <p><strong>MIME types defined:</strong> <code>text/x-diff</code>.</p> | |||
|
103 | ||||
|
104 | </body> | |||
|
105 | </html> |
@@ -0,0 +1,192 b'' | |||||
|
1 | CodeMirror.defineMode("ecl", function(config) { | |||
|
2 | ||||
|
3 | function words(str) { | |||
|
4 | var obj = {}, words = str.split(" "); | |||
|
5 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | |||
|
6 | return obj; | |||
|
7 | } | |||
|
8 | ||||
|
9 | function metaHook(stream, state) { | |||
|
10 | if (!state.startOfLine) return false; | |||
|
11 | stream.skipToEnd(); | |||
|
12 | return "meta"; | |||
|
13 | } | |||
|
14 | ||||
|
15 | var indentUnit = config.indentUnit; | |||
|
16 | var keyword = words("abs acos allnodes ascii asin asstring atan atan2 ave case choose choosen choosesets clustersize combine correlation cos cosh count covariance cron dataset dedup define denormalize distribute distributed distribution ebcdic enth error evaluate event eventextra eventname exists exp failcode failmessage fetch fromunicode getisvalid global graph group hash hash32 hash64 hashcrc hashmd5 having if index intformat isvalid iterate join keyunicode length library limit ln local log loop map matched matchlength matchposition matchtext matchunicode max merge mergejoin min nolocal nonempty normalize parse pipe power preload process project pull random range rank ranked realformat recordof regexfind regexreplace regroup rejected rollup round roundup row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt stepped stored sum table tan tanh thisnode topn tounicode transfer trim truncate typeof ungroup unicodeorder variance which workunit xmldecode xmlencode xmltext xmlunicode"); | |||
|
17 | var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait"); | |||
|
18 | var variable_2 = words("__compressed__ all and any as atmost before beginc++ best between case const counter csv descend encrypt end endc++ endmacro except exclusive expire export extend false few first flat from full function group header heading hole ifblock import in interface joined keep keyed last left limit load local locale lookup macro many maxcount maxlength min skew module named nocase noroot noscan nosort not of only opt or outer overwrite packed partition penalty physicallength pipe quote record relationship repeat return right scan self separator service shared skew skip sql store terminator thor threshold token transform trim true type unicodeorder unsorted validate virtual whole wild within xml xpath"); | |||
|
19 | var variable_3 = words("ascii big_endian boolean data decimal ebcdic integer pattern qstring real record rule set of string token udecimal unicode unsigned varstring varunicode"); | |||
|
20 | var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when"); | |||
|
21 | var blockKeywords = words("catch class do else finally for if switch try while"); | |||
|
22 | var atoms = words("true false null"); | |||
|
23 | var hooks = {"#": metaHook}; | |||
|
24 | var multiLineStrings; | |||
|
25 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | |||
|
26 | ||||
|
27 | var curPunc; | |||
|
28 | ||||
|
29 | function tokenBase(stream, state) { | |||
|
30 | var ch = stream.next(); | |||
|
31 | if (hooks[ch]) { | |||
|
32 | var result = hooks[ch](stream, state); | |||
|
33 | if (result !== false) return result; | |||
|
34 | } | |||
|
35 | if (ch == '"' || ch == "'") { | |||
|
36 | state.tokenize = tokenString(ch); | |||
|
37 | return state.tokenize(stream, state); | |||
|
38 | } | |||
|
39 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |||
|
40 | curPunc = ch; | |||
|
41 | return null; | |||
|
42 | } | |||
|
43 | if (/\d/.test(ch)) { | |||
|
44 | stream.eatWhile(/[\w\.]/); | |||
|
45 | return "number"; | |||
|
46 | } | |||
|
47 | if (ch == "/") { | |||
|
48 | if (stream.eat("*")) { | |||
|
49 | state.tokenize = tokenComment; | |||
|
50 | return tokenComment(stream, state); | |||
|
51 | } | |||
|
52 | if (stream.eat("/")) { | |||
|
53 | stream.skipToEnd(); | |||
|
54 | return "comment"; | |||
|
55 | } | |||
|
56 | } | |||
|
57 | if (isOperatorChar.test(ch)) { | |||
|
58 | stream.eatWhile(isOperatorChar); | |||
|
59 | return "operator"; | |||
|
60 | } | |||
|
61 | stream.eatWhile(/[\w\$_]/); | |||
|
62 | var cur = stream.current().toLowerCase(); | |||
|
63 | if (keyword.propertyIsEnumerable(cur)) { | |||
|
64 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
65 | return "keyword"; | |||
|
66 | } else if (variable.propertyIsEnumerable(cur)) { | |||
|
67 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
68 | return "variable"; | |||
|
69 | } else if (variable_2.propertyIsEnumerable(cur)) { | |||
|
70 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
71 | return "variable-2"; | |||
|
72 | } else if (variable_3.propertyIsEnumerable(cur)) { | |||
|
73 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
74 | return "variable-3"; | |||
|
75 | } else if (builtin.propertyIsEnumerable(cur)) { | |||
|
76 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
77 | return "builtin"; | |||
|
78 | } else { //Data types are of from KEYWORD## | |||
|
79 | var i = cur.length - 1; | |||
|
80 | while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_')) | |||
|
81 | --i; | |||
|
82 | ||||
|
83 | if (i > 0) { | |||
|
84 | var cur2 = cur.substr(0, i + 1); | |||
|
85 | if (variable_3.propertyIsEnumerable(cur2)) { | |||
|
86 | if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement"; | |||
|
87 | return "variable-3"; | |||
|
88 | } | |||
|
89 | } | |||
|
90 | } | |||
|
91 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | |||
|
92 | return null; | |||
|
93 | } | |||
|
94 | ||||
|
95 | function tokenString(quote) { | |||
|
96 | return function(stream, state) { | |||
|
97 | var escaped = false, next, end = false; | |||
|
98 | while ((next = stream.next()) != null) { | |||
|
99 | if (next == quote && !escaped) {end = true; break;} | |||
|
100 | escaped = !escaped && next == "\\"; | |||
|
101 | } | |||
|
102 | if (end || !(escaped || multiLineStrings)) | |||
|
103 | state.tokenize = tokenBase; | |||
|
104 | return "string"; | |||
|
105 | }; | |||
|
106 | } | |||
|
107 | ||||
|
108 | function tokenComment(stream, state) { | |||
|
109 | var maybeEnd = false, ch; | |||
|
110 | while (ch = stream.next()) { | |||
|
111 | if (ch == "/" && maybeEnd) { | |||
|
112 | state.tokenize = tokenBase; | |||
|
113 | break; | |||
|
114 | } | |||
|
115 | maybeEnd = (ch == "*"); | |||
|
116 | } | |||
|
117 | return "comment"; | |||
|
118 | } | |||
|
119 | ||||
|
120 | function Context(indented, column, type, align, prev) { | |||
|
121 | this.indented = indented; | |||
|
122 | this.column = column; | |||
|
123 | this.type = type; | |||
|
124 | this.align = align; | |||
|
125 | this.prev = prev; | |||
|
126 | } | |||
|
127 | function pushContext(state, col, type) { | |||
|
128 | return state.context = new Context(state.indented, 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 | // Interface | |||
|
138 | ||||
|
139 | return { | |||
|
140 | startState: function(basecolumn) { | |||
|
141 | return { | |||
|
142 | tokenize: null, | |||
|
143 | context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | |||
|
144 | indented: 0, | |||
|
145 | startOfLine: true | |||
|
146 | }; | |||
|
147 | }, | |||
|
148 | ||||
|
149 | token: function(stream, state) { | |||
|
150 | var ctx = state.context; | |||
|
151 | if (stream.sol()) { | |||
|
152 | if (ctx.align == null) ctx.align = false; | |||
|
153 | state.indented = stream.indentation(); | |||
|
154 | state.startOfLine = true; | |||
|
155 | } | |||
|
156 | if (stream.eatSpace()) return null; | |||
|
157 | curPunc = null; | |||
|
158 | var style = (state.tokenize || tokenBase)(stream, state); | |||
|
159 | if (style == "comment" || style == "meta") return style; | |||
|
160 | if (ctx.align == null) ctx.align = true; | |||
|
161 | ||||
|
162 | if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state); | |||
|
163 | else if (curPunc == "{") pushContext(state, stream.column(), "}"); | |||
|
164 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); | |||
|
165 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); | |||
|
166 | else if (curPunc == "}") { | |||
|
167 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
168 | if (ctx.type == "}") ctx = popContext(state); | |||
|
169 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
170 | } | |||
|
171 | else if (curPunc == ctx.type) popContext(state); | |||
|
172 | else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement")) | |||
|
173 | pushContext(state, stream.column(), "statement"); | |||
|
174 | state.startOfLine = false; | |||
|
175 | return style; | |||
|
176 | }, | |||
|
177 | ||||
|
178 | indent: function(state, textAfter) { | |||
|
179 | if (state.tokenize != tokenBase && state.tokenize != null) return 0; | |||
|
180 | var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); | |||
|
181 | if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; | |||
|
182 | var closing = firstChar == ctx.type; | |||
|
183 | if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit); | |||
|
184 | else if (ctx.align) return ctx.column + (closing ? 0 : 1); | |||
|
185 | else return ctx.indented + (closing ? 0 : indentUnit); | |||
|
186 | }, | |||
|
187 | ||||
|
188 | electricChars: "{}" | |||
|
189 | }; | |||
|
190 | }); | |||
|
191 | ||||
|
192 | CodeMirror.defineMIME("text/x-ecl", "ecl"); |
@@ -0,0 +1,39 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <title>CodeMirror: ECL mode</title> | |||
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
6 | <script src="../../lib/codemirror.js"></script> | |||
|
7 | <script src="ecl.js"></script> | |||
|
8 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
9 | <style>.CodeMirror {border: 1px solid black;}</style> | |||
|
10 | </head> | |||
|
11 | <body> | |||
|
12 | <h1>CodeMirror: ECL mode</h1> | |||
|
13 | <form><textarea id="code" name="code"> | |||
|
14 | /* | |||
|
15 | sample useless code to demonstrate ecl syntax highlighting | |||
|
16 | this is a multiline comment! | |||
|
17 | */ | |||
|
18 | ||||
|
19 | // this is a singleline comment! | |||
|
20 | ||||
|
21 | import ut; | |||
|
22 | r := | |||
|
23 | record | |||
|
24 | string22 s1 := '123'; | |||
|
25 | integer4 i1 := 123; | |||
|
26 | end; | |||
|
27 | #option('tmp', true); | |||
|
28 | d := dataset('tmp::qb', r, thor); | |||
|
29 | output(d); | |||
|
30 | </textarea></form> | |||
|
31 | <script> | |||
|
32 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | |||
|
33 | </script> | |||
|
34 | ||||
|
35 | <p>Based on CodeMirror's clike mode. For more information see <a href="http://hpccsystems.com">HPCC Systems</a> web site.</p> | |||
|
36 | <p><strong>MIME types defined:</strong> <code>text/x-ecl</code>.</p> | |||
|
37 | ||||
|
38 | </body> | |||
|
39 | </html> |
@@ -0,0 +1,464 b'' | |||||
|
1 | // block; "begin", "case", "fun", "if", "receive", "try": closed by "end" | |||
|
2 | // block internal; "after", "catch", "of" | |||
|
3 | // guard; "when", closed by "->" | |||
|
4 | // "->" opens a clause, closed by ";" or "." | |||
|
5 | // "<<" opens a binary, closed by ">>" | |||
|
6 | // "," appears in arglists, lists, tuples and terminates lines of code | |||
|
7 | // "." resets indentation to 0 | |||
|
8 | // obsolete; "cond", "let", "query" | |||
|
9 | ||||
|
10 | CodeMirror.defineMIME("text/x-erlang", "erlang"); | |||
|
11 | ||||
|
12 | CodeMirror.defineMode("erlang", function(cmCfg) { | |||
|
13 | ||||
|
14 | function rval(state,stream,type) { | |||
|
15 | // distinguish between "." as terminator and record field operator | |||
|
16 | if (type == "record") { | |||
|
17 | state.context = "record"; | |||
|
18 | }else{ | |||
|
19 | state.context = false; | |||
|
20 | } | |||
|
21 | ||||
|
22 | // remember last significant bit on last line for indenting | |||
|
23 | if (type != "whitespace" && type != "comment") { | |||
|
24 | state.lastToken = stream.current(); | |||
|
25 | } | |||
|
26 | // erlang -> CodeMirror tag | |||
|
27 | switch (type) { | |||
|
28 | case "atom": return "atom"; | |||
|
29 | case "attribute": return "attribute"; | |||
|
30 | case "builtin": return "builtin"; | |||
|
31 | case "comment": return "comment"; | |||
|
32 | case "fun": return "meta"; | |||
|
33 | case "function": return "tag"; | |||
|
34 | case "guard": return "property"; | |||
|
35 | case "keyword": return "keyword"; | |||
|
36 | case "macro": return "variable-2"; | |||
|
37 | case "number": return "number"; | |||
|
38 | case "operator": return "operator"; | |||
|
39 | case "record": return "bracket"; | |||
|
40 | case "string": return "string"; | |||
|
41 | case "type": return "def"; | |||
|
42 | case "variable": return "variable"; | |||
|
43 | case "error": return "error"; | |||
|
44 | case "separator": return null; | |||
|
45 | case "open_paren": return null; | |||
|
46 | case "close_paren": return null; | |||
|
47 | default: return null; | |||
|
48 | } | |||
|
49 | } | |||
|
50 | ||||
|
51 | var typeWords = [ | |||
|
52 | "-type", "-spec", "-export_type", "-opaque"]; | |||
|
53 | ||||
|
54 | var keywordWords = [ | |||
|
55 | "after","begin","catch","case","cond","end","fun","if", | |||
|
56 | "let","of","query","receive","try","when"]; | |||
|
57 | ||||
|
58 | var separatorWords = [ | |||
|
59 | "->",";",":",".",","]; | |||
|
60 | ||||
|
61 | var operatorWords = [ | |||
|
62 | "and","andalso","band","bnot","bor","bsl","bsr","bxor", | |||
|
63 | "div","not","or","orelse","rem","xor"]; | |||
|
64 | ||||
|
65 | var symbolWords = [ | |||
|
66 | "+","-","*","/",">",">=","<","=<","=:=","==","=/=","/=","||","<-"]; | |||
|
67 | ||||
|
68 | var openParenWords = [ | |||
|
69 | "<<","(","[","{"]; | |||
|
70 | ||||
|
71 | var closeParenWords = [ | |||
|
72 | "}","]",")",">>"]; | |||
|
73 | ||||
|
74 | var guardWords = [ | |||
|
75 | "is_atom","is_binary","is_bitstring","is_boolean","is_float", | |||
|
76 | "is_function","is_integer","is_list","is_number","is_pid", | |||
|
77 | "is_port","is_record","is_reference","is_tuple", | |||
|
78 | "atom","binary","bitstring","boolean","function","integer","list", | |||
|
79 | "number","pid","port","record","reference","tuple"]; | |||
|
80 | ||||
|
81 | var bifWords = [ | |||
|
82 | "abs","adler32","adler32_combine","alive","apply","atom_to_binary", | |||
|
83 | "atom_to_list","binary_to_atom","binary_to_existing_atom", | |||
|
84 | "binary_to_list","binary_to_term","bit_size","bitstring_to_list", | |||
|
85 | "byte_size","check_process_code","contact_binary","crc32", | |||
|
86 | "crc32_combine","date","decode_packet","delete_module", | |||
|
87 | "disconnect_node","element","erase","exit","float","float_to_list", | |||
|
88 | "garbage_collect","get","get_keys","group_leader","halt","hd", | |||
|
89 | "integer_to_list","internal_bif","iolist_size","iolist_to_binary", | |||
|
90 | "is_alive","is_atom","is_binary","is_bitstring","is_boolean", | |||
|
91 | "is_float","is_function","is_integer","is_list","is_number","is_pid", | |||
|
92 | "is_port","is_process_alive","is_record","is_reference","is_tuple", | |||
|
93 | "length","link","list_to_atom","list_to_binary","list_to_bitstring", | |||
|
94 | "list_to_existing_atom","list_to_float","list_to_integer", | |||
|
95 | "list_to_pid","list_to_tuple","load_module","make_ref","module_loaded", | |||
|
96 | "monitor_node","node","node_link","node_unlink","nodes","notalive", | |||
|
97 | "now","open_port","pid_to_list","port_close","port_command", | |||
|
98 | "port_connect","port_control","pre_loaded","process_flag", | |||
|
99 | "process_info","processes","purge_module","put","register", | |||
|
100 | "registered","round","self","setelement","size","spawn","spawn_link", | |||
|
101 | "spawn_monitor","spawn_opt","split_binary","statistics", | |||
|
102 | "term_to_binary","time","throw","tl","trunc","tuple_size", | |||
|
103 | "tuple_to_list","unlink","unregister","whereis"]; | |||
|
104 | ||||
|
105 | // ignored for indenting purposes | |||
|
106 | var ignoreWords = [ | |||
|
107 | ",", ":", "catch", "after", "of", "cond", "let", "query"]; | |||
|
108 | ||||
|
109 | ||||
|
110 | var smallRE = /[a-z_]/; | |||
|
111 | var largeRE = /[A-Z_]/; | |||
|
112 | var digitRE = /[0-9]/; | |||
|
113 | var octitRE = /[0-7]/; | |||
|
114 | var anumRE = /[a-z_A-Z0-9]/; | |||
|
115 | var symbolRE = /[\+\-\*\/<>=\|:]/; | |||
|
116 | var openParenRE = /[<\(\[\{]/; | |||
|
117 | var closeParenRE = /[>\)\]\}]/; | |||
|
118 | var sepRE = /[\->\.,:;]/; | |||
|
119 | ||||
|
120 | function isMember(element,list) { | |||
|
121 | return (-1 < list.indexOf(element)); | |||
|
122 | } | |||
|
123 | ||||
|
124 | function isPrev(stream,string) { | |||
|
125 | var start = stream.start; | |||
|
126 | var len = string.length; | |||
|
127 | if (len <= start) { | |||
|
128 | var word = stream.string.slice(start-len,start); | |||
|
129 | return word == string; | |||
|
130 | }else{ | |||
|
131 | return false; | |||
|
132 | } | |||
|
133 | } | |||
|
134 | ||||
|
135 | function tokenize(stream, state) { | |||
|
136 | if (stream.eatSpace()) { | |||
|
137 | return rval(state,stream,"whitespace"); | |||
|
138 | } | |||
|
139 | ||||
|
140 | // attributes and type specs | |||
|
141 | if ((peekToken(state).token == "" || peekToken(state).token == ".") && | |||
|
142 | stream.peek() == '-') { | |||
|
143 | stream.next(); | |||
|
144 | if (stream.eat(smallRE) && stream.eatWhile(anumRE)) { | |||
|
145 | if (isMember(stream.current(),typeWords)) { | |||
|
146 | return rval(state,stream,"type"); | |||
|
147 | }else{ | |||
|
148 | return rval(state,stream,"attribute"); | |||
|
149 | } | |||
|
150 | } | |||
|
151 | stream.backUp(1); | |||
|
152 | } | |||
|
153 | ||||
|
154 | var ch = stream.next(); | |||
|
155 | ||||
|
156 | // comment | |||
|
157 | if (ch == '%') { | |||
|
158 | stream.skipToEnd(); | |||
|
159 | return rval(state,stream,"comment"); | |||
|
160 | } | |||
|
161 | ||||
|
162 | // macro | |||
|
163 | if (ch == '?') { | |||
|
164 | stream.eatWhile(anumRE); | |||
|
165 | return rval(state,stream,"macro"); | |||
|
166 | } | |||
|
167 | ||||
|
168 | // record | |||
|
169 | if ( ch == "#") { | |||
|
170 | stream.eatWhile(anumRE); | |||
|
171 | return rval(state,stream,"record"); | |||
|
172 | } | |||
|
173 | ||||
|
174 | // char | |||
|
175 | if ( ch == "$") { | |||
|
176 | if (stream.next() == "\\") { | |||
|
177 | if (!stream.eatWhile(octitRE)) { | |||
|
178 | stream.next(); | |||
|
179 | } | |||
|
180 | } | |||
|
181 | return rval(state,stream,"string"); | |||
|
182 | } | |||
|
183 | ||||
|
184 | // quoted atom | |||
|
185 | if (ch == '\'') { | |||
|
186 | if (singleQuote(stream)) { | |||
|
187 | return rval(state,stream,"atom"); | |||
|
188 | }else{ | |||
|
189 | return rval(state,stream,"error"); | |||
|
190 | } | |||
|
191 | } | |||
|
192 | ||||
|
193 | // string | |||
|
194 | if (ch == '"') { | |||
|
195 | if (doubleQuote(stream)) { | |||
|
196 | return rval(state,stream,"string"); | |||
|
197 | }else{ | |||
|
198 | return rval(state,stream,"error"); | |||
|
199 | } | |||
|
200 | } | |||
|
201 | ||||
|
202 | // variable | |||
|
203 | if (largeRE.test(ch)) { | |||
|
204 | stream.eatWhile(anumRE); | |||
|
205 | return rval(state,stream,"variable"); | |||
|
206 | } | |||
|
207 | ||||
|
208 | // atom/keyword/BIF/function | |||
|
209 | if (smallRE.test(ch)) { | |||
|
210 | stream.eatWhile(anumRE); | |||
|
211 | ||||
|
212 | if (stream.peek() == "/") { | |||
|
213 | stream.next(); | |||
|
214 | if (stream.eatWhile(digitRE)) { | |||
|
215 | return rval(state,stream,"fun"); // f/0 style fun | |||
|
216 | }else{ | |||
|
217 | stream.backUp(1); | |||
|
218 | return rval(state,stream,"atom"); | |||
|
219 | } | |||
|
220 | } | |||
|
221 | ||||
|
222 | var w = stream.current(); | |||
|
223 | ||||
|
224 | if (isMember(w,keywordWords)) { | |||
|
225 | pushToken(state,stream); | |||
|
226 | return rval(state,stream,"keyword"); | |||
|
227 | } | |||
|
228 | if (stream.peek() == "(") { | |||
|
229 | // 'put' and 'erlang:put' are bifs, 'foo:put' is not | |||
|
230 | if (isMember(w,bifWords) && | |||
|
231 | (!isPrev(stream,":") || isPrev(stream,"erlang:"))) { | |||
|
232 | return rval(state,stream,"builtin"); | |||
|
233 | }else{ | |||
|
234 | return rval(state,stream,"function"); | |||
|
235 | } | |||
|
236 | } | |||
|
237 | if (isMember(w,guardWords)) { | |||
|
238 | return rval(state,stream,"guard"); | |||
|
239 | } | |||
|
240 | if (isMember(w,operatorWords)) { | |||
|
241 | return rval(state,stream,"operator"); | |||
|
242 | } | |||
|
243 | if (stream.peek() == ":") { | |||
|
244 | if (w == "erlang") { | |||
|
245 | return rval(state,stream,"builtin"); | |||
|
246 | } else { | |||
|
247 | return rval(state,stream,"function"); | |||
|
248 | } | |||
|
249 | } | |||
|
250 | return rval(state,stream,"atom"); | |||
|
251 | } | |||
|
252 | ||||
|
253 | // number | |||
|
254 | if (digitRE.test(ch)) { | |||
|
255 | stream.eatWhile(digitRE); | |||
|
256 | if (stream.eat('#')) { | |||
|
257 | stream.eatWhile(digitRE); // 16#10 style integer | |||
|
258 | } else { | |||
|
259 | if (stream.eat('.')) { // float | |||
|
260 | stream.eatWhile(digitRE); | |||
|
261 | } | |||
|
262 | if (stream.eat(/[eE]/)) { | |||
|
263 | stream.eat(/[-+]/); // float with exponent | |||
|
264 | stream.eatWhile(digitRE); | |||
|
265 | } | |||
|
266 | } | |||
|
267 | return rval(state,stream,"number"); // normal integer | |||
|
268 | } | |||
|
269 | ||||
|
270 | // open parens | |||
|
271 | if (nongreedy(stream,openParenRE,openParenWords)) { | |||
|
272 | pushToken(state,stream); | |||
|
273 | return rval(state,stream,"open_paren"); | |||
|
274 | } | |||
|
275 | ||||
|
276 | // close parens | |||
|
277 | if (nongreedy(stream,closeParenRE,closeParenWords)) { | |||
|
278 | pushToken(state,stream); | |||
|
279 | return rval(state,stream,"close_paren"); | |||
|
280 | } | |||
|
281 | ||||
|
282 | // separators | |||
|
283 | if (greedy(stream,sepRE,separatorWords)) { | |||
|
284 | // distinguish between "." as terminator and record field operator | |||
|
285 | if (state.context == false) { | |||
|
286 | pushToken(state,stream); | |||
|
287 | } | |||
|
288 | return rval(state,stream,"separator"); | |||
|
289 | } | |||
|
290 | ||||
|
291 | // operators | |||
|
292 | if (greedy(stream,symbolRE,symbolWords)) { | |||
|
293 | return rval(state,stream,"operator"); | |||
|
294 | } | |||
|
295 | ||||
|
296 | return rval(state,stream,null); | |||
|
297 | } | |||
|
298 | ||||
|
299 | function nongreedy(stream,re,words) { | |||
|
300 | if (stream.current().length == 1 && re.test(stream.current())) { | |||
|
301 | stream.backUp(1); | |||
|
302 | while (re.test(stream.peek())) { | |||
|
303 | stream.next(); | |||
|
304 | if (isMember(stream.current(),words)) { | |||
|
305 | return true; | |||
|
306 | } | |||
|
307 | } | |||
|
308 | stream.backUp(stream.current().length-1); | |||
|
309 | } | |||
|
310 | return false; | |||
|
311 | } | |||
|
312 | ||||
|
313 | function greedy(stream,re,words) { | |||
|
314 | if (stream.current().length == 1 && re.test(stream.current())) { | |||
|
315 | while (re.test(stream.peek())) { | |||
|
316 | stream.next(); | |||
|
317 | } | |||
|
318 | while (0 < stream.current().length) { | |||
|
319 | if (isMember(stream.current(),words)) { | |||
|
320 | return true; | |||
|
321 | }else{ | |||
|
322 | stream.backUp(1); | |||
|
323 | } | |||
|
324 | } | |||
|
325 | stream.next(); | |||
|
326 | } | |||
|
327 | return false; | |||
|
328 | } | |||
|
329 | ||||
|
330 | function doubleQuote(stream) { | |||
|
331 | return quote(stream, '"', '\\'); | |||
|
332 | } | |||
|
333 | ||||
|
334 | function singleQuote(stream) { | |||
|
335 | return quote(stream,'\'','\\'); | |||
|
336 | } | |||
|
337 | ||||
|
338 | function quote(stream,quoteChar,escapeChar) { | |||
|
339 | while (!stream.eol()) { | |||
|
340 | var ch = stream.next(); | |||
|
341 | if (ch == quoteChar) { | |||
|
342 | return true; | |||
|
343 | }else if (ch == escapeChar) { | |||
|
344 | stream.next(); | |||
|
345 | } | |||
|
346 | } | |||
|
347 | return false; | |||
|
348 | } | |||
|
349 | ||||
|
350 | function Token(stream) { | |||
|
351 | this.token = stream ? stream.current() : ""; | |||
|
352 | this.column = stream ? stream.column() : 0; | |||
|
353 | this.indent = stream ? stream.indentation() : 0; | |||
|
354 | } | |||
|
355 | ||||
|
356 | function myIndent(state,textAfter) { | |||
|
357 | var indent = cmCfg.indentUnit; | |||
|
358 | var outdentWords = ["after","catch"]; | |||
|
359 | var token = (peekToken(state)).token; | |||
|
360 | var wordAfter = takewhile(textAfter,/[^a-z]/); | |||
|
361 | ||||
|
362 | if (isMember(token,openParenWords)) { | |||
|
363 | return (peekToken(state)).column+token.length; | |||
|
364 | }else if (token == "." || token == ""){ | |||
|
365 | return 0; | |||
|
366 | }else if (token == "->") { | |||
|
367 | if (wordAfter == "end") { | |||
|
368 | return peekToken(state,2).column; | |||
|
369 | }else if (peekToken(state,2).token == "fun") { | |||
|
370 | return peekToken(state,2).column+indent; | |||
|
371 | }else{ | |||
|
372 | return (peekToken(state)).indent+indent; | |||
|
373 | } | |||
|
374 | }else if (isMember(wordAfter,outdentWords)) { | |||
|
375 | return (peekToken(state)).indent; | |||
|
376 | }else{ | |||
|
377 | return (peekToken(state)).column+indent; | |||
|
378 | } | |||
|
379 | } | |||
|
380 | ||||
|
381 | function takewhile(str,re) { | |||
|
382 | var m = str.match(re); | |||
|
383 | return m ? str.slice(0,m.index) : str; | |||
|
384 | } | |||
|
385 | ||||
|
386 | function popToken(state) { | |||
|
387 | return state.tokenStack.pop(); | |||
|
388 | } | |||
|
389 | ||||
|
390 | function peekToken(state,depth) { | |||
|
391 | var len = state.tokenStack.length; | |||
|
392 | var dep = (depth ? depth : 1); | |||
|
393 | if (len < dep) { | |||
|
394 | return new Token; | |||
|
395 | }else{ | |||
|
396 | return state.tokenStack[len-dep]; | |||
|
397 | } | |||
|
398 | } | |||
|
399 | ||||
|
400 | function pushToken(state,stream) { | |||
|
401 | var token = stream.current(); | |||
|
402 | var prev_token = peekToken(state).token; | |||
|
403 | if (isMember(token,ignoreWords)) { | |||
|
404 | return false; | |||
|
405 | }else if (drop_both(prev_token,token)) { | |||
|
406 | popToken(state); | |||
|
407 | return false; | |||
|
408 | }else if (drop_first(prev_token,token)) { | |||
|
409 | popToken(state); | |||
|
410 | return pushToken(state,stream); | |||
|
411 | }else{ | |||
|
412 | state.tokenStack.push(new Token(stream)); | |||
|
413 | return true; | |||
|
414 | } | |||
|
415 | } | |||
|
416 | ||||
|
417 | function drop_first(open, close) { | |||
|
418 | switch (open+" "+close) { | |||
|
419 | case "when ->": return true; | |||
|
420 | case "-> end": return true; | |||
|
421 | case "-> .": return true; | |||
|
422 | case ". .": return true; | |||
|
423 | default: return false; | |||
|
424 | } | |||
|
425 | } | |||
|
426 | ||||
|
427 | function drop_both(open, close) { | |||
|
428 | switch (open+" "+close) { | |||
|
429 | case "( )": return true; | |||
|
430 | case "[ ]": return true; | |||
|
431 | case "{ }": return true; | |||
|
432 | case "<< >>": return true; | |||
|
433 | case "begin end": return true; | |||
|
434 | case "case end": return true; | |||
|
435 | case "fun end": return true; | |||
|
436 | case "if end": return true; | |||
|
437 | case "receive end": return true; | |||
|
438 | case "try end": return true; | |||
|
439 | case "-> ;": return true; | |||
|
440 | default: return false; | |||
|
441 | } | |||
|
442 | } | |||
|
443 | ||||
|
444 | return { | |||
|
445 | startState: | |||
|
446 | function() { | |||
|
447 | return {tokenStack: [], | |||
|
448 | context: false, | |||
|
449 | lastToken: null}; | |||
|
450 | }, | |||
|
451 | ||||
|
452 | token: | |||
|
453 | function(stream, state) { | |||
|
454 | return tokenize(stream, state); | |||
|
455 | }, | |||
|
456 | ||||
|
457 | indent: | |||
|
458 | function(state, textAfter) { | |||
|
459 | return myIndent(state,textAfter); | |||
|
460 | }, | |||
|
461 | ||||
|
462 | lineComment: "%" | |||
|
463 | }; | |||
|
464 | }); |
@@ -0,0 +1,64 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Erlang mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="erlang.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../theme/erlang-dark.css"> | |||
|
11 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
12 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
13 | </head> | |||
|
14 | <body> | |||
|
15 | <h1>CodeMirror: Erlang mode</h1> | |||
|
16 | ||||
|
17 | <form><textarea id="code" name="code"> | |||
|
18 | %% -*- mode: erlang; erlang-indent-level: 2 -*- | |||
|
19 | %%% Created : 7 May 2012 by mats cronqvist <masse@klarna.com> | |||
|
20 | ||||
|
21 | %% @doc | |||
|
22 | %% Demonstrates how to print a record. | |||
|
23 | %% @end | |||
|
24 | ||||
|
25 | -module('ex'). | |||
|
26 | -author('mats cronqvist'). | |||
|
27 | -export([demo/0, | |||
|
28 | rec_info/1]). | |||
|
29 | ||||
|
30 | -record(demo,{a="One",b="Two",c="Three",d="Four"}). | |||
|
31 | ||||
|
32 | rec_info(demo) -> record_info(fields,demo). | |||
|
33 | ||||
|
34 | demo() -> expand_recs(?MODULE,#demo{a="A",b="BB"}). | |||
|
35 | ||||
|
36 | expand_recs(M,List) when is_list(List) -> | |||
|
37 | [expand_recs(M,L)||L<-List]; | |||
|
38 | expand_recs(M,Tup) when is_tuple(Tup) -> | |||
|
39 | case tuple_size(Tup) of | |||
|
40 | L when L < 1 -> Tup; | |||
|
41 | L -> | |||
|
42 | try Fields = M:rec_info(element(1,Tup)), | |||
|
43 | L = length(Fields)+1, | |||
|
44 | lists:zip(Fields,expand_recs(M,tl(tuple_to_list(Tup)))) | |||
|
45 | catch _:_ -> | |||
|
46 | list_to_tuple(expand_recs(M,tuple_to_list(Tup))) | |||
|
47 | end | |||
|
48 | end; | |||
|
49 | expand_recs(_,Term) -> | |||
|
50 | Term. | |||
|
51 | </textarea></form> | |||
|
52 | ||||
|
53 | <script> | |||
|
54 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
55 | lineNumbers: true, | |||
|
56 | matchBrackets: true, | |||
|
57 | extraKeys: {"Tab": "indentAuto"}, | |||
|
58 | theme: "erlang-dark" | |||
|
59 | }); | |||
|
60 | </script> | |||
|
61 | ||||
|
62 | <p><strong>MIME types defined:</strong> <code>text/x-erlang</code>.</p> | |||
|
63 | </body> | |||
|
64 | </html> |
@@ -0,0 +1,330 b'' | |||||
|
1 | CodeMirror.defineMode("gas", function(_config, parserConfig) { | |||
|
2 | 'use strict'; | |||
|
3 | ||||
|
4 | // If an architecture is specified, its initialization function may | |||
|
5 | // populate this array with custom parsing functions which will be | |||
|
6 | // tried in the event that the standard functions do not find a match. | |||
|
7 | var custom = []; | |||
|
8 | ||||
|
9 | // The symbol used to start a line comment changes based on the target | |||
|
10 | // architecture. | |||
|
11 | // If no architecture is pased in "parserConfig" then only multiline | |||
|
12 | // comments will have syntax support. | |||
|
13 | var lineCommentStartSymbol = ""; | |||
|
14 | ||||
|
15 | // These directives are architecture independent. | |||
|
16 | // Machine specific directives should go in their respective | |||
|
17 | // architecture initialization function. | |||
|
18 | // Reference: | |||
|
19 | // http://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops | |||
|
20 | var directives = { | |||
|
21 | ".abort" : "builtin", | |||
|
22 | ".align" : "builtin", | |||
|
23 | ".altmacro" : "builtin", | |||
|
24 | ".ascii" : "builtin", | |||
|
25 | ".asciz" : "builtin", | |||
|
26 | ".balign" : "builtin", | |||
|
27 | ".balignw" : "builtin", | |||
|
28 | ".balignl" : "builtin", | |||
|
29 | ".bundle_align_mode" : "builtin", | |||
|
30 | ".bundle_lock" : "builtin", | |||
|
31 | ".bundle_unlock" : "builtin", | |||
|
32 | ".byte" : "builtin", | |||
|
33 | ".cfi_startproc" : "builtin", | |||
|
34 | ".comm" : "builtin", | |||
|
35 | ".data" : "builtin", | |||
|
36 | ".def" : "builtin", | |||
|
37 | ".desc" : "builtin", | |||
|
38 | ".dim" : "builtin", | |||
|
39 | ".double" : "builtin", | |||
|
40 | ".eject" : "builtin", | |||
|
41 | ".else" : "builtin", | |||
|
42 | ".elseif" : "builtin", | |||
|
43 | ".end" : "builtin", | |||
|
44 | ".endef" : "builtin", | |||
|
45 | ".endfunc" : "builtin", | |||
|
46 | ".endif" : "builtin", | |||
|
47 | ".equ" : "builtin", | |||
|
48 | ".equiv" : "builtin", | |||
|
49 | ".eqv" : "builtin", | |||
|
50 | ".err" : "builtin", | |||
|
51 | ".error" : "builtin", | |||
|
52 | ".exitm" : "builtin", | |||
|
53 | ".extern" : "builtin", | |||
|
54 | ".fail" : "builtin", | |||
|
55 | ".file" : "builtin", | |||
|
56 | ".fill" : "builtin", | |||
|
57 | ".float" : "builtin", | |||
|
58 | ".func" : "builtin", | |||
|
59 | ".global" : "builtin", | |||
|
60 | ".gnu_attribute" : "builtin", | |||
|
61 | ".hidden" : "builtin", | |||
|
62 | ".hword" : "builtin", | |||
|
63 | ".ident" : "builtin", | |||
|
64 | ".if" : "builtin", | |||
|
65 | ".incbin" : "builtin", | |||
|
66 | ".include" : "builtin", | |||
|
67 | ".int" : "builtin", | |||
|
68 | ".internal" : "builtin", | |||
|
69 | ".irp" : "builtin", | |||
|
70 | ".irpc" : "builtin", | |||
|
71 | ".lcomm" : "builtin", | |||
|
72 | ".lflags" : "builtin", | |||
|
73 | ".line" : "builtin", | |||
|
74 | ".linkonce" : "builtin", | |||
|
75 | ".list" : "builtin", | |||
|
76 | ".ln" : "builtin", | |||
|
77 | ".loc" : "builtin", | |||
|
78 | ".loc_mark_labels" : "builtin", | |||
|
79 | ".local" : "builtin", | |||
|
80 | ".long" : "builtin", | |||
|
81 | ".macro" : "builtin", | |||
|
82 | ".mri" : "builtin", | |||
|
83 | ".noaltmacro" : "builtin", | |||
|
84 | ".nolist" : "builtin", | |||
|
85 | ".octa" : "builtin", | |||
|
86 | ".offset" : "builtin", | |||
|
87 | ".org" : "builtin", | |||
|
88 | ".p2align" : "builtin", | |||
|
89 | ".popsection" : "builtin", | |||
|
90 | ".previous" : "builtin", | |||
|
91 | ".print" : "builtin", | |||
|
92 | ".protected" : "builtin", | |||
|
93 | ".psize" : "builtin", | |||
|
94 | ".purgem" : "builtin", | |||
|
95 | ".pushsection" : "builtin", | |||
|
96 | ".quad" : "builtin", | |||
|
97 | ".reloc" : "builtin", | |||
|
98 | ".rept" : "builtin", | |||
|
99 | ".sbttl" : "builtin", | |||
|
100 | ".scl" : "builtin", | |||
|
101 | ".section" : "builtin", | |||
|
102 | ".set" : "builtin", | |||
|
103 | ".short" : "builtin", | |||
|
104 | ".single" : "builtin", | |||
|
105 | ".size" : "builtin", | |||
|
106 | ".skip" : "builtin", | |||
|
107 | ".sleb128" : "builtin", | |||
|
108 | ".space" : "builtin", | |||
|
109 | ".stab" : "builtin", | |||
|
110 | ".string" : "builtin", | |||
|
111 | ".struct" : "builtin", | |||
|
112 | ".subsection" : "builtin", | |||
|
113 | ".symver" : "builtin", | |||
|
114 | ".tag" : "builtin", | |||
|
115 | ".text" : "builtin", | |||
|
116 | ".title" : "builtin", | |||
|
117 | ".type" : "builtin", | |||
|
118 | ".uleb128" : "builtin", | |||
|
119 | ".val" : "builtin", | |||
|
120 | ".version" : "builtin", | |||
|
121 | ".vtable_entry" : "builtin", | |||
|
122 | ".vtable_inherit" : "builtin", | |||
|
123 | ".warning" : "builtin", | |||
|
124 | ".weak" : "builtin", | |||
|
125 | ".weakref" : "builtin", | |||
|
126 | ".word" : "builtin" | |||
|
127 | }; | |||
|
128 | ||||
|
129 | var registers = {}; | |||
|
130 | ||||
|
131 | function x86(_parserConfig) { | |||
|
132 | lineCommentStartSymbol = "#"; | |||
|
133 | ||||
|
134 | registers.ax = "variable"; | |||
|
135 | registers.eax = "variable-2"; | |||
|
136 | registers.rax = "variable-3"; | |||
|
137 | ||||
|
138 | registers.bx = "variable"; | |||
|
139 | registers.ebx = "variable-2"; | |||
|
140 | registers.rbx = "variable-3"; | |||
|
141 | ||||
|
142 | registers.cx = "variable"; | |||
|
143 | registers.ecx = "variable-2"; | |||
|
144 | registers.rcx = "variable-3"; | |||
|
145 | ||||
|
146 | registers.dx = "variable"; | |||
|
147 | registers.edx = "variable-2"; | |||
|
148 | registers.rdx = "variable-3"; | |||
|
149 | ||||
|
150 | registers.si = "variable"; | |||
|
151 | registers.esi = "variable-2"; | |||
|
152 | registers.rsi = "variable-3"; | |||
|
153 | ||||
|
154 | registers.di = "variable"; | |||
|
155 | registers.edi = "variable-2"; | |||
|
156 | registers.rdi = "variable-3"; | |||
|
157 | ||||
|
158 | registers.sp = "variable"; | |||
|
159 | registers.esp = "variable-2"; | |||
|
160 | registers.rsp = "variable-3"; | |||
|
161 | ||||
|
162 | registers.bp = "variable"; | |||
|
163 | registers.ebp = "variable-2"; | |||
|
164 | registers.rbp = "variable-3"; | |||
|
165 | ||||
|
166 | registers.ip = "variable"; | |||
|
167 | registers.eip = "variable-2"; | |||
|
168 | registers.rip = "variable-3"; | |||
|
169 | ||||
|
170 | registers.cs = "keyword"; | |||
|
171 | registers.ds = "keyword"; | |||
|
172 | registers.ss = "keyword"; | |||
|
173 | registers.es = "keyword"; | |||
|
174 | registers.fs = "keyword"; | |||
|
175 | registers.gs = "keyword"; | |||
|
176 | } | |||
|
177 | ||||
|
178 | function armv6(_parserConfig) { | |||
|
179 | // Reference: | |||
|
180 | // http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf | |||
|
181 | // http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf | |||
|
182 | lineCommentStartSymbol = "@"; | |||
|
183 | directives.syntax = "builtin"; | |||
|
184 | ||||
|
185 | registers.r0 = "variable"; | |||
|
186 | registers.r1 = "variable"; | |||
|
187 | registers.r2 = "variable"; | |||
|
188 | registers.r3 = "variable"; | |||
|
189 | registers.r4 = "variable"; | |||
|
190 | registers.r5 = "variable"; | |||
|
191 | registers.r6 = "variable"; | |||
|
192 | registers.r7 = "variable"; | |||
|
193 | registers.r8 = "variable"; | |||
|
194 | registers.r9 = "variable"; | |||
|
195 | registers.r10 = "variable"; | |||
|
196 | registers.r11 = "variable"; | |||
|
197 | registers.r12 = "variable"; | |||
|
198 | ||||
|
199 | registers.sp = "variable-2"; | |||
|
200 | registers.lr = "variable-2"; | |||
|
201 | registers.pc = "variable-2"; | |||
|
202 | registers.r13 = registers.sp; | |||
|
203 | registers.r14 = registers.lr; | |||
|
204 | registers.r15 = registers.pc; | |||
|
205 | ||||
|
206 | custom.push(function(ch, stream) { | |||
|
207 | if (ch === '#') { | |||
|
208 | stream.eatWhile(/\w/); | |||
|
209 | return "number"; | |||
|
210 | } | |||
|
211 | }); | |||
|
212 | } | |||
|
213 | ||||
|
214 | var arch = parserConfig.architecture.toLowerCase(); | |||
|
215 | if (arch === "x86") { | |||
|
216 | x86(parserConfig); | |||
|
217 | } else if (arch === "arm" || arch === "armv6") { | |||
|
218 | armv6(parserConfig); | |||
|
219 | } | |||
|
220 | ||||
|
221 | function nextUntilUnescaped(stream, end) { | |||
|
222 | var escaped = false, next; | |||
|
223 | while ((next = stream.next()) != null) { | |||
|
224 | if (next === end && !escaped) { | |||
|
225 | return false; | |||
|
226 | } | |||
|
227 | escaped = !escaped && next === "\\"; | |||
|
228 | } | |||
|
229 | return escaped; | |||
|
230 | } | |||
|
231 | ||||
|
232 | function clikeComment(stream, state) { | |||
|
233 | var maybeEnd = false, ch; | |||
|
234 | while ((ch = stream.next()) != null) { | |||
|
235 | if (ch === "/" && maybeEnd) { | |||
|
236 | state.tokenize = null; | |||
|
237 | break; | |||
|
238 | } | |||
|
239 | maybeEnd = (ch === "*"); | |||
|
240 | } | |||
|
241 | return "comment"; | |||
|
242 | } | |||
|
243 | ||||
|
244 | return { | |||
|
245 | startState: function() { | |||
|
246 | return { | |||
|
247 | tokenize: null | |||
|
248 | }; | |||
|
249 | }, | |||
|
250 | ||||
|
251 | token: function(stream, state) { | |||
|
252 | if (state.tokenize) { | |||
|
253 | return state.tokenize(stream, state); | |||
|
254 | } | |||
|
255 | ||||
|
256 | if (stream.eatSpace()) { | |||
|
257 | return null; | |||
|
258 | } | |||
|
259 | ||||
|
260 | var style, cur, ch = stream.next(); | |||
|
261 | ||||
|
262 | if (ch === "/") { | |||
|
263 | if (stream.eat("*")) { | |||
|
264 | state.tokenize = clikeComment; | |||
|
265 | return clikeComment(stream, state); | |||
|
266 | } | |||
|
267 | } | |||
|
268 | ||||
|
269 | if (ch === lineCommentStartSymbol) { | |||
|
270 | stream.skipToEnd(); | |||
|
271 | return "comment"; | |||
|
272 | } | |||
|
273 | ||||
|
274 | if (ch === '"') { | |||
|
275 | nextUntilUnescaped(stream, '"'); | |||
|
276 | return "string"; | |||
|
277 | } | |||
|
278 | ||||
|
279 | if (ch === '.') { | |||
|
280 | stream.eatWhile(/\w/); | |||
|
281 | cur = stream.current().toLowerCase(); | |||
|
282 | style = directives[cur]; | |||
|
283 | return style || null; | |||
|
284 | } | |||
|
285 | ||||
|
286 | if (ch === '=') { | |||
|
287 | stream.eatWhile(/\w/); | |||
|
288 | return "tag"; | |||
|
289 | } | |||
|
290 | ||||
|
291 | if (ch === '{') { | |||
|
292 | return "braket"; | |||
|
293 | } | |||
|
294 | ||||
|
295 | if (ch === '}') { | |||
|
296 | return "braket"; | |||
|
297 | } | |||
|
298 | ||||
|
299 | if (/\d/.test(ch)) { | |||
|
300 | if (ch === "0" && stream.eat("x")) { | |||
|
301 | stream.eatWhile(/[0-9a-fA-F]/); | |||
|
302 | return "number"; | |||
|
303 | } | |||
|
304 | stream.eatWhile(/\d/); | |||
|
305 | return "number"; | |||
|
306 | } | |||
|
307 | ||||
|
308 | if (/\w/.test(ch)) { | |||
|
309 | stream.eatWhile(/\w/); | |||
|
310 | if (stream.eat(":")) { | |||
|
311 | return 'tag'; | |||
|
312 | } | |||
|
313 | cur = stream.current().toLowerCase(); | |||
|
314 | style = registers[cur]; | |||
|
315 | return style || null; | |||
|
316 | } | |||
|
317 | ||||
|
318 | for (var i = 0; i < custom.length; i++) { | |||
|
319 | style = custom[i](ch, stream, state); | |||
|
320 | if (style) { | |||
|
321 | return style; | |||
|
322 | } | |||
|
323 | } | |||
|
324 | }, | |||
|
325 | ||||
|
326 | lineComment: lineCommentStartSymbol, | |||
|
327 | blockCommentStart: "/*", | |||
|
328 | blockCommentEnd: "*/" | |||
|
329 | }; | |||
|
330 | }); |
@@ -0,0 +1,57 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Gas mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="gas.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style>.CodeMirror {border: 2px inset #dee;}</style> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Gas mode</h1> | |||
|
14 | ||||
|
15 | <form> | |||
|
16 | <textarea id="code" name="code"> | |||
|
17 | .syntax unified | |||
|
18 | .global main | |||
|
19 | ||||
|
20 | /* | |||
|
21 | * A | |||
|
22 | * multi-line | |||
|
23 | * comment. | |||
|
24 | */ | |||
|
25 | ||||
|
26 | @ A single line comment. | |||
|
27 | ||||
|
28 | main: | |||
|
29 | push {sp, lr} | |||
|
30 | ldr r0, =message | |||
|
31 | bl puts | |||
|
32 | mov r0, #0 | |||
|
33 | pop {sp, pc} | |||
|
34 | ||||
|
35 | message: | |||
|
36 | .asciz "Hello world!<br />" | |||
|
37 | </textarea> | |||
|
38 | </form> | |||
|
39 | ||||
|
40 | <script> | |||
|
41 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
42 | lineNumbers: true, | |||
|
43 | mode: {name: "gas", architecture: "ARMv6"}, | |||
|
44 | }); | |||
|
45 | </script> | |||
|
46 | ||||
|
47 | <p>Handles AT&T assembler syntax (more specifically this handles | |||
|
48 | the GNU Assembler (gas) syntax.) | |||
|
49 | It takes a single optional configuration parameter: | |||
|
50 | <code>architecture</code>, which can be one of <code>"ARM"</code>, | |||
|
51 | <code>"ARMv6"</code> or <code>"x86"</code>. | |||
|
52 | Including the parameter adds syntax for the registers and special | |||
|
53 | directives for the supplied architecture. | |||
|
54 | ||||
|
55 | <p><strong>MIME types defined:</strong> <code>text/x-gas</code></p> | |||
|
56 | </body> | |||
|
57 | </html> |
@@ -0,0 +1,96 b'' | |||||
|
1 | CodeMirror.defineMode("gfm", function(config) { | |||
|
2 | var codeDepth = 0; | |||
|
3 | function blankLine(state) { | |||
|
4 | state.code = false; | |||
|
5 | return null; | |||
|
6 | } | |||
|
7 | var gfmOverlay = { | |||
|
8 | startState: function() { | |||
|
9 | return { | |||
|
10 | code: false, | |||
|
11 | codeBlock: false, | |||
|
12 | ateSpace: false | |||
|
13 | }; | |||
|
14 | }, | |||
|
15 | copyState: function(s) { | |||
|
16 | return { | |||
|
17 | code: s.code, | |||
|
18 | codeBlock: s.codeBlock, | |||
|
19 | ateSpace: s.ateSpace | |||
|
20 | }; | |||
|
21 | }, | |||
|
22 | token: function(stream, state) { | |||
|
23 | // Hack to prevent formatting override inside code blocks (block and inline) | |||
|
24 | if (state.codeBlock) { | |||
|
25 | if (stream.match(/^```/)) { | |||
|
26 | state.codeBlock = false; | |||
|
27 | return null; | |||
|
28 | } | |||
|
29 | stream.skipToEnd(); | |||
|
30 | return null; | |||
|
31 | } | |||
|
32 | if (stream.sol()) { | |||
|
33 | state.code = false; | |||
|
34 | } | |||
|
35 | if (stream.sol() && stream.match(/^```/)) { | |||
|
36 | stream.skipToEnd(); | |||
|
37 | state.codeBlock = true; | |||
|
38 | return null; | |||
|
39 | } | |||
|
40 | // If this block is changed, it may need to be updated in Markdown mode | |||
|
41 | if (stream.peek() === '`') { | |||
|
42 | stream.next(); | |||
|
43 | var before = stream.pos; | |||
|
44 | stream.eatWhile('`'); | |||
|
45 | var difference = 1 + stream.pos - before; | |||
|
46 | if (!state.code) { | |||
|
47 | codeDepth = difference; | |||
|
48 | state.code = true; | |||
|
49 | } else { | |||
|
50 | if (difference === codeDepth) { // Must be exact | |||
|
51 | state.code = false; | |||
|
52 | } | |||
|
53 | } | |||
|
54 | return null; | |||
|
55 | } else if (state.code) { | |||
|
56 | stream.next(); | |||
|
57 | return null; | |||
|
58 | } | |||
|
59 | // Check if space. If so, links can be formatted later on | |||
|
60 | if (stream.eatSpace()) { | |||
|
61 | state.ateSpace = true; | |||
|
62 | return null; | |||
|
63 | } | |||
|
64 | if (stream.sol() || state.ateSpace) { | |||
|
65 | state.ateSpace = false; | |||
|
66 | if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) { | |||
|
67 | // User/Project@SHA | |||
|
68 | // User@SHA | |||
|
69 | // SHA | |||
|
70 | return "link"; | |||
|
71 | } else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) { | |||
|
72 | // User/Project#Num | |||
|
73 | // User#Num | |||
|
74 | // #Num | |||
|
75 | return "link"; | |||
|
76 | } | |||
|
77 | } | |||
|
78 | if (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i)) { | |||
|
79 | // URLs | |||
|
80 | // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls | |||
|
81 | // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine | |||
|
82 | return "link"; | |||
|
83 | } | |||
|
84 | stream.next(); | |||
|
85 | return null; | |||
|
86 | }, | |||
|
87 | blankLine: blankLine | |||
|
88 | }; | |||
|
89 | CodeMirror.defineMIME("gfmBase", { | |||
|
90 | name: "markdown", | |||
|
91 | underscoresBreakWords: false, | |||
|
92 | taskLists: true, | |||
|
93 | fencedCodeBlocks: true | |||
|
94 | }); | |||
|
95 | return CodeMirror.overlayMode(CodeMirror.getMode(config, "gfmBase"), gfmOverlay); | |||
|
96 | }, "markdown"); |
@@ -0,0 +1,74 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: GFM mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/mode/overlay.js"></script> | |||
|
9 | <script src="../xml/xml.js"></script> | |||
|
10 | <script src="../markdown/markdown.js"></script> | |||
|
11 | <script src="gfm.js"></script> | |||
|
12 | ||||
|
13 | <!-- Code block highlighting modes --> | |||
|
14 | <script src="../javascript/javascript.js"></script> | |||
|
15 | <script src="../css/css.js"></script> | |||
|
16 | <script src="../htmlmixed/htmlmixed.js"></script> | |||
|
17 | <script src="../clike/clike.js"></script> | |||
|
18 | ||||
|
19 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
20 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
21 | </head> | |||
|
22 | <body> | |||
|
23 | <h1>CodeMirror: GFM mode</h1> | |||
|
24 | ||||
|
25 | <form><textarea id="code" name="code"> | |||
|
26 | GitHub Flavored Markdown | |||
|
27 | ======================== | |||
|
28 | ||||
|
29 | Everything from markdown plus GFM features: | |||
|
30 | ||||
|
31 | ## URL autolinking | |||
|
32 | ||||
|
33 | Underscores_are_allowed_between_words. | |||
|
34 | ||||
|
35 | ## Fenced code blocks (and syntax highlighting) | |||
|
36 | ||||
|
37 | ```javascript | |||
|
38 | for (var i = 0; i < items.length; i++) { | |||
|
39 | console.log(items[i], i); // log them | |||
|
40 | } | |||
|
41 | ``` | |||
|
42 | ||||
|
43 | ## Task Lists | |||
|
44 | ||||
|
45 | - [ ] Incomplete task list item | |||
|
46 | - [x] **Completed** task list item | |||
|
47 | ||||
|
48 | ## A bit of GitHub spice | |||
|
49 | ||||
|
50 | * SHA: be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2 | |||
|
51 | * User@SHA ref: mojombo@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2 | |||
|
52 | * User/Project@SHA: mojombo/god@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2 | |||
|
53 | * \#Num: #1 | |||
|
54 | * User/#Num: mojombo#1 | |||
|
55 | * User/Project#Num: mojombo/god#1 | |||
|
56 | ||||
|
57 | See http://github.github.com/github-flavored-markdown/. | |||
|
58 | ||||
|
59 | </textarea></form> | |||
|
60 | ||||
|
61 | <script> | |||
|
62 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
63 | mode: 'gfm', | |||
|
64 | lineNumbers: true, | |||
|
65 | theme: "default" | |||
|
66 | }); | |||
|
67 | </script> | |||
|
68 | ||||
|
69 | <p>Optionally depends on other modes for properly highlighted code blocks.</p> | |||
|
70 | ||||
|
71 | <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#gfm_*">normal</a>, <a href="../../test/index.html#verbose,gfm_*">verbose</a>.</p> | |||
|
72 | ||||
|
73 | </body> | |||
|
74 | </html> |
@@ -0,0 +1,112 b'' | |||||
|
1 | (function() { | |||
|
2 | var mode = CodeMirror.getMode({tabSize: 4}, "gfm"); | |||
|
3 | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | |||
|
4 | ||||
|
5 | MT("emInWordAsterisk", | |||
|
6 | "foo[em *bar*]hello"); | |||
|
7 | ||||
|
8 | MT("emInWordUnderscore", | |||
|
9 | "foo_bar_hello"); | |||
|
10 | ||||
|
11 | MT("emStrongUnderscore", | |||
|
12 | "[strong __][em&strong _foo__][em _] bar"); | |||
|
13 | ||||
|
14 | MT("fencedCodeBlocks", | |||
|
15 | "[comment ```]", | |||
|
16 | "[comment foo]", | |||
|
17 | "", | |||
|
18 | "[comment ```]", | |||
|
19 | "bar"); | |||
|
20 | ||||
|
21 | MT("fencedCodeBlockModeSwitching", | |||
|
22 | "[comment ```javascript]", | |||
|
23 | "[variable foo]", | |||
|
24 | "", | |||
|
25 | "[comment ```]", | |||
|
26 | "bar"); | |||
|
27 | ||||
|
28 | MT("taskListAsterisk", | |||
|
29 | "[variable-2 * []] foo]", // Invalid; must have space or x between [] | |||
|
30 | "[variable-2 * [ ]]bar]", // Invalid; must have space after ] | |||
|
31 | "[variable-2 * [x]]hello]", // Invalid; must have space after ] | |||
|
32 | "[variable-2 * ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links | |||
|
33 | " [variable-3 * ][property [x]]][variable-3 foo]"); // Valid; can be nested | |||
|
34 | ||||
|
35 | MT("taskListPlus", | |||
|
36 | "[variable-2 + []] foo]", // Invalid; must have space or x between [] | |||
|
37 | "[variable-2 + [ ]]bar]", // Invalid; must have space after ] | |||
|
38 | "[variable-2 + [x]]hello]", // Invalid; must have space after ] | |||
|
39 | "[variable-2 + ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links | |||
|
40 | " [variable-3 + ][property [x]]][variable-3 foo]"); // Valid; can be nested | |||
|
41 | ||||
|
42 | MT("taskListDash", | |||
|
43 | "[variable-2 - []] foo]", // Invalid; must have space or x between [] | |||
|
44 | "[variable-2 - [ ]]bar]", // Invalid; must have space after ] | |||
|
45 | "[variable-2 - [x]]hello]", // Invalid; must have space after ] | |||
|
46 | "[variable-2 - ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links | |||
|
47 | " [variable-3 - ][property [x]]][variable-3 foo]"); // Valid; can be nested | |||
|
48 | ||||
|
49 | MT("taskListNumber", | |||
|
50 | "[variable-2 1. []] foo]", // Invalid; must have space or x between [] | |||
|
51 | "[variable-2 2. [ ]]bar]", // Invalid; must have space after ] | |||
|
52 | "[variable-2 3. [x]]hello]", // Invalid; must have space after ] | |||
|
53 | "[variable-2 4. ][meta [ ]]][variable-2 [world]]]", // Valid; tests reference style links | |||
|
54 | " [variable-3 1. ][property [x]]][variable-3 foo]"); // Valid; can be nested | |||
|
55 | ||||
|
56 | MT("SHA", | |||
|
57 | "foo [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] bar"); | |||
|
58 | ||||
|
59 | MT("shortSHA", | |||
|
60 | "foo [link be6a8cc] bar"); | |||
|
61 | ||||
|
62 | MT("tooShortSHA", | |||
|
63 | "foo be6a8c bar"); | |||
|
64 | ||||
|
65 | MT("longSHA", | |||
|
66 | "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd22 bar"); | |||
|
67 | ||||
|
68 | MT("badSHA", | |||
|
69 | "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cg2 bar"); | |||
|
70 | ||||
|
71 | MT("userSHA", | |||
|
72 | "foo [link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] hello"); | |||
|
73 | ||||
|
74 | MT("userProjectSHA", | |||
|
75 | "foo [link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] world"); | |||
|
76 | ||||
|
77 | MT("num", | |||
|
78 | "foo [link #1] bar"); | |||
|
79 | ||||
|
80 | MT("badNum", | |||
|
81 | "foo #1bar hello"); | |||
|
82 | ||||
|
83 | MT("userNum", | |||
|
84 | "foo [link bar#1] hello"); | |||
|
85 | ||||
|
86 | MT("userProjectNum", | |||
|
87 | "foo [link bar/hello#1] world"); | |||
|
88 | ||||
|
89 | MT("vanillaLink", | |||
|
90 | "foo [link http://www.example.com/] bar"); | |||
|
91 | ||||
|
92 | MT("vanillaLinkPunctuation", | |||
|
93 | "foo [link http://www.example.com/]. bar"); | |||
|
94 | ||||
|
95 | MT("vanillaLinkExtension", | |||
|
96 | "foo [link http://www.example.com/index.html] bar"); | |||
|
97 | ||||
|
98 | MT("notALink", | |||
|
99 | "[comment ```css]", | |||
|
100 | "[tag foo] {[property color][operator :][keyword black];}", | |||
|
101 | "[comment ```][link http://www.example.com/]"); | |||
|
102 | ||||
|
103 | MT("notALink", | |||
|
104 | "[comment ``foo `bar` http://www.example.com/``] hello"); | |||
|
105 | ||||
|
106 | MT("notALink", | |||
|
107 | "[comment `foo]", | |||
|
108 | "[link http://www.example.com/]", | |||
|
109 | "[comment `foo]", | |||
|
110 | "", | |||
|
111 | "[link http://www.example.com/]"); | |||
|
112 | })(); |
@@ -0,0 +1,168 b'' | |||||
|
1 | CodeMirror.defineMode("go", function(config) { | |||
|
2 | var indentUnit = config.indentUnit; | |||
|
3 | ||||
|
4 | var keywords = { | |||
|
5 | "break":true, "case":true, "chan":true, "const":true, "continue":true, | |||
|
6 | "default":true, "defer":true, "else":true, "fallthrough":true, "for":true, | |||
|
7 | "func":true, "go":true, "goto":true, "if":true, "import":true, | |||
|
8 | "interface":true, "map":true, "package":true, "range":true, "return":true, | |||
|
9 | "select":true, "struct":true, "switch":true, "type":true, "var":true, | |||
|
10 | "bool":true, "byte":true, "complex64":true, "complex128":true, | |||
|
11 | "float32":true, "float64":true, "int8":true, "int16":true, "int32":true, | |||
|
12 | "int64":true, "string":true, "uint8":true, "uint16":true, "uint32":true, | |||
|
13 | "uint64":true, "int":true, "uint":true, "uintptr":true | |||
|
14 | }; | |||
|
15 | ||||
|
16 | var atoms = { | |||
|
17 | "true":true, "false":true, "iota":true, "nil":true, "append":true, | |||
|
18 | "cap":true, "close":true, "complex":true, "copy":true, "imag":true, | |||
|
19 | "len":true, "make":true, "new":true, "panic":true, "print":true, | |||
|
20 | "println":true, "real":true, "recover":true | |||
|
21 | }; | |||
|
22 | ||||
|
23 | var isOperatorChar = /[+\-*&^%:=<>!|\/]/; | |||
|
24 | ||||
|
25 | var curPunc; | |||
|
26 | ||||
|
27 | function tokenBase(stream, state) { | |||
|
28 | var ch = stream.next(); | |||
|
29 | if (ch == '"' || ch == "'" || ch == "`") { | |||
|
30 | state.tokenize = tokenString(ch); | |||
|
31 | return state.tokenize(stream, state); | |||
|
32 | } | |||
|
33 | if (/[\d\.]/.test(ch)) { | |||
|
34 | if (ch == ".") { | |||
|
35 | stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/); | |||
|
36 | } else if (ch == "0") { | |||
|
37 | stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/); | |||
|
38 | } else { | |||
|
39 | stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/); | |||
|
40 | } | |||
|
41 | return "number"; | |||
|
42 | } | |||
|
43 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |||
|
44 | curPunc = ch; | |||
|
45 | return null; | |||
|
46 | } | |||
|
47 | if (ch == "/") { | |||
|
48 | if (stream.eat("*")) { | |||
|
49 | state.tokenize = tokenComment; | |||
|
50 | return tokenComment(stream, state); | |||
|
51 | } | |||
|
52 | if (stream.eat("/")) { | |||
|
53 | stream.skipToEnd(); | |||
|
54 | return "comment"; | |||
|
55 | } | |||
|
56 | } | |||
|
57 | if (isOperatorChar.test(ch)) { | |||
|
58 | stream.eatWhile(isOperatorChar); | |||
|
59 | return "operator"; | |||
|
60 | } | |||
|
61 | stream.eatWhile(/[\w\$_]/); | |||
|
62 | var cur = stream.current(); | |||
|
63 | if (keywords.propertyIsEnumerable(cur)) { | |||
|
64 | if (cur == "case" || cur == "default") curPunc = "case"; | |||
|
65 | return "keyword"; | |||
|
66 | } | |||
|
67 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | |||
|
68 | return "variable"; | |||
|
69 | } | |||
|
70 | ||||
|
71 | function tokenString(quote) { | |||
|
72 | return function(stream, state) { | |||
|
73 | var escaped = false, next, end = false; | |||
|
74 | while ((next = stream.next()) != null) { | |||
|
75 | if (next == quote && !escaped) {end = true; break;} | |||
|
76 | escaped = !escaped && next == "\\"; | |||
|
77 | } | |||
|
78 | if (end || !(escaped || quote == "`")) | |||
|
79 | state.tokenize = tokenBase; | |||
|
80 | return "string"; | |||
|
81 | }; | |||
|
82 | } | |||
|
83 | ||||
|
84 | function tokenComment(stream, state) { | |||
|
85 | var maybeEnd = false, ch; | |||
|
86 | while (ch = stream.next()) { | |||
|
87 | if (ch == "/" && maybeEnd) { | |||
|
88 | state.tokenize = tokenBase; | |||
|
89 | break; | |||
|
90 | } | |||
|
91 | maybeEnd = (ch == "*"); | |||
|
92 | } | |||
|
93 | return "comment"; | |||
|
94 | } | |||
|
95 | ||||
|
96 | function Context(indented, column, type, align, prev) { | |||
|
97 | this.indented = indented; | |||
|
98 | this.column = column; | |||
|
99 | this.type = type; | |||
|
100 | this.align = align; | |||
|
101 | this.prev = prev; | |||
|
102 | } | |||
|
103 | function pushContext(state, col, type) { | |||
|
104 | return state.context = new Context(state.indented, col, type, null, state.context); | |||
|
105 | } | |||
|
106 | function popContext(state) { | |||
|
107 | var t = state.context.type; | |||
|
108 | if (t == ")" || t == "]" || t == "}") | |||
|
109 | state.indented = state.context.indented; | |||
|
110 | return state.context = state.context.prev; | |||
|
111 | } | |||
|
112 | ||||
|
113 | // Interface | |||
|
114 | ||||
|
115 | return { | |||
|
116 | startState: function(basecolumn) { | |||
|
117 | return { | |||
|
118 | tokenize: null, | |||
|
119 | context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | |||
|
120 | indented: 0, | |||
|
121 | startOfLine: true | |||
|
122 | }; | |||
|
123 | }, | |||
|
124 | ||||
|
125 | token: function(stream, state) { | |||
|
126 | var ctx = state.context; | |||
|
127 | if (stream.sol()) { | |||
|
128 | if (ctx.align == null) ctx.align = false; | |||
|
129 | state.indented = stream.indentation(); | |||
|
130 | state.startOfLine = true; | |||
|
131 | if (ctx.type == "case") ctx.type = "}"; | |||
|
132 | } | |||
|
133 | if (stream.eatSpace()) return null; | |||
|
134 | curPunc = null; | |||
|
135 | var style = (state.tokenize || tokenBase)(stream, state); | |||
|
136 | if (style == "comment") return style; | |||
|
137 | if (ctx.align == null) ctx.align = true; | |||
|
138 | ||||
|
139 | if (curPunc == "{") pushContext(state, stream.column(), "}"); | |||
|
140 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); | |||
|
141 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); | |||
|
142 | else if (curPunc == "case") ctx.type = "case"; | |||
|
143 | else if (curPunc == "}" && ctx.type == "}") ctx = popContext(state); | |||
|
144 | else if (curPunc == ctx.type) popContext(state); | |||
|
145 | state.startOfLine = false; | |||
|
146 | return style; | |||
|
147 | }, | |||
|
148 | ||||
|
149 | indent: function(state, textAfter) { | |||
|
150 | if (state.tokenize != tokenBase && state.tokenize != null) return 0; | |||
|
151 | var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); | |||
|
152 | if (ctx.type == "case" && /^(?:case|default)\b/.test(textAfter)) { | |||
|
153 | state.context.type = "}"; | |||
|
154 | return ctx.indented; | |||
|
155 | } | |||
|
156 | var closing = firstChar == ctx.type; | |||
|
157 | if (ctx.align) return ctx.column + (closing ? 0 : 1); | |||
|
158 | else return ctx.indented + (closing ? 0 : indentUnit); | |||
|
159 | }, | |||
|
160 | ||||
|
161 | electricChars: "{}:", | |||
|
162 | blockCommentStart: "/*", | |||
|
163 | blockCommentEnd: "*/", | |||
|
164 | lineComment: "//" | |||
|
165 | }; | |||
|
166 | }); | |||
|
167 | ||||
|
168 | CodeMirror.defineMIME("text/x-go", "go"); |
@@ -0,0 +1,74 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Go mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <link rel="stylesheet" href="../../theme/elegant.css"> | |||
|
8 | <script src="../../lib/codemirror.js"></script> | |||
|
9 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
10 | <script src="go.js"></script> | |||
|
11 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
12 | <style>.CodeMirror {border:1px solid #999; background:#ffc}</style> | |||
|
13 | </head> | |||
|
14 | <body> | |||
|
15 | <h1>CodeMirror: Go mode</h1> | |||
|
16 | ||||
|
17 | <form><textarea id="code" name="code"> | |||
|
18 | // Prime Sieve in Go. | |||
|
19 | // Taken from the Go specification. | |||
|
20 | // Copyright © The Go Authors. | |||
|
21 | ||||
|
22 | package main | |||
|
23 | ||||
|
24 | import "fmt" | |||
|
25 | ||||
|
26 | // Send the sequence 2, 3, 4, ... to channel 'ch'. | |||
|
27 | func generate(ch chan<- int) { | |||
|
28 | for i := 2; ; i++ { | |||
|
29 | ch <- i // Send 'i' to channel 'ch' | |||
|
30 | } | |||
|
31 | } | |||
|
32 | ||||
|
33 | // Copy the values from channel 'src' to channel 'dst', | |||
|
34 | // removing those divisible by 'prime'. | |||
|
35 | func filter(src <-chan int, dst chan<- int, prime int) { | |||
|
36 | for i := range src { // Loop over values received from 'src'. | |||
|
37 | if i%prime != 0 { | |||
|
38 | dst <- i // Send 'i' to channel 'dst'. | |||
|
39 | } | |||
|
40 | } | |||
|
41 | } | |||
|
42 | ||||
|
43 | // The prime sieve: Daisy-chain filter processes together. | |||
|
44 | func sieve() { | |||
|
45 | ch := make(chan int) // Create a new channel. | |||
|
46 | go generate(ch) // Start generate() as a subprocess. | |||
|
47 | for { | |||
|
48 | prime := <-ch | |||
|
49 | fmt.Print(prime, "\n") | |||
|
50 | ch1 := make(chan int) | |||
|
51 | go filter(ch, ch1, prime) | |||
|
52 | ch = ch1 | |||
|
53 | } | |||
|
54 | } | |||
|
55 | ||||
|
56 | func main() { | |||
|
57 | sieve() | |||
|
58 | } | |||
|
59 | </textarea></form> | |||
|
60 | ||||
|
61 | <script> | |||
|
62 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
63 | theme: "elegant", | |||
|
64 | matchBrackets: true, | |||
|
65 | indentUnit: 8, | |||
|
66 | tabSize: 8, | |||
|
67 | indentWithTabs: true, | |||
|
68 | mode: "text/x-go" | |||
|
69 | }); | |||
|
70 | </script> | |||
|
71 | ||||
|
72 | <p><strong>MIME type:</strong> <code>text/x-go</code></p> | |||
|
73 | </body> | |||
|
74 | </html> |
@@ -0,0 +1,210 b'' | |||||
|
1 | CodeMirror.defineMode("groovy", 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( | |||
|
8 | "abstract as assert boolean break byte case catch char class const continue def default " + | |||
|
9 | "do double else enum extends final finally float for goto if implements import in " + | |||
|
10 | "instanceof int interface long native new package private protected public return " + | |||
|
11 | "short static strictfp super switch synchronized threadsafe throw throws transient " + | |||
|
12 | "try void volatile while"); | |||
|
13 | var blockKeywords = words("catch class do else finally for if switch try while enum interface def"); | |||
|
14 | var atoms = words("null true false this"); | |||
|
15 | ||||
|
16 | var curPunc; | |||
|
17 | function tokenBase(stream, state) { | |||
|
18 | var ch = stream.next(); | |||
|
19 | if (ch == '"' || ch == "'") { | |||
|
20 | return startString(ch, stream, state); | |||
|
21 | } | |||
|
22 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |||
|
23 | curPunc = ch; | |||
|
24 | return null; | |||
|
25 | } | |||
|
26 | if (/\d/.test(ch)) { | |||
|
27 | stream.eatWhile(/[\w\.]/); | |||
|
28 | if (stream.eat(/eE/)) { stream.eat(/\+\-/); stream.eatWhile(/\d/); } | |||
|
29 | return "number"; | |||
|
30 | } | |||
|
31 | if (ch == "/") { | |||
|
32 | if (stream.eat("*")) { | |||
|
33 | state.tokenize.push(tokenComment); | |||
|
34 | return tokenComment(stream, state); | |||
|
35 | } | |||
|
36 | if (stream.eat("/")) { | |||
|
37 | stream.skipToEnd(); | |||
|
38 | return "comment"; | |||
|
39 | } | |||
|
40 | if (expectExpression(state.lastToken)) { | |||
|
41 | return startString(ch, stream, state); | |||
|
42 | } | |||
|
43 | } | |||
|
44 | if (ch == "-" && stream.eat(">")) { | |||
|
45 | curPunc = "->"; | |||
|
46 | return null; | |||
|
47 | } | |||
|
48 | if (/[+\-*&%=<>!?|\/~]/.test(ch)) { | |||
|
49 | stream.eatWhile(/[+\-*&%=<>|~]/); | |||
|
50 | return "operator"; | |||
|
51 | } | |||
|
52 | stream.eatWhile(/[\w\$_]/); | |||
|
53 | if (ch == "@") { stream.eatWhile(/[\w\$_\.]/); return "meta"; } | |||
|
54 | if (state.lastToken == ".") return "property"; | |||
|
55 | if (stream.eat(":")) { curPunc = "proplabel"; return "property"; } | |||
|
56 | var cur = stream.current(); | |||
|
57 | if (atoms.propertyIsEnumerable(cur)) { return "atom"; } | |||
|
58 | if (keywords.propertyIsEnumerable(cur)) { | |||
|
59 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | |||
|
60 | return "keyword"; | |||
|
61 | } | |||
|
62 | return "variable"; | |||
|
63 | } | |||
|
64 | tokenBase.isBase = true; | |||
|
65 | ||||
|
66 | function startString(quote, stream, state) { | |||
|
67 | var tripleQuoted = false; | |||
|
68 | if (quote != "/" && stream.eat(quote)) { | |||
|
69 | if (stream.eat(quote)) tripleQuoted = true; | |||
|
70 | else return "string"; | |||
|
71 | } | |||
|
72 | function t(stream, state) { | |||
|
73 | var escaped = false, next, end = !tripleQuoted; | |||
|
74 | while ((next = stream.next()) != null) { | |||
|
75 | if (next == quote && !escaped) { | |||
|
76 | if (!tripleQuoted) { break; } | |||
|
77 | if (stream.match(quote + quote)) { end = true; break; } | |||
|
78 | } | |||
|
79 | if (quote == '"' && next == "$" && !escaped && stream.eat("{")) { | |||
|
80 | state.tokenize.push(tokenBaseUntilBrace()); | |||
|
81 | return "string"; | |||
|
82 | } | |||
|
83 | escaped = !escaped && next == "\\"; | |||
|
84 | } | |||
|
85 | if (end) state.tokenize.pop(); | |||
|
86 | return "string"; | |||
|
87 | } | |||
|
88 | state.tokenize.push(t); | |||
|
89 | return t(stream, state); | |||
|
90 | } | |||
|
91 | ||||
|
92 | function tokenBaseUntilBrace() { | |||
|
93 | var depth = 1; | |||
|
94 | function t(stream, state) { | |||
|
95 | if (stream.peek() == "}") { | |||
|
96 | depth--; | |||
|
97 | if (depth == 0) { | |||
|
98 | state.tokenize.pop(); | |||
|
99 | return state.tokenize[state.tokenize.length-1](stream, state); | |||
|
100 | } | |||
|
101 | } else if (stream.peek() == "{") { | |||
|
102 | depth++; | |||
|
103 | } | |||
|
104 | return tokenBase(stream, state); | |||
|
105 | } | |||
|
106 | t.isBase = true; | |||
|
107 | return t; | |||
|
108 | } | |||
|
109 | ||||
|
110 | function tokenComment(stream, state) { | |||
|
111 | var maybeEnd = false, ch; | |||
|
112 | while (ch = stream.next()) { | |||
|
113 | if (ch == "/" && maybeEnd) { | |||
|
114 | state.tokenize.pop(); | |||
|
115 | break; | |||
|
116 | } | |||
|
117 | maybeEnd = (ch == "*"); | |||
|
118 | } | |||
|
119 | return "comment"; | |||
|
120 | } | |||
|
121 | ||||
|
122 | function expectExpression(last) { | |||
|
123 | return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) || | |||
|
124 | last == "newstatement" || last == "keyword" || last == "proplabel"; | |||
|
125 | } | |||
|
126 | ||||
|
127 | function Context(indented, column, type, align, prev) { | |||
|
128 | this.indented = indented; | |||
|
129 | this.column = column; | |||
|
130 | this.type = type; | |||
|
131 | this.align = align; | |||
|
132 | this.prev = prev; | |||
|
133 | } | |||
|
134 | function pushContext(state, col, type) { | |||
|
135 | return state.context = new Context(state.indented, col, type, null, state.context); | |||
|
136 | } | |||
|
137 | function popContext(state) { | |||
|
138 | var t = state.context.type; | |||
|
139 | if (t == ")" || t == "]" || t == "}") | |||
|
140 | state.indented = state.context.indented; | |||
|
141 | return state.context = state.context.prev; | |||
|
142 | } | |||
|
143 | ||||
|
144 | // Interface | |||
|
145 | ||||
|
146 | return { | |||
|
147 | startState: function(basecolumn) { | |||
|
148 | return { | |||
|
149 | tokenize: [tokenBase], | |||
|
150 | context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false), | |||
|
151 | indented: 0, | |||
|
152 | startOfLine: true, | |||
|
153 | lastToken: null | |||
|
154 | }; | |||
|
155 | }, | |||
|
156 | ||||
|
157 | token: function(stream, state) { | |||
|
158 | var ctx = state.context; | |||
|
159 | if (stream.sol()) { | |||
|
160 | if (ctx.align == null) ctx.align = false; | |||
|
161 | state.indented = stream.indentation(); | |||
|
162 | state.startOfLine = true; | |||
|
163 | // Automatic semicolon insertion | |||
|
164 | if (ctx.type == "statement" && !expectExpression(state.lastToken)) { | |||
|
165 | popContext(state); ctx = state.context; | |||
|
166 | } | |||
|
167 | } | |||
|
168 | if (stream.eatSpace()) return null; | |||
|
169 | curPunc = null; | |||
|
170 | var style = state.tokenize[state.tokenize.length-1](stream, state); | |||
|
171 | if (style == "comment") return style; | |||
|
172 | if (ctx.align == null) ctx.align = true; | |||
|
173 | ||||
|
174 | if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state); | |||
|
175 | // Handle indentation for {x -> \n ... } | |||
|
176 | else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") { | |||
|
177 | popContext(state); | |||
|
178 | state.context.align = false; | |||
|
179 | } | |||
|
180 | else if (curPunc == "{") pushContext(state, stream.column(), "}"); | |||
|
181 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); | |||
|
182 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); | |||
|
183 | else if (curPunc == "}") { | |||
|
184 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
185 | if (ctx.type == "}") ctx = popContext(state); | |||
|
186 | while (ctx.type == "statement") ctx = popContext(state); | |||
|
187 | } | |||
|
188 | else if (curPunc == ctx.type) popContext(state); | |||
|
189 | else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement")) | |||
|
190 | pushContext(state, stream.column(), "statement"); | |||
|
191 | state.startOfLine = false; | |||
|
192 | state.lastToken = curPunc || style; | |||
|
193 | return style; | |||
|
194 | }, | |||
|
195 | ||||
|
196 | indent: function(state, textAfter) { | |||
|
197 | if (!state.tokenize[state.tokenize.length-1].isBase) return 0; | |||
|
198 | var firstChar = textAfter && textAfter.charAt(0), ctx = state.context; | |||
|
199 | if (ctx.type == "statement" && !expectExpression(state.lastToken)) ctx = ctx.prev; | |||
|
200 | var closing = firstChar == ctx.type; | |||
|
201 | if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit); | |||
|
202 | else if (ctx.align) return ctx.column + (closing ? 0 : 1); | |||
|
203 | else return ctx.indented + (closing ? 0 : config.indentUnit); | |||
|
204 | }, | |||
|
205 | ||||
|
206 | electricChars: "{}" | |||
|
207 | }; | |||
|
208 | }); | |||
|
209 | ||||
|
210 | CodeMirror.defineMIME("text/x-groovy", "groovy"); |
@@ -0,0 +1,73 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Groovy mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="groovy.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | <style>.CodeMirror {border-top: 1px solid #500; border-bottom: 1px solid #500;}</style> | |||
|
12 | </head> | |||
|
13 | <body> | |||
|
14 | <h1>CodeMirror: Groovy mode</h1> | |||
|
15 | ||||
|
16 | <form><textarea id="code" name="code"> | |||
|
17 | //Pattern for groovy script | |||
|
18 | def p = ~/.*\.groovy/ | |||
|
19 | new File( 'd:\\scripts' ).eachFileMatch(p) {f -> | |||
|
20 | // imports list | |||
|
21 | def imports = [] | |||
|
22 | f.eachLine { | |||
|
23 | // condition to detect an import instruction | |||
|
24 | ln -> if ( ln =~ '^import .*' ) { | |||
|
25 | imports << "${ln - 'import '}" | |||
|
26 | } | |||
|
27 | } | |||
|
28 | // print thmen | |||
|
29 | if ( ! imports.empty ) { | |||
|
30 | println f | |||
|
31 | imports.each{ println " $it" } | |||
|
32 | } | |||
|
33 | } | |||
|
34 | ||||
|
35 | /* Coin changer demo code from http://groovy.codehaus.org */ | |||
|
36 | ||||
|
37 | enum UsCoin { | |||
|
38 | quarter(25), dime(10), nickel(5), penny(1) | |||
|
39 | UsCoin(v) { value = v } | |||
|
40 | final value | |||
|
41 | } | |||
|
42 | ||||
|
43 | enum OzzieCoin { | |||
|
44 | fifty(50), twenty(20), ten(10), five(5) | |||
|
45 | OzzieCoin(v) { value = v } | |||
|
46 | final value | |||
|
47 | } | |||
|
48 | ||||
|
49 | def plural(word, count) { | |||
|
50 | if (count == 1) return word | |||
|
51 | word[-1] == 'y' ? word[0..-2] + "ies" : word + "s" | |||
|
52 | } | |||
|
53 | ||||
|
54 | def change(currency, amount) { | |||
|
55 | currency.values().inject([]){ list, coin -> | |||
|
56 | int count = amount / coin.value | |||
|
57 | amount = amount % coin.value | |||
|
58 | list += "$count ${plural(coin.toString(), count)}" | |||
|
59 | } | |||
|
60 | } | |||
|
61 | </textarea></form> | |||
|
62 | ||||
|
63 | <script> | |||
|
64 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
65 | lineNumbers: true, | |||
|
66 | matchBrackets: true, | |||
|
67 | mode: "text/x-groovy" | |||
|
68 | }); | |||
|
69 | </script> | |||
|
70 | ||||
|
71 | <p><strong>MIME types defined:</strong> <code>text/x-groovy</code></p> | |||
|
72 | </body> | |||
|
73 | </html> |
@@ -0,0 +1,153 b'' | |||||
|
1 | (function() { | |||
|
2 | "use strict"; | |||
|
3 | ||||
|
4 | // full haml mode. This handled embeded ruby and html fragments too | |||
|
5 | CodeMirror.defineMode("haml", function(config) { | |||
|
6 | var htmlMode = CodeMirror.getMode(config, {name: "htmlmixed"}); | |||
|
7 | var rubyMode = CodeMirror.getMode(config, "ruby"); | |||
|
8 | ||||
|
9 | function rubyInQuote(endQuote) { | |||
|
10 | return function(stream, state) { | |||
|
11 | var ch = stream.peek(); | |||
|
12 | if (ch == endQuote && state.rubyState.tokenize.length == 1) { | |||
|
13 | // step out of ruby context as it seems to complete processing all the braces | |||
|
14 | stream.next(); | |||
|
15 | state.tokenize = html; | |||
|
16 | return "closeAttributeTag"; | |||
|
17 | } else { | |||
|
18 | return ruby(stream, state); | |||
|
19 | } | |||
|
20 | }; | |||
|
21 | } | |||
|
22 | ||||
|
23 | function ruby(stream, state) { | |||
|
24 | if (stream.match("-#")) { | |||
|
25 | stream.skipToEnd(); | |||
|
26 | return "comment"; | |||
|
27 | } | |||
|
28 | return rubyMode.token(stream, state.rubyState); | |||
|
29 | } | |||
|
30 | ||||
|
31 | function html(stream, state) { | |||
|
32 | var ch = stream.peek(); | |||
|
33 | ||||
|
34 | // handle haml declarations. All declarations that cant be handled here | |||
|
35 | // will be passed to html mode | |||
|
36 | if (state.previousToken.style == "comment" ) { | |||
|
37 | if (state.indented > state.previousToken.indented) { | |||
|
38 | stream.skipToEnd(); | |||
|
39 | return "commentLine"; | |||
|
40 | } | |||
|
41 | } | |||
|
42 | ||||
|
43 | if (state.startOfLine) { | |||
|
44 | if (ch == "!" && stream.match("!!")) { | |||
|
45 | stream.skipToEnd(); | |||
|
46 | return "tag"; | |||
|
47 | } else if (stream.match(/^%[\w:#\.]+=/)) { | |||
|
48 | state.tokenize = ruby; | |||
|
49 | return "hamlTag"; | |||
|
50 | } else if (stream.match(/^%[\w:]+/)) { | |||
|
51 | return "hamlTag"; | |||
|
52 | } else if (ch == "/" ) { | |||
|
53 | stream.skipToEnd(); | |||
|
54 | return "comment"; | |||
|
55 | } | |||
|
56 | } | |||
|
57 | ||||
|
58 | if (state.startOfLine || state.previousToken.style == "hamlTag") { | |||
|
59 | if ( ch == "#" || ch == ".") { | |||
|
60 | stream.match(/[\w-#\.]*/); | |||
|
61 | return "hamlAttribute"; | |||
|
62 | } | |||
|
63 | } | |||
|
64 | ||||
|
65 | // donot handle --> as valid ruby, make it HTML close comment instead | |||
|
66 | if (state.startOfLine && !stream.match("-->", false) && (ch == "=" || ch == "-" )) { | |||
|
67 | state.tokenize = ruby; | |||
|
68 | return null; | |||
|
69 | } | |||
|
70 | ||||
|
71 | if (state.previousToken.style == "hamlTag" || | |||
|
72 | state.previousToken.style == "closeAttributeTag" || | |||
|
73 | state.previousToken.style == "hamlAttribute") { | |||
|
74 | if (ch == "(") { | |||
|
75 | state.tokenize = rubyInQuote(")"); | |||
|
76 | return null; | |||
|
77 | } else if (ch == "{") { | |||
|
78 | state.tokenize = rubyInQuote("}"); | |||
|
79 | return null; | |||
|
80 | } | |||
|
81 | } | |||
|
82 | ||||
|
83 | return htmlMode.token(stream, state.htmlState); | |||
|
84 | } | |||
|
85 | ||||
|
86 | return { | |||
|
87 | // default to html mode | |||
|
88 | startState: function() { | |||
|
89 | var htmlState = htmlMode.startState(); | |||
|
90 | var rubyState = rubyMode.startState(); | |||
|
91 | return { | |||
|
92 | htmlState: htmlState, | |||
|
93 | rubyState: rubyState, | |||
|
94 | indented: 0, | |||
|
95 | previousToken: { style: null, indented: 0}, | |||
|
96 | tokenize: html | |||
|
97 | }; | |||
|
98 | }, | |||
|
99 | ||||
|
100 | copyState: function(state) { | |||
|
101 | return { | |||
|
102 | htmlState : CodeMirror.copyState(htmlMode, state.htmlState), | |||
|
103 | rubyState: CodeMirror.copyState(rubyMode, state.rubyState), | |||
|
104 | indented: state.indented, | |||
|
105 | previousToken: state.previousToken, | |||
|
106 | tokenize: state.tokenize | |||
|
107 | }; | |||
|
108 | }, | |||
|
109 | ||||
|
110 | token: function(stream, state) { | |||
|
111 | if (stream.sol()) { | |||
|
112 | state.indented = stream.indentation(); | |||
|
113 | state.startOfLine = true; | |||
|
114 | } | |||
|
115 | if (stream.eatSpace()) return null; | |||
|
116 | var style = state.tokenize(stream, state); | |||
|
117 | state.startOfLine = false; | |||
|
118 | // dont record comment line as we only want to measure comment line with | |||
|
119 | // the opening comment block | |||
|
120 | if (style && style != "commentLine") { | |||
|
121 | state.previousToken = { style: style, indented: state.indented }; | |||
|
122 | } | |||
|
123 | // if current state is ruby and the previous token is not `,` reset the | |||
|
124 | // tokenize to html | |||
|
125 | if (stream.eol() && state.tokenize == ruby) { | |||
|
126 | stream.backUp(1); | |||
|
127 | var ch = stream.peek(); | |||
|
128 | stream.next(); | |||
|
129 | if (ch && ch != ",") { | |||
|
130 | state.tokenize = html; | |||
|
131 | } | |||
|
132 | } | |||
|
133 | // reprocess some of the specific style tag when finish setting previousToken | |||
|
134 | if (style == "hamlTag") { | |||
|
135 | style = "tag"; | |||
|
136 | } else if (style == "commentLine") { | |||
|
137 | style = "comment"; | |||
|
138 | } else if (style == "hamlAttribute") { | |||
|
139 | style = "attribute"; | |||
|
140 | } else if (style == "closeAttributeTag") { | |||
|
141 | style = null; | |||
|
142 | } | |||
|
143 | return style; | |||
|
144 | }, | |||
|
145 | ||||
|
146 | indent: function(state) { | |||
|
147 | return state.indented; | |||
|
148 | } | |||
|
149 | }; | |||
|
150 | }, "htmlmixed", "ruby"); | |||
|
151 | ||||
|
152 | CodeMirror.defineMIME("text/x-haml", "haml"); | |||
|
153 | })(); |
@@ -0,0 +1,67 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: HAML mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../xml/xml.js"></script> | |||
|
9 | <script src="../htmlmixed/htmlmixed.js"></script> | |||
|
10 | <script src="../javascript/javascript.js"></script> | |||
|
11 | <script src="../ruby/ruby.js"></script> | |||
|
12 | <script src="haml.js"></script> | |||
|
13 | <style>.CodeMirror {background: #f8f8f8;}</style> | |||
|
14 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
15 | </head> | |||
|
16 | <body> | |||
|
17 | <h1>CodeMirror: HAML mode</h1> | |||
|
18 | <form><textarea id="code" name="code"> | |||
|
19 | !!! | |||
|
20 | #content | |||
|
21 | .left.column(title="title"){:href => "/hello", :test => "#{hello}_#{world}"} | |||
|
22 | <!-- This is a comment --> | |||
|
23 | %h2 Welcome to our site! | |||
|
24 | %p= puts "HAML MODE" | |||
|
25 | .right.column | |||
|
26 | = render :partial => "sidebar" | |||
|
27 | ||||
|
28 | .container | |||
|
29 | .row | |||
|
30 | .span8 | |||
|
31 | %h1.title= @page_title | |||
|
32 | %p.title= @page_title | |||
|
33 | %p | |||
|
34 | / | |||
|
35 | The same as HTML comment | |||
|
36 | Hello multiline comment | |||
|
37 | ||||
|
38 | -# haml comment | |||
|
39 | This wont be displayed | |||
|
40 | nor will this | |||
|
41 | Date/Time: | |||
|
42 | - now = DateTime.now | |||
|
43 | %strong= now | |||
|
44 | - if now > DateTime.parse("December 31, 2006") | |||
|
45 | = "Happy new " + "year!" | |||
|
46 | ||||
|
47 | %title | |||
|
48 | = @title | |||
|
49 | \= @title | |||
|
50 | <h1>Title</h1> | |||
|
51 | <h1 title="HELLO"> | |||
|
52 | Title | |||
|
53 | </h1> | |||
|
54 | </textarea></form> | |||
|
55 | <script> | |||
|
56 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
57 | lineNumbers: true, | |||
|
58 | mode: "text/x-haml" | |||
|
59 | }); | |||
|
60 | </script> | |||
|
61 | ||||
|
62 | <p><strong>MIME types defined:</strong> <code>text/x-haml</code>.</p> | |||
|
63 | ||||
|
64 | <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#haml_*">normal</a>, <a href="../../test/index.html#verbose,haml_*">verbose</a>.</p> | |||
|
65 | ||||
|
66 | </body> | |||
|
67 | </html> |
@@ -0,0 +1,94 b'' | |||||
|
1 | (function() { | |||
|
2 | var mode = CodeMirror.getMode({tabSize: 4}, "haml"); | |||
|
3 | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | |||
|
4 | ||||
|
5 | // Requires at least one media query | |||
|
6 | MT("elementName", | |||
|
7 | "[tag %h1] Hey There"); | |||
|
8 | ||||
|
9 | MT("oneElementPerLine", | |||
|
10 | "[tag %h1] Hey There %h2"); | |||
|
11 | ||||
|
12 | MT("idSelector", | |||
|
13 | "[tag %h1][attribute #test] Hey There"); | |||
|
14 | ||||
|
15 | MT("classSelector", | |||
|
16 | "[tag %h1][attribute .hello] Hey There"); | |||
|
17 | ||||
|
18 | MT("docType", | |||
|
19 | "[tag !!! XML]"); | |||
|
20 | ||||
|
21 | MT("comment", | |||
|
22 | "[comment / Hello WORLD]"); | |||
|
23 | ||||
|
24 | MT("notComment", | |||
|
25 | "[tag %h1] This is not a / comment "); | |||
|
26 | ||||
|
27 | MT("attributes", | |||
|
28 | "[tag %a]([variable title][operator =][string \"test\"]){[atom :title] [operator =>] [string \"test\"]}"); | |||
|
29 | ||||
|
30 | MT("htmlCode", | |||
|
31 | "[tag <h1>]Title[tag </h1>]"); | |||
|
32 | ||||
|
33 | MT("rubyBlock", | |||
|
34 | "[operator =][variable-2 @item]"); | |||
|
35 | ||||
|
36 | MT("selectorRubyBlock", | |||
|
37 | "[tag %a.selector=] [variable-2 @item]"); | |||
|
38 | ||||
|
39 | MT("nestedRubyBlock", | |||
|
40 | "[tag %a]", | |||
|
41 | " [operator =][variable puts] [string \"test\"]"); | |||
|
42 | ||||
|
43 | MT("multilinePlaintext", | |||
|
44 | "[tag %p]", | |||
|
45 | " Hello,", | |||
|
46 | " World"); | |||
|
47 | ||||
|
48 | MT("multilineRuby", | |||
|
49 | "[tag %p]", | |||
|
50 | " [comment -# this is a comment]", | |||
|
51 | " [comment and this is a comment too]", | |||
|
52 | " Date/Time", | |||
|
53 | " [operator -] [variable now] [operator =] [tag DateTime][operator .][variable now]", | |||
|
54 | " [tag %strong=] [variable now]", | |||
|
55 | " [operator -] [keyword if] [variable now] [operator >] [tag DateTime][operator .][variable parse]([string \"December 31, 2006\"])", | |||
|
56 | " [operator =][string \"Happy\"]", | |||
|
57 | " [operator =][string \"Belated\"]", | |||
|
58 | " [operator =][string \"Birthday\"]"); | |||
|
59 | ||||
|
60 | MT("multilineComment", | |||
|
61 | "[comment /]", | |||
|
62 | " [comment Multiline]", | |||
|
63 | " [comment Comment]"); | |||
|
64 | ||||
|
65 | MT("hamlComment", | |||
|
66 | "[comment -# this is a comment]"); | |||
|
67 | ||||
|
68 | MT("multilineHamlComment", | |||
|
69 | "[comment -# this is a comment]", | |||
|
70 | " [comment and this is a comment too]"); | |||
|
71 | ||||
|
72 | MT("multilineHTMLComment", | |||
|
73 | "[comment <!--]", | |||
|
74 | " [comment what a comment]", | |||
|
75 | " [comment -->]"); | |||
|
76 | ||||
|
77 | MT("hamlAfterRubyTag", | |||
|
78 | "[attribute .block]", | |||
|
79 | " [tag %strong=] [variable now]", | |||
|
80 | " [attribute .test]", | |||
|
81 | " [operator =][variable now]", | |||
|
82 | " [attribute .right]"); | |||
|
83 | ||||
|
84 | MT("stretchedRuby", | |||
|
85 | "[operator =] [variable puts] [string \"Hello\"],", | |||
|
86 | " [string \"World\"]"); | |||
|
87 | ||||
|
88 | MT("interpolationInHashAttribute", | |||
|
89 | //"[tag %div]{[atom :id] [operator =>] [string \"#{][variable test][string }_#{][variable ting][string }\"]} test"); | |||
|
90 | "[tag %div]{[atom :id] [operator =>] [string \"#{][variable test][string }_#{][variable ting][string }\"]} test"); | |||
|
91 | ||||
|
92 | MT("interpolationInHTMLAttribute", | |||
|
93 | "[tag %div]([variable title][operator =][string \"#{][variable test][string }_#{][variable ting]()[string }\"]) Test"); | |||
|
94 | })(); |
@@ -0,0 +1,246 b'' | |||||
|
1 | CodeMirror.defineMode("haskell", function() { | |||
|
2 | ||||
|
3 | function switchState(source, setState, f) { | |||
|
4 | setState(f); | |||
|
5 | return f(source, setState); | |||
|
6 | } | |||
|
7 | ||||
|
8 | // These should all be Unicode extended, as per the Haskell 2010 report | |||
|
9 | var smallRE = /[a-z_]/; | |||
|
10 | var largeRE = /[A-Z]/; | |||
|
11 | var digitRE = /[0-9]/; | |||
|
12 | var hexitRE = /[0-9A-Fa-f]/; | |||
|
13 | var octitRE = /[0-7]/; | |||
|
14 | var idRE = /[a-z_A-Z0-9']/; | |||
|
15 | var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/; | |||
|
16 | var specialRE = /[(),;[\]`{}]/; | |||
|
17 | var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer | |||
|
18 | ||||
|
19 | function normal(source, setState) { | |||
|
20 | if (source.eatWhile(whiteCharRE)) { | |||
|
21 | return null; | |||
|
22 | } | |||
|
23 | ||||
|
24 | var ch = source.next(); | |||
|
25 | if (specialRE.test(ch)) { | |||
|
26 | if (ch == '{' && source.eat('-')) { | |||
|
27 | var t = "comment"; | |||
|
28 | if (source.eat('#')) { | |||
|
29 | t = "meta"; | |||
|
30 | } | |||
|
31 | return switchState(source, setState, ncomment(t, 1)); | |||
|
32 | } | |||
|
33 | return null; | |||
|
34 | } | |||
|
35 | ||||
|
36 | if (ch == '\'') { | |||
|
37 | if (source.eat('\\')) { | |||
|
38 | source.next(); // should handle other escapes here | |||
|
39 | } | |||
|
40 | else { | |||
|
41 | source.next(); | |||
|
42 | } | |||
|
43 | if (source.eat('\'')) { | |||
|
44 | return "string"; | |||
|
45 | } | |||
|
46 | return "error"; | |||
|
47 | } | |||
|
48 | ||||
|
49 | if (ch == '"') { | |||
|
50 | return switchState(source, setState, stringLiteral); | |||
|
51 | } | |||
|
52 | ||||
|
53 | if (largeRE.test(ch)) { | |||
|
54 | source.eatWhile(idRE); | |||
|
55 | if (source.eat('.')) { | |||
|
56 | return "qualifier"; | |||
|
57 | } | |||
|
58 | return "variable-2"; | |||
|
59 | } | |||
|
60 | ||||
|
61 | if (smallRE.test(ch)) { | |||
|
62 | source.eatWhile(idRE); | |||
|
63 | return "variable"; | |||
|
64 | } | |||
|
65 | ||||
|
66 | if (digitRE.test(ch)) { | |||
|
67 | if (ch == '0') { | |||
|
68 | if (source.eat(/[xX]/)) { | |||
|
69 | source.eatWhile(hexitRE); // should require at least 1 | |||
|
70 | return "integer"; | |||
|
71 | } | |||
|
72 | if (source.eat(/[oO]/)) { | |||
|
73 | source.eatWhile(octitRE); // should require at least 1 | |||
|
74 | return "number"; | |||
|
75 | } | |||
|
76 | } | |||
|
77 | source.eatWhile(digitRE); | |||
|
78 | var t = "number"; | |||
|
79 | if (source.eat('.')) { | |||
|
80 | t = "number"; | |||
|
81 | source.eatWhile(digitRE); // should require at least 1 | |||
|
82 | } | |||
|
83 | if (source.eat(/[eE]/)) { | |||
|
84 | t = "number"; | |||
|
85 | source.eat(/[-+]/); | |||
|
86 | source.eatWhile(digitRE); // should require at least 1 | |||
|
87 | } | |||
|
88 | return t; | |||
|
89 | } | |||
|
90 | ||||
|
91 | if (symbolRE.test(ch)) { | |||
|
92 | if (ch == '-' && source.eat(/-/)) { | |||
|
93 | source.eatWhile(/-/); | |||
|
94 | if (!source.eat(symbolRE)) { | |||
|
95 | source.skipToEnd(); | |||
|
96 | return "comment"; | |||
|
97 | } | |||
|
98 | } | |||
|
99 | var t = "variable"; | |||
|
100 | if (ch == ':') { | |||
|
101 | t = "variable-2"; | |||
|
102 | } | |||
|
103 | source.eatWhile(symbolRE); | |||
|
104 | return t; | |||
|
105 | } | |||
|
106 | ||||
|
107 | return "error"; | |||
|
108 | } | |||
|
109 | ||||
|
110 | function ncomment(type, nest) { | |||
|
111 | if (nest == 0) { | |||
|
112 | return normal; | |||
|
113 | } | |||
|
114 | return function(source, setState) { | |||
|
115 | var currNest = nest; | |||
|
116 | while (!source.eol()) { | |||
|
117 | var ch = source.next(); | |||
|
118 | if (ch == '{' && source.eat('-')) { | |||
|
119 | ++currNest; | |||
|
120 | } | |||
|
121 | else if (ch == '-' && source.eat('}')) { | |||
|
122 | --currNest; | |||
|
123 | if (currNest == 0) { | |||
|
124 | setState(normal); | |||
|
125 | return type; | |||
|
126 | } | |||
|
127 | } | |||
|
128 | } | |||
|
129 | setState(ncomment(type, currNest)); | |||
|
130 | return type; | |||
|
131 | }; | |||
|
132 | } | |||
|
133 | ||||
|
134 | function stringLiteral(source, setState) { | |||
|
135 | while (!source.eol()) { | |||
|
136 | var ch = source.next(); | |||
|
137 | if (ch == '"') { | |||
|
138 | setState(normal); | |||
|
139 | return "string"; | |||
|
140 | } | |||
|
141 | if (ch == '\\') { | |||
|
142 | if (source.eol() || source.eat(whiteCharRE)) { | |||
|
143 | setState(stringGap); | |||
|
144 | return "string"; | |||
|
145 | } | |||
|
146 | if (source.eat('&')) { | |||
|
147 | } | |||
|
148 | else { | |||
|
149 | source.next(); // should handle other escapes here | |||
|
150 | } | |||
|
151 | } | |||
|
152 | } | |||
|
153 | setState(normal); | |||
|
154 | return "error"; | |||
|
155 | } | |||
|
156 | ||||
|
157 | function stringGap(source, setState) { | |||
|
158 | if (source.eat('\\')) { | |||
|
159 | return switchState(source, setState, stringLiteral); | |||
|
160 | } | |||
|
161 | source.next(); | |||
|
162 | setState(normal); | |||
|
163 | return "error"; | |||
|
164 | } | |||
|
165 | ||||
|
166 | ||||
|
167 | var wellKnownWords = (function() { | |||
|
168 | var wkw = {}; | |||
|
169 | function setType(t) { | |||
|
170 | return function () { | |||
|
171 | for (var i = 0; i < arguments.length; i++) | |||
|
172 | wkw[arguments[i]] = t; | |||
|
173 | }; | |||
|
174 | } | |||
|
175 | ||||
|
176 | setType("keyword")( | |||
|
177 | "case", "class", "data", "default", "deriving", "do", "else", "foreign", | |||
|
178 | "if", "import", "in", "infix", "infixl", "infixr", "instance", "let", | |||
|
179 | "module", "newtype", "of", "then", "type", "where", "_"); | |||
|
180 | ||||
|
181 | setType("keyword")( | |||
|
182 | "\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>"); | |||
|
183 | ||||
|
184 | setType("builtin")( | |||
|
185 | "!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<", | |||
|
186 | "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**"); | |||
|
187 | ||||
|
188 | setType("builtin")( | |||
|
189 | "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq", | |||
|
190 | "False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT", | |||
|
191 | "IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left", | |||
|
192 | "Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read", | |||
|
193 | "ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS", | |||
|
194 | "String", "True"); | |||
|
195 | ||||
|
196 | setType("builtin")( | |||
|
197 | "abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf", | |||
|
198 | "asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling", | |||
|
199 | "compare", "concat", "concatMap", "const", "cos", "cosh", "curry", | |||
|
200 | "cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either", | |||
|
201 | "elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo", | |||
|
202 | "enumFromTo", "error", "even", "exp", "exponent", "fail", "filter", | |||
|
203 | "flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap", | |||
|
204 | "foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger", | |||
|
205 | "fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents", | |||
|
206 | "getLine", "head", "id", "init", "interact", "ioError", "isDenormalized", | |||
|
207 | "isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last", | |||
|
208 | "lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map", | |||
|
209 | "mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound", | |||
|
210 | "minimum", "mod", "negate", "not", "notElem", "null", "odd", "or", | |||
|
211 | "otherwise", "pi", "pred", "print", "product", "properFraction", | |||
|
212 | "putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile", | |||
|
213 | "readIO", "readList", "readLn", "readParen", "reads", "readsPrec", | |||
|
214 | "realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse", | |||
|
215 | "round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq", | |||
|
216 | "sequence", "sequence_", "show", "showChar", "showList", "showParen", | |||
|
217 | "showString", "shows", "showsPrec", "significand", "signum", "sin", | |||
|
218 | "sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum", | |||
|
219 | "tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger", | |||
|
220 | "toRational", "truncate", "uncurry", "undefined", "unlines", "until", | |||
|
221 | "unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip", | |||
|
222 | "zip3", "zipWith", "zipWith3"); | |||
|
223 | ||||
|
224 | return wkw; | |||
|
225 | })(); | |||
|
226 | ||||
|
227 | ||||
|
228 | ||||
|
229 | return { | |||
|
230 | startState: function () { return { f: normal }; }, | |||
|
231 | copyState: function (s) { return { f: s.f }; }, | |||
|
232 | ||||
|
233 | token: function(stream, state) { | |||
|
234 | var t = state.f(stream, function(s) { state.f = s; }); | |||
|
235 | var w = stream.current(); | |||
|
236 | return (w in wellKnownWords) ? wellKnownWords[w] : t; | |||
|
237 | }, | |||
|
238 | ||||
|
239 | blockCommentStart: "{-", | |||
|
240 | blockCommentEnd: "-}", | |||
|
241 | lineComment: "--" | |||
|
242 | }; | |||
|
243 | ||||
|
244 | }); | |||
|
245 | ||||
|
246 | CodeMirror.defineMIME("text/x-haskell", "haskell"); |
@@ -0,0 +1,62 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Haskell mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="haskell.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../theme/elegant.css"> | |||
|
11 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
12 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
13 | </head> | |||
|
14 | <body> | |||
|
15 | <h1>CodeMirror: Haskell mode</h1> | |||
|
16 | ||||
|
17 | <form><textarea id="code" name="code"> | |||
|
18 | module UniquePerms ( | |||
|
19 | uniquePerms | |||
|
20 | ) | |||
|
21 | where | |||
|
22 | ||||
|
23 | -- | Find all unique permutations of a list where there might be duplicates. | |||
|
24 | uniquePerms :: (Eq a) => [a] -> [[a]] | |||
|
25 | uniquePerms = permBag . makeBag | |||
|
26 | ||||
|
27 | -- | An unordered collection where duplicate values are allowed, | |||
|
28 | -- but represented with a single value and a count. | |||
|
29 | type Bag a = [(a, Int)] | |||
|
30 | ||||
|
31 | makeBag :: (Eq a) => [a] -> Bag a | |||
|
32 | makeBag [] = [] | |||
|
33 | makeBag (a:as) = mix a $ makeBag as | |||
|
34 | where | |||
|
35 | mix a [] = [(a,1)] | |||
|
36 | mix a (bn@(b,n):bs) | a == b = (b,n+1):bs | |||
|
37 | | otherwise = bn : mix a bs | |||
|
38 | ||||
|
39 | permBag :: Bag a -> [[a]] | |||
|
40 | permBag [] = [[]] | |||
|
41 | permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs | |||
|
42 | where | |||
|
43 | oneOfEach [] = [] | |||
|
44 | oneOfEach (an@(a,n):bs) = | |||
|
45 | let bs' = if n == 1 then bs else (a,n-1):bs | |||
|
46 | in (a,bs') : mapSnd (an:) (oneOfEach bs) | |||
|
47 | ||||
|
48 | apSnd f (a,b) = (a, f b) | |||
|
49 | mapSnd = map . apSnd | |||
|
50 | </textarea></form> | |||
|
51 | ||||
|
52 | <script> | |||
|
53 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
54 | lineNumbers: true, | |||
|
55 | matchBrackets: true, | |||
|
56 | theme: "elegant" | |||
|
57 | }); | |||
|
58 | </script> | |||
|
59 | ||||
|
60 | <p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p> | |||
|
61 | </body> | |||
|
62 | </html> |
@@ -0,0 +1,429 b'' | |||||
|
1 | CodeMirror.defineMode("haxe", function(config, parserConfig) { | |||
|
2 | var indentUnit = config.indentUnit; | |||
|
3 | ||||
|
4 | // Tokenizer | |||
|
5 | ||||
|
6 | var keywords = function(){ | |||
|
7 | function kw(type) {return {type: type, style: "keyword"};} | |||
|
8 | var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"); | |||
|
9 | var operator = kw("operator"), atom = {type: "atom", style: "atom"}, attribute = {type:"attribute", style: "attribute"}; | |||
|
10 | var type = kw("typedef"); | |||
|
11 | return { | |||
|
12 | "if": A, "while": A, "else": B, "do": B, "try": B, | |||
|
13 | "return": C, "break": C, "continue": C, "new": C, "throw": C, | |||
|
14 | "var": kw("var"), "inline":attribute, "static": attribute, "using":kw("import"), | |||
|
15 | "public": attribute, "private": attribute, "cast": kw("cast"), "import": kw("import"), "macro": kw("macro"), | |||
|
16 | "function": kw("function"), "catch": kw("catch"), "untyped": kw("untyped"), "callback": kw("cb"), | |||
|
17 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), | |||
|
18 | "in": operator, "never": kw("property_access"), "trace":kw("trace"), | |||
|
19 | "class": type, "enum":type, "interface":type, "typedef":type, "extends":type, "implements":type, "dynamic":type, | |||
|
20 | "true": atom, "false": atom, "null": atom | |||
|
21 | }; | |||
|
22 | }(); | |||
|
23 | ||||
|
24 | var isOperatorChar = /[+\-*&%=<>!?|]/; | |||
|
25 | ||||
|
26 | function chain(stream, state, f) { | |||
|
27 | state.tokenize = f; | |||
|
28 | return f(stream, state); | |||
|
29 | } | |||
|
30 | ||||
|
31 | function nextUntilUnescaped(stream, end) { | |||
|
32 | var escaped = false, next; | |||
|
33 | while ((next = stream.next()) != null) { | |||
|
34 | if (next == end && !escaped) | |||
|
35 | return false; | |||
|
36 | escaped = !escaped && next == "\\"; | |||
|
37 | } | |||
|
38 | return escaped; | |||
|
39 | } | |||
|
40 | ||||
|
41 | // Used as scratch variables to communicate multiple values without | |||
|
42 | // consing up tons of objects. | |||
|
43 | var type, content; | |||
|
44 | function ret(tp, style, cont) { | |||
|
45 | type = tp; content = cont; | |||
|
46 | return style; | |||
|
47 | } | |||
|
48 | ||||
|
49 | function haxeTokenBase(stream, state) { | |||
|
50 | var ch = stream.next(); | |||
|
51 | if (ch == '"' || ch == "'") | |||
|
52 | return chain(stream, state, haxeTokenString(ch)); | |||
|
53 | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) | |||
|
54 | return ret(ch); | |||
|
55 | else if (ch == "0" && stream.eat(/x/i)) { | |||
|
56 | stream.eatWhile(/[\da-f]/i); | |||
|
57 | return ret("number", "number"); | |||
|
58 | } | |||
|
59 | else if (/\d/.test(ch) || ch == "-" && stream.eat(/\d/)) { | |||
|
60 | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); | |||
|
61 | return ret("number", "number"); | |||
|
62 | } | |||
|
63 | else if (state.reAllowed && (ch == "~" && stream.eat(/\//))) { | |||
|
64 | nextUntilUnescaped(stream, "/"); | |||
|
65 | stream.eatWhile(/[gimsu]/); | |||
|
66 | return ret("regexp", "string-2"); | |||
|
67 | } | |||
|
68 | else if (ch == "/") { | |||
|
69 | if (stream.eat("*")) { | |||
|
70 | return chain(stream, state, haxeTokenComment); | |||
|
71 | } | |||
|
72 | else if (stream.eat("/")) { | |||
|
73 | stream.skipToEnd(); | |||
|
74 | return ret("comment", "comment"); | |||
|
75 | } | |||
|
76 | else { | |||
|
77 | stream.eatWhile(isOperatorChar); | |||
|
78 | return ret("operator", null, stream.current()); | |||
|
79 | } | |||
|
80 | } | |||
|
81 | else if (ch == "#") { | |||
|
82 | stream.skipToEnd(); | |||
|
83 | return ret("conditional", "meta"); | |||
|
84 | } | |||
|
85 | else if (ch == "@") { | |||
|
86 | stream.eat(/:/); | |||
|
87 | stream.eatWhile(/[\w_]/); | |||
|
88 | return ret ("metadata", "meta"); | |||
|
89 | } | |||
|
90 | else if (isOperatorChar.test(ch)) { | |||
|
91 | stream.eatWhile(isOperatorChar); | |||
|
92 | return ret("operator", null, stream.current()); | |||
|
93 | } | |||
|
94 | else { | |||
|
95 | var word; | |||
|
96 | if(/[A-Z]/.test(ch)) | |||
|
97 | { | |||
|
98 | stream.eatWhile(/[\w_<>]/); | |||
|
99 | word = stream.current(); | |||
|
100 | return ret("type", "variable-3", word); | |||
|
101 | } | |||
|
102 | else | |||
|
103 | { | |||
|
104 | stream.eatWhile(/[\w_]/); | |||
|
105 | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; | |||
|
106 | return (known && state.kwAllowed) ? ret(known.type, known.style, word) : | |||
|
107 | ret("variable", "variable", word); | |||
|
108 | } | |||
|
109 | } | |||
|
110 | } | |||
|
111 | ||||
|
112 | function haxeTokenString(quote) { | |||
|
113 | return function(stream, state) { | |||
|
114 | if (!nextUntilUnescaped(stream, quote)) | |||
|
115 | state.tokenize = haxeTokenBase; | |||
|
116 | return ret("string", "string"); | |||
|
117 | }; | |||
|
118 | } | |||
|
119 | ||||
|
120 | function haxeTokenComment(stream, state) { | |||
|
121 | var maybeEnd = false, ch; | |||
|
122 | while (ch = stream.next()) { | |||
|
123 | if (ch == "/" && maybeEnd) { | |||
|
124 | state.tokenize = haxeTokenBase; | |||
|
125 | break; | |||
|
126 | } | |||
|
127 | maybeEnd = (ch == "*"); | |||
|
128 | } | |||
|
129 | return ret("comment", "comment"); | |||
|
130 | } | |||
|
131 | ||||
|
132 | // Parser | |||
|
133 | ||||
|
134 | var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true}; | |||
|
135 | ||||
|
136 | function HaxeLexical(indented, column, type, align, prev, info) { | |||
|
137 | this.indented = indented; | |||
|
138 | this.column = column; | |||
|
139 | this.type = type; | |||
|
140 | this.prev = prev; | |||
|
141 | this.info = info; | |||
|
142 | if (align != null) this.align = align; | |||
|
143 | } | |||
|
144 | ||||
|
145 | function inScope(state, varname) { | |||
|
146 | for (var v = state.localVars; v; v = v.next) | |||
|
147 | if (v.name == varname) return true; | |||
|
148 | } | |||
|
149 | ||||
|
150 | function parseHaxe(state, style, type, content, stream) { | |||
|
151 | var cc = state.cc; | |||
|
152 | // Communicate our context to the combinators. | |||
|
153 | // (Less wasteful than consing up a hundred closures on every call.) | |||
|
154 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; | |||
|
155 | ||||
|
156 | if (!state.lexical.hasOwnProperty("align")) | |||
|
157 | state.lexical.align = true; | |||
|
158 | ||||
|
159 | while(true) { | |||
|
160 | var combinator = cc.length ? cc.pop() : statement; | |||
|
161 | if (combinator(type, content)) { | |||
|
162 | while(cc.length && cc[cc.length - 1].lex) | |||
|
163 | cc.pop()(); | |||
|
164 | if (cx.marked) return cx.marked; | |||
|
165 | if (type == "variable" && inScope(state, content)) return "variable-2"; | |||
|
166 | if (type == "variable" && imported(state, content)) return "variable-3"; | |||
|
167 | return style; | |||
|
168 | } | |||
|
169 | } | |||
|
170 | } | |||
|
171 | ||||
|
172 | function imported(state, typename) | |||
|
173 | { | |||
|
174 | if (/[a-z]/.test(typename.charAt(0))) | |||
|
175 | return false; | |||
|
176 | var len = state.importedtypes.length; | |||
|
177 | for (var i = 0; i<len; i++) | |||
|
178 | if(state.importedtypes[i]==typename) return true; | |||
|
179 | } | |||
|
180 | ||||
|
181 | ||||
|
182 | function registerimport(importname) { | |||
|
183 | var state = cx.state; | |||
|
184 | for (var t = state.importedtypes; t; t = t.next) | |||
|
185 | if(t.name == importname) return; | |||
|
186 | state.importedtypes = { name: importname, next: state.importedtypes }; | |||
|
187 | } | |||
|
188 | // Combinator utils | |||
|
189 | ||||
|
190 | var cx = {state: null, column: null, marked: null, cc: null}; | |||
|
191 | function pass() { | |||
|
192 | for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); | |||
|
193 | } | |||
|
194 | function cont() { | |||
|
195 | pass.apply(null, arguments); | |||
|
196 | return true; | |||
|
197 | } | |||
|
198 | function register(varname) { | |||
|
199 | var state = cx.state; | |||
|
200 | if (state.context) { | |||
|
201 | cx.marked = "def"; | |||
|
202 | for (var v = state.localVars; v; v = v.next) | |||
|
203 | if (v.name == varname) return; | |||
|
204 | state.localVars = {name: varname, next: state.localVars}; | |||
|
205 | } | |||
|
206 | } | |||
|
207 | ||||
|
208 | // Combinators | |||
|
209 | ||||
|
210 | var defaultVars = {name: "this", next: null}; | |||
|
211 | function pushcontext() { | |||
|
212 | if (!cx.state.context) cx.state.localVars = defaultVars; | |||
|
213 | cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; | |||
|
214 | } | |||
|
215 | function popcontext() { | |||
|
216 | cx.state.localVars = cx.state.context.vars; | |||
|
217 | cx.state.context = cx.state.context.prev; | |||
|
218 | } | |||
|
219 | function pushlex(type, info) { | |||
|
220 | var result = function() { | |||
|
221 | var state = cx.state; | |||
|
222 | state.lexical = new HaxeLexical(state.indented, cx.stream.column(), type, null, state.lexical, info); | |||
|
223 | }; | |||
|
224 | result.lex = true; | |||
|
225 | return result; | |||
|
226 | } | |||
|
227 | function poplex() { | |||
|
228 | var state = cx.state; | |||
|
229 | if (state.lexical.prev) { | |||
|
230 | if (state.lexical.type == ")") | |||
|
231 | state.indented = state.lexical.indented; | |||
|
232 | state.lexical = state.lexical.prev; | |||
|
233 | } | |||
|
234 | } | |||
|
235 | poplex.lex = true; | |||
|
236 | ||||
|
237 | function expect(wanted) { | |||
|
238 | return function(type) { | |||
|
239 | if (type == wanted) return cont(); | |||
|
240 | else if (wanted == ";") return pass(); | |||
|
241 | else return cont(arguments.callee); | |||
|
242 | }; | |||
|
243 | } | |||
|
244 | ||||
|
245 | function statement(type) { | |||
|
246 | if (type == "@") return cont(metadef); | |||
|
247 | if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex); | |||
|
248 | if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex); | |||
|
249 | if (type == "keyword b") return cont(pushlex("form"), statement, poplex); | |||
|
250 | if (type == "{") return cont(pushlex("}"), pushcontext, block, poplex, popcontext); | |||
|
251 | if (type == ";") return cont(); | |||
|
252 | if (type == "attribute") return cont(maybeattribute); | |||
|
253 | if (type == "function") return cont(functiondef); | |||
|
254 | if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), | |||
|
255 | poplex, statement, poplex); | |||
|
256 | if (type == "variable") return cont(pushlex("stat"), maybelabel); | |||
|
257 | if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), | |||
|
258 | block, poplex, poplex); | |||
|
259 | if (type == "case") return cont(expression, expect(":")); | |||
|
260 | if (type == "default") return cont(expect(":")); | |||
|
261 | if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), | |||
|
262 | statement, poplex, popcontext); | |||
|
263 | if (type == "import") return cont(importdef, expect(";")); | |||
|
264 | if (type == "typedef") return cont(typedef); | |||
|
265 | return pass(pushlex("stat"), expression, expect(";"), poplex); | |||
|
266 | } | |||
|
267 | function expression(type) { | |||
|
268 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator); | |||
|
269 | if (type == "function") return cont(functiondef); | |||
|
270 | if (type == "keyword c") return cont(maybeexpression); | |||
|
271 | if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeoperator); | |||
|
272 | if (type == "operator") return cont(expression); | |||
|
273 | if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator); | |||
|
274 | if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator); | |||
|
275 | return cont(); | |||
|
276 | } | |||
|
277 | function maybeexpression(type) { | |||
|
278 | if (type.match(/[;\}\)\],]/)) return pass(); | |||
|
279 | return pass(expression); | |||
|
280 | } | |||
|
281 | ||||
|
282 | function maybeoperator(type, value) { | |||
|
283 | if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); | |||
|
284 | if (type == "operator" || type == ":") return cont(expression); | |||
|
285 | if (type == ";") return; | |||
|
286 | if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator); | |||
|
287 | if (type == ".") return cont(property, maybeoperator); | |||
|
288 | if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator); | |||
|
289 | } | |||
|
290 | ||||
|
291 | function maybeattribute(type) { | |||
|
292 | if (type == "attribute") return cont(maybeattribute); | |||
|
293 | if (type == "function") return cont(functiondef); | |||
|
294 | if (type == "var") return cont(vardef1); | |||
|
295 | } | |||
|
296 | ||||
|
297 | function metadef(type) { | |||
|
298 | if(type == ":") return cont(metadef); | |||
|
299 | if(type == "variable") return cont(metadef); | |||
|
300 | if(type == "(") return cont(pushlex(")"), comasep(metaargs, ")"), poplex, statement); | |||
|
301 | } | |||
|
302 | function metaargs(type) { | |||
|
303 | if(type == "variable") return cont(); | |||
|
304 | } | |||
|
305 | ||||
|
306 | function importdef (type, value) { | |||
|
307 | if(type == "variable" && /[A-Z]/.test(value.charAt(0))) { registerimport(value); return cont(); } | |||
|
308 | else if(type == "variable" || type == "property" || type == ".") return cont(importdef); | |||
|
309 | } | |||
|
310 | ||||
|
311 | function typedef (type, value) | |||
|
312 | { | |||
|
313 | if(type == "variable" && /[A-Z]/.test(value.charAt(0))) { registerimport(value); return cont(); } | |||
|
314 | } | |||
|
315 | ||||
|
316 | function maybelabel(type) { | |||
|
317 | if (type == ":") return cont(poplex, statement); | |||
|
318 | return pass(maybeoperator, expect(";"), poplex); | |||
|
319 | } | |||
|
320 | function property(type) { | |||
|
321 | if (type == "variable") {cx.marked = "property"; return cont();} | |||
|
322 | } | |||
|
323 | function objprop(type) { | |||
|
324 | if (type == "variable") cx.marked = "property"; | |||
|
325 | if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression); | |||
|
326 | } | |||
|
327 | function commasep(what, end) { | |||
|
328 | function proceed(type) { | |||
|
329 | if (type == ",") return cont(what, proceed); | |||
|
330 | if (type == end) return cont(); | |||
|
331 | return cont(expect(end)); | |||
|
332 | } | |||
|
333 | return function(type) { | |||
|
334 | if (type == end) return cont(); | |||
|
335 | else return pass(what, proceed); | |||
|
336 | }; | |||
|
337 | } | |||
|
338 | function block(type) { | |||
|
339 | if (type == "}") return cont(); | |||
|
340 | return pass(statement, block); | |||
|
341 | } | |||
|
342 | function vardef1(type, value) { | |||
|
343 | if (type == "variable"){register(value); return cont(typeuse, vardef2);} | |||
|
344 | return cont(); | |||
|
345 | } | |||
|
346 | function vardef2(type, value) { | |||
|
347 | if (value == "=") return cont(expression, vardef2); | |||
|
348 | if (type == ",") return cont(vardef1); | |||
|
349 | } | |||
|
350 | function forspec1(type, value) { | |||
|
351 | if (type == "variable") { | |||
|
352 | register(value); | |||
|
353 | } | |||
|
354 | return cont(pushlex(")"), pushcontext, forin, expression, poplex, statement, popcontext); | |||
|
355 | } | |||
|
356 | function forin(_type, value) { | |||
|
357 | if (value == "in") return cont(); | |||
|
358 | } | |||
|
359 | function functiondef(type, value) { | |||
|
360 | if (type == "variable") {register(value); return cont(functiondef);} | |||
|
361 | if (value == "new") return cont(functiondef); | |||
|
362 | if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, typeuse, statement, popcontext); | |||
|
363 | } | |||
|
364 | function typeuse(type) { | |||
|
365 | if(type == ":") return cont(typestring); | |||
|
366 | } | |||
|
367 | function typestring(type) { | |||
|
368 | if(type == "type") return cont(); | |||
|
369 | if(type == "variable") return cont(); | |||
|
370 | if(type == "{") return cont(pushlex("}"), commasep(typeprop, "}"), poplex); | |||
|
371 | } | |||
|
372 | function typeprop(type) { | |||
|
373 | if(type == "variable") return cont(typeuse); | |||
|
374 | } | |||
|
375 | function funarg(type, value) { | |||
|
376 | if (type == "variable") {register(value); return cont(typeuse);} | |||
|
377 | } | |||
|
378 | ||||
|
379 | // Interface | |||
|
380 | ||||
|
381 | return { | |||
|
382 | startState: function(basecolumn) { | |||
|
383 | var defaulttypes = ["Int", "Float", "String", "Void", "Std", "Bool", "Dynamic", "Array"]; | |||
|
384 | return { | |||
|
385 | tokenize: haxeTokenBase, | |||
|
386 | reAllowed: true, | |||
|
387 | kwAllowed: true, | |||
|
388 | cc: [], | |||
|
389 | lexical: new HaxeLexical((basecolumn || 0) - indentUnit, 0, "block", false), | |||
|
390 | localVars: parserConfig.localVars, | |||
|
391 | importedtypes: defaulttypes, | |||
|
392 | context: parserConfig.localVars && {vars: parserConfig.localVars}, | |||
|
393 | indented: 0 | |||
|
394 | }; | |||
|
395 | }, | |||
|
396 | ||||
|
397 | token: function(stream, state) { | |||
|
398 | if (stream.sol()) { | |||
|
399 | if (!state.lexical.hasOwnProperty("align")) | |||
|
400 | state.lexical.align = false; | |||
|
401 | state.indented = stream.indentation(); | |||
|
402 | } | |||
|
403 | if (stream.eatSpace()) return null; | |||
|
404 | var style = state.tokenize(stream, state); | |||
|
405 | if (type == "comment") return style; | |||
|
406 | state.reAllowed = !!(type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/)); | |||
|
407 | state.kwAllowed = type != '.'; | |||
|
408 | return parseHaxe(state, style, type, content, stream); | |||
|
409 | }, | |||
|
410 | ||||
|
411 | indent: function(state, textAfter) { | |||
|
412 | if (state.tokenize != haxeTokenBase) return 0; | |||
|
413 | var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; | |||
|
414 | if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; | |||
|
415 | var type = lexical.type, closing = firstChar == type; | |||
|
416 | if (type == "vardef") return lexical.indented + 4; | |||
|
417 | else if (type == "form" && firstChar == "{") return lexical.indented; | |||
|
418 | else if (type == "stat" || type == "form") return lexical.indented + indentUnit; | |||
|
419 | else if (lexical.info == "switch" && !closing) | |||
|
420 | return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); | |||
|
421 | else if (lexical.align) return lexical.column + (closing ? 0 : 1); | |||
|
422 | else return lexical.indented + (closing ? 0 : indentUnit); | |||
|
423 | }, | |||
|
424 | ||||
|
425 | electricChars: "{}" | |||
|
426 | }; | |||
|
427 | }); | |||
|
428 | ||||
|
429 | CodeMirror.defineMIME("text/x-haxe", "haxe"); |
@@ -0,0 +1,90 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Haxe mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="haxe.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Haxe mode</h1> | |||
|
14 | ||||
|
15 | <div><textarea id="code" name="code"> | |||
|
16 | import one.two.Three; | |||
|
17 | ||||
|
18 | @attr("test") | |||
|
19 | class Foo<T> extends Three | |||
|
20 | { | |||
|
21 | public function new() | |||
|
22 | { | |||
|
23 | noFoo = 12; | |||
|
24 | } | |||
|
25 | ||||
|
26 | public static inline function doFoo(obj:{k:Int, l:Float}):Int | |||
|
27 | { | |||
|
28 | for(i in 0...10) | |||
|
29 | { | |||
|
30 | obj.k++; | |||
|
31 | trace(i); | |||
|
32 | var var1 = new Array(); | |||
|
33 | if(var1.length > 1) | |||
|
34 | throw "Error"; | |||
|
35 | } | |||
|
36 | // The following line should not be colored, the variable is scoped out | |||
|
37 | var1; | |||
|
38 | /* Multi line | |||
|
39 | * Comment test | |||
|
40 | */ | |||
|
41 | return obj.k; | |||
|
42 | } | |||
|
43 | private function bar():Void | |||
|
44 | { | |||
|
45 | #if flash | |||
|
46 | var t1:String = "1.21"; | |||
|
47 | #end | |||
|
48 | try { | |||
|
49 | doFoo({k:3, l:1.2}); | |||
|
50 | } | |||
|
51 | catch (e : String) { | |||
|
52 | trace(e); | |||
|
53 | } | |||
|
54 | var t2:Float = cast(3.2); | |||
|
55 | var t3:haxe.Timer = new haxe.Timer(); | |||
|
56 | var t4 = {k:Std.int(t2), l:Std.parseFloat(t1)}; | |||
|
57 | var t5 = ~/123+.*$/i; | |||
|
58 | doFoo(t4); | |||
|
59 | untyped t1 = 4; | |||
|
60 | bob = new Foo<Int> | |||
|
61 | } | |||
|
62 | public var okFoo(default, never):Float; | |||
|
63 | var noFoo(getFoo, null):Int; | |||
|
64 | function getFoo():Int { | |||
|
65 | return noFoo; | |||
|
66 | } | |||
|
67 | ||||
|
68 | public var three:Int; | |||
|
69 | } | |||
|
70 | enum Color | |||
|
71 | { | |||
|
72 | red; | |||
|
73 | green; | |||
|
74 | blue; | |||
|
75 | grey( v : Int ); | |||
|
76 | rgb (r:Int,g:Int,b:Int); | |||
|
77 | } | |||
|
78 | </textarea></div> | |||
|
79 | ||||
|
80 | <script> | |||
|
81 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
82 | lineNumbers: true, | |||
|
83 | indentUnit: 4, | |||
|
84 | indentWithTabs: true | |||
|
85 | }); | |||
|
86 | </script> | |||
|
87 | ||||
|
88 | <p><strong>MIME types defined:</strong> <code>text/x-haxe</code>.</p> | |||
|
89 | </body> | |||
|
90 | </html> |
@@ -0,0 +1,73 b'' | |||||
|
1 | CodeMirror.defineMode("htmlembedded", function(config, parserConfig) { | |||
|
2 | ||||
|
3 | //config settings | |||
|
4 | var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i, | |||
|
5 | scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i; | |||
|
6 | ||||
|
7 | //inner modes | |||
|
8 | var scriptingMode, htmlMixedMode; | |||
|
9 | ||||
|
10 | //tokenizer when in html mode | |||
|
11 | function htmlDispatch(stream, state) { | |||
|
12 | if (stream.match(scriptStartRegex, false)) { | |||
|
13 | state.token=scriptingDispatch; | |||
|
14 | return scriptingMode.token(stream, state.scriptState); | |||
|
15 | } | |||
|
16 | else | |||
|
17 | return htmlMixedMode.token(stream, state.htmlState); | |||
|
18 | } | |||
|
19 | ||||
|
20 | //tokenizer when in scripting mode | |||
|
21 | function scriptingDispatch(stream, state) { | |||
|
22 | if (stream.match(scriptEndRegex, false)) { | |||
|
23 | state.token=htmlDispatch; | |||
|
24 | return htmlMixedMode.token(stream, state.htmlState); | |||
|
25 | } | |||
|
26 | else | |||
|
27 | return scriptingMode.token(stream, state.scriptState); | |||
|
28 | } | |||
|
29 | ||||
|
30 | ||||
|
31 | return { | |||
|
32 | startState: function() { | |||
|
33 | scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec); | |||
|
34 | htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed"); | |||
|
35 | return { | |||
|
36 | token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch, | |||
|
37 | htmlState : CodeMirror.startState(htmlMixedMode), | |||
|
38 | scriptState : CodeMirror.startState(scriptingMode) | |||
|
39 | }; | |||
|
40 | }, | |||
|
41 | ||||
|
42 | token: function(stream, state) { | |||
|
43 | return state.token(stream, state); | |||
|
44 | }, | |||
|
45 | ||||
|
46 | indent: function(state, textAfter) { | |||
|
47 | if (state.token == htmlDispatch) | |||
|
48 | return htmlMixedMode.indent(state.htmlState, textAfter); | |||
|
49 | else if (scriptingMode.indent) | |||
|
50 | return scriptingMode.indent(state.scriptState, textAfter); | |||
|
51 | }, | |||
|
52 | ||||
|
53 | copyState: function(state) { | |||
|
54 | return { | |||
|
55 | token : state.token, | |||
|
56 | htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState), | |||
|
57 | scriptState : CodeMirror.copyState(scriptingMode, state.scriptState) | |||
|
58 | }; | |||
|
59 | }, | |||
|
60 | ||||
|
61 | electricChars: "/{}:", | |||
|
62 | ||||
|
63 | innerMode: function(state) { | |||
|
64 | if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode}; | |||
|
65 | else return {state: state.htmlState, mode: htmlMixedMode}; | |||
|
66 | } | |||
|
67 | }; | |||
|
68 | }, "htmlmixed"); | |||
|
69 | ||||
|
70 | CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"}); | |||
|
71 | CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"}); | |||
|
72 | CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"}); | |||
|
73 | CodeMirror.defineMIME("application/x-erb", { name: "htmlembedded", scriptingModeSpec:"ruby"}); |
@@ -0,0 +1,49 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Html Embedded Scripts mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../xml/xml.js"></script> | |||
|
9 | <script src="../javascript/javascript.js"></script> | |||
|
10 | <script src="../css/css.js"></script> | |||
|
11 | <script src="../htmlmixed/htmlmixed.js"></script> | |||
|
12 | <script src="htmlembedded.js"></script> | |||
|
13 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
14 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
15 | </head> | |||
|
16 | <body> | |||
|
17 | <h1>CodeMirror: Html Embedded Scripts mode</h1> | |||
|
18 | ||||
|
19 | <form><textarea id="code" name="code"> | |||
|
20 | <% | |||
|
21 | function hello(who) { | |||
|
22 | return "Hello " + who; | |||
|
23 | } | |||
|
24 | %> | |||
|
25 | This is an example of EJS (embedded javascript) | |||
|
26 | <p>The program says <%= hello("world") %>.</p> | |||
|
27 | <script> | |||
|
28 | alert("And here is some normal JS code"); // also colored | |||
|
29 | </script> | |||
|
30 | </textarea></form> | |||
|
31 | ||||
|
32 | <script> | |||
|
33 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
34 | lineNumbers: true, | |||
|
35 | mode: "application/x-ejs", | |||
|
36 | indentUnit: 4, | |||
|
37 | indentWithTabs: true, | |||
|
38 | enterMode: "keep", | |||
|
39 | tabMode: "shift" | |||
|
40 | }); | |||
|
41 | </script> | |||
|
42 | ||||
|
43 | <p>Mode for html embedded scripts like JSP and ASP.NET. Depends on HtmlMixed which in turn depends on | |||
|
44 | JavaScript, CSS and XML.<br />Other dependancies include those of the scriping language chosen.</p> | |||
|
45 | ||||
|
46 | <p><strong>MIME types defined:</strong> <code>application/x-aspx</code> (ASP.NET), | |||
|
47 | <code>application/x-ejs</code> (Embedded Javascript), <code>application/x-jsp</code> (JavaServer Pages)</p> | |||
|
48 | </body> | |||
|
49 | </html> |
@@ -0,0 +1,104 b'' | |||||
|
1 | CodeMirror.defineMode("htmlmixed", function(config, parserConfig) { | |||
|
2 | var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true}); | |||
|
3 | var cssMode = CodeMirror.getMode(config, "css"); | |||
|
4 | ||||
|
5 | var scriptTypes = [], scriptTypesConf = parserConfig && parserConfig.scriptTypes; | |||
|
6 | scriptTypes.push({matches: /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i, | |||
|
7 | mode: CodeMirror.getMode(config, "javascript")}); | |||
|
8 | if (scriptTypesConf) for (var i = 0; i < scriptTypesConf.length; ++i) { | |||
|
9 | var conf = scriptTypesConf[i]; | |||
|
10 | scriptTypes.push({matches: conf.matches, mode: conf.mode && CodeMirror.getMode(config, conf.mode)}); | |||
|
11 | } | |||
|
12 | scriptTypes.push({matches: /./, | |||
|
13 | mode: CodeMirror.getMode(config, "text/plain")}); | |||
|
14 | ||||
|
15 | function html(stream, state) { | |||
|
16 | var tagName = state.htmlState.tagName; | |||
|
17 | var style = htmlMode.token(stream, state.htmlState); | |||
|
18 | if (tagName == "script" && /\btag\b/.test(style) && stream.current() == ">") { | |||
|
19 | // Script block: mode to change to depends on type attribute | |||
|
20 | var scriptType = stream.string.slice(Math.max(0, stream.pos - 100), stream.pos).match(/\btype\s*=\s*("[^"]+"|'[^']+'|\S+)[^<]*$/i); | |||
|
21 | scriptType = scriptType ? scriptType[1] : ""; | |||
|
22 | if (scriptType && /[\"\']/.test(scriptType.charAt(0))) scriptType = scriptType.slice(1, scriptType.length - 1); | |||
|
23 | for (var i = 0; i < scriptTypes.length; ++i) { | |||
|
24 | var tp = scriptTypes[i]; | |||
|
25 | if (typeof tp.matches == "string" ? scriptType == tp.matches : tp.matches.test(scriptType)) { | |||
|
26 | if (tp.mode) { | |||
|
27 | state.token = script; | |||
|
28 | state.localMode = tp.mode; | |||
|
29 | state.localState = tp.mode.startState && tp.mode.startState(htmlMode.indent(state.htmlState, "")); | |||
|
30 | } | |||
|
31 | break; | |||
|
32 | } | |||
|
33 | } | |||
|
34 | } else if (tagName == "style" && /\btag\b/.test(style) && stream.current() == ">") { | |||
|
35 | state.token = css; | |||
|
36 | state.localMode = cssMode; | |||
|
37 | state.localState = cssMode.startState(htmlMode.indent(state.htmlState, "")); | |||
|
38 | } | |||
|
39 | return style; | |||
|
40 | } | |||
|
41 | function maybeBackup(stream, pat, style) { | |||
|
42 | var cur = stream.current(); | |||
|
43 | var close = cur.search(pat), m; | |||
|
44 | if (close > -1) stream.backUp(cur.length - close); | |||
|
45 | else if (m = cur.match(/<\/?$/)) { | |||
|
46 | stream.backUp(cur.length); | |||
|
47 | if (!stream.match(pat, false)) stream.match(cur[0]); | |||
|
48 | } | |||
|
49 | return style; | |||
|
50 | } | |||
|
51 | function script(stream, state) { | |||
|
52 | if (stream.match(/^<\/\s*script\s*>/i, false)) { | |||
|
53 | state.token = html; | |||
|
54 | state.localState = state.localMode = null; | |||
|
55 | return html(stream, state); | |||
|
56 | } | |||
|
57 | return maybeBackup(stream, /<\/\s*script\s*>/, | |||
|
58 | state.localMode.token(stream, state.localState)); | |||
|
59 | } | |||
|
60 | function css(stream, state) { | |||
|
61 | if (stream.match(/^<\/\s*style\s*>/i, false)) { | |||
|
62 | state.token = html; | |||
|
63 | state.localState = state.localMode = null; | |||
|
64 | return html(stream, state); | |||
|
65 | } | |||
|
66 | return maybeBackup(stream, /<\/\s*style\s*>/, | |||
|
67 | cssMode.token(stream, state.localState)); | |||
|
68 | } | |||
|
69 | ||||
|
70 | return { | |||
|
71 | startState: function() { | |||
|
72 | var state = htmlMode.startState(); | |||
|
73 | return {token: html, localMode: null, localState: null, htmlState: state}; | |||
|
74 | }, | |||
|
75 | ||||
|
76 | copyState: function(state) { | |||
|
77 | if (state.localState) | |||
|
78 | var local = CodeMirror.copyState(state.localMode, state.localState); | |||
|
79 | return {token: state.token, localMode: state.localMode, localState: local, | |||
|
80 | htmlState: CodeMirror.copyState(htmlMode, state.htmlState)}; | |||
|
81 | }, | |||
|
82 | ||||
|
83 | token: function(stream, state) { | |||
|
84 | return state.token(stream, state); | |||
|
85 | }, | |||
|
86 | ||||
|
87 | indent: function(state, textAfter) { | |||
|
88 | if (!state.localMode || /^\s*<\//.test(textAfter)) | |||
|
89 | return htmlMode.indent(state.htmlState, textAfter); | |||
|
90 | else if (state.localMode.indent) | |||
|
91 | return state.localMode.indent(state.localState, textAfter); | |||
|
92 | else | |||
|
93 | return CodeMirror.Pass; | |||
|
94 | }, | |||
|
95 | ||||
|
96 | electricChars: "/{}:", | |||
|
97 | ||||
|
98 | innerMode: function(state) { | |||
|
99 | return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode}; | |||
|
100 | } | |||
|
101 | }; | |||
|
102 | }, "xml", "javascript", "css"); | |||
|
103 | ||||
|
104 | CodeMirror.defineMIME("text/html", "htmlmixed"); |
@@ -0,0 +1,73 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: HTML mixed mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../xml/xml.js"></script> | |||
|
9 | <script src="../javascript/javascript.js"></script> | |||
|
10 | <script src="../css/css.js"></script> | |||
|
11 | <script src="../vbscript/vbscript.js"></script> | |||
|
12 | <script src="htmlmixed.js"></script> | |||
|
13 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
14 | <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
15 | </head> | |||
|
16 | <body> | |||
|
17 | <h1>CodeMirror: HTML mixed mode</h1> | |||
|
18 | <form><textarea id="code" name="code"> | |||
|
19 | <html style="color: green"> | |||
|
20 | <!-- this is a comment --> | |||
|
21 | <head> | |||
|
22 | <title>Mixed HTML Example</title> | |||
|
23 | <style type="text/css"> | |||
|
24 | h1 {font-family: comic sans; color: #f0f;} | |||
|
25 | div {background: yellow !important;} | |||
|
26 | body { | |||
|
27 | max-width: 50em; | |||
|
28 | margin: 1em 2em 1em 5em; | |||
|
29 | } | |||
|
30 | </style> | |||
|
31 | </head> | |||
|
32 | <body> | |||
|
33 | <h1>Mixed HTML Example</h1> | |||
|
34 | <script> | |||
|
35 | function jsFunc(arg1, arg2) { | |||
|
36 | if (arg1 && arg2) document.body.innerHTML = "achoo"; | |||
|
37 | } | |||
|
38 | </script> | |||
|
39 | </body> | |||
|
40 | </html> | |||
|
41 | </textarea></form> | |||
|
42 | <script> | |||
|
43 | // Define an extended mixed-mode that understands vbscript and | |||
|
44 | // leaves mustache/handlebars embedded templates in html mode | |||
|
45 | var mixedMode = { | |||
|
46 | name: "htmlmixed", | |||
|
47 | scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i, | |||
|
48 | mode: null}, | |||
|
49 | {matches: /(text|application)\/(x-)?vb(a|script)/i, | |||
|
50 | mode: "vbscript"}] | |||
|
51 | }; | |||
|
52 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: mixedMode, tabMode: "indent"}); | |||
|
53 | </script> | |||
|
54 | ||||
|
55 | <p>The HTML mixed mode depends on the XML, JavaScript, and CSS modes.</p> | |||
|
56 | ||||
|
57 | <p>It takes an optional mode configuration | |||
|
58 | option, <code>scriptTypes</code>, which can be used to add custom | |||
|
59 | behavior for specific <code><script type="..."></code> tags. If | |||
|
60 | given, it should hold an array of <code>{matches, mode}</code> | |||
|
61 | objects, where <code>matches</code> is a string or regexp that | |||
|
62 | matches the script type, and <code>mode</code> is | |||
|
63 | either <code>null</code>, for script types that should stay in | |||
|
64 | HTML mode, or a <a href="../../doc/manual.html#option_mode">mode | |||
|
65 | spec</a> corresponding to the mode that should be used for the | |||
|
66 | script.</p> | |||
|
67 | ||||
|
68 | <p><strong>MIME types defined:</strong> <code>text/html</code> | |||
|
69 | (redefined, only takes effect if you load this parser after the | |||
|
70 | XML parser).</p> | |||
|
71 | ||||
|
72 | </body> | |||
|
73 | </html> |
@@ -0,0 +1,98 b'' | |||||
|
1 | CodeMirror.defineMode("http", function() { | |||
|
2 | function failFirstLine(stream, state) { | |||
|
3 | stream.skipToEnd(); | |||
|
4 | state.cur = header; | |||
|
5 | return "error"; | |||
|
6 | } | |||
|
7 | ||||
|
8 | function start(stream, state) { | |||
|
9 | if (stream.match(/^HTTP\/\d\.\d/)) { | |||
|
10 | state.cur = responseStatusCode; | |||
|
11 | return "keyword"; | |||
|
12 | } else if (stream.match(/^[A-Z]+/) && /[ \t]/.test(stream.peek())) { | |||
|
13 | state.cur = requestPath; | |||
|
14 | return "keyword"; | |||
|
15 | } else { | |||
|
16 | return failFirstLine(stream, state); | |||
|
17 | } | |||
|
18 | } | |||
|
19 | ||||
|
20 | function responseStatusCode(stream, state) { | |||
|
21 | var code = stream.match(/^\d+/); | |||
|
22 | if (!code) return failFirstLine(stream, state); | |||
|
23 | ||||
|
24 | state.cur = responseStatusText; | |||
|
25 | var status = Number(code[0]); | |||
|
26 | if (status >= 100 && status < 200) { | |||
|
27 | return "positive informational"; | |||
|
28 | } else if (status >= 200 && status < 300) { | |||
|
29 | return "positive success"; | |||
|
30 | } else if (status >= 300 && status < 400) { | |||
|
31 | return "positive redirect"; | |||
|
32 | } else if (status >= 400 && status < 500) { | |||
|
33 | return "negative client-error"; | |||
|
34 | } else if (status >= 500 && status < 600) { | |||
|
35 | return "negative server-error"; | |||
|
36 | } else { | |||
|
37 | return "error"; | |||
|
38 | } | |||
|
39 | } | |||
|
40 | ||||
|
41 | function responseStatusText(stream, state) { | |||
|
42 | stream.skipToEnd(); | |||
|
43 | state.cur = header; | |||
|
44 | return null; | |||
|
45 | } | |||
|
46 | ||||
|
47 | function requestPath(stream, state) { | |||
|
48 | stream.eatWhile(/\S/); | |||
|
49 | state.cur = requestProtocol; | |||
|
50 | return "string-2"; | |||
|
51 | } | |||
|
52 | ||||
|
53 | function requestProtocol(stream, state) { | |||
|
54 | if (stream.match(/^HTTP\/\d\.\d$/)) { | |||
|
55 | state.cur = header; | |||
|
56 | return "keyword"; | |||
|
57 | } else { | |||
|
58 | return failFirstLine(stream, state); | |||
|
59 | } | |||
|
60 | } | |||
|
61 | ||||
|
62 | function header(stream) { | |||
|
63 | if (stream.sol() && !stream.eat(/[ \t]/)) { | |||
|
64 | if (stream.match(/^.*?:/)) { | |||
|
65 | return "atom"; | |||
|
66 | } else { | |||
|
67 | stream.skipToEnd(); | |||
|
68 | return "error"; | |||
|
69 | } | |||
|
70 | } else { | |||
|
71 | stream.skipToEnd(); | |||
|
72 | return "string"; | |||
|
73 | } | |||
|
74 | } | |||
|
75 | ||||
|
76 | function body(stream) { | |||
|
77 | stream.skipToEnd(); | |||
|
78 | return null; | |||
|
79 | } | |||
|
80 | ||||
|
81 | return { | |||
|
82 | token: function(stream, state) { | |||
|
83 | var cur = state.cur; | |||
|
84 | if (cur != header && cur != body && stream.eatSpace()) return null; | |||
|
85 | return cur(stream, state); | |||
|
86 | }, | |||
|
87 | ||||
|
88 | blankLine: function(state) { | |||
|
89 | state.cur = body; | |||
|
90 | }, | |||
|
91 | ||||
|
92 | startState: function() { | |||
|
93 | return {cur: start}; | |||
|
94 | } | |||
|
95 | }; | |||
|
96 | }); | |||
|
97 | ||||
|
98 | CodeMirror.defineMIME("message/http", "http"); |
@@ -0,0 +1,32 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: HTTP mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="http.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: HTTP mode</h1> | |||
|
14 | ||||
|
15 | <div><textarea id="code" name="code"> | |||
|
16 | POST /somewhere HTTP/1.1 | |||
|
17 | Host: example.com | |||
|
18 | If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT | |||
|
19 | Content-Type: application/x-www-form-urlencoded; | |||
|
20 | charset=utf-8 | |||
|
21 | User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11 | |||
|
22 | ||||
|
23 | This is the request body! | |||
|
24 | </textarea></div> | |||
|
25 | ||||
|
26 | <script> | |||
|
27 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); | |||
|
28 | </script> | |||
|
29 | ||||
|
30 | <p><strong>MIME types defined:</strong> <code>message/http</code>.</p> | |||
|
31 | </body> | |||
|
32 | </html> |
@@ -0,0 +1,94 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: JavaScript mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="../../addon/edit/continuecomment.js"></script> | |||
|
10 | <script src="../../addon/comment/comment.js"></script> | |||
|
11 | <script src="javascript.js"></script> | |||
|
12 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
13 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
14 | </head> | |||
|
15 | <body> | |||
|
16 | <h1>CodeMirror: JavaScript mode</h1> | |||
|
17 | ||||
|
18 | <div><textarea id="code" name="code"> | |||
|
19 | // Demo code (the actual new parser character stream implementation) | |||
|
20 | ||||
|
21 | function StringStream(string) { | |||
|
22 | this.pos = 0; | |||
|
23 | this.string = string; | |||
|
24 | } | |||
|
25 | ||||
|
26 | StringStream.prototype = { | |||
|
27 | done: function() {return this.pos >= this.string.length;}, | |||
|
28 | peek: function() {return this.string.charAt(this.pos);}, | |||
|
29 | next: function() { | |||
|
30 | if (this.pos < this.string.length) | |||
|
31 | return this.string.charAt(this.pos++); | |||
|
32 | }, | |||
|
33 | eat: function(match) { | |||
|
34 | var ch = this.string.charAt(this.pos); | |||
|
35 | if (typeof match == "string") var ok = ch == match; | |||
|
36 | else var ok = ch && match.test ? match.test(ch) : match(ch); | |||
|
37 | if (ok) {this.pos++; return ch;} | |||
|
38 | }, | |||
|
39 | eatWhile: function(match) { | |||
|
40 | var start = this.pos; | |||
|
41 | while (this.eat(match)); | |||
|
42 | if (this.pos > start) return this.string.slice(start, this.pos); | |||
|
43 | }, | |||
|
44 | backUp: function(n) {this.pos -= n;}, | |||
|
45 | column: function() {return this.pos;}, | |||
|
46 | eatSpace: function() { | |||
|
47 | var start = this.pos; | |||
|
48 | while (/\s/.test(this.string.charAt(this.pos))) this.pos++; | |||
|
49 | return this.pos - start; | |||
|
50 | }, | |||
|
51 | match: function(pattern, consume, caseInsensitive) { | |||
|
52 | if (typeof pattern == "string") { | |||
|
53 | function cased(str) {return caseInsensitive ? str.toLowerCase() : str;} | |||
|
54 | if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) { | |||
|
55 | if (consume !== false) this.pos += str.length; | |||
|
56 | return true; | |||
|
57 | } | |||
|
58 | } | |||
|
59 | else { | |||
|
60 | var match = this.string.slice(this.pos).match(pattern); | |||
|
61 | if (match && consume !== false) this.pos += match[0].length; | |||
|
62 | return match; | |||
|
63 | } | |||
|
64 | } | |||
|
65 | }; | |||
|
66 | </textarea></div> | |||
|
67 | ||||
|
68 | <script> | |||
|
69 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
70 | lineNumbers: true, | |||
|
71 | matchBrackets: true, | |||
|
72 | continueComments: "Enter", | |||
|
73 | extraKeys: {"Ctrl-Q": "toggleComment"} | |||
|
74 | }); | |||
|
75 | </script> | |||
|
76 | ||||
|
77 | <p> | |||
|
78 | JavaScript mode supports a two configuration | |||
|
79 | options: | |||
|
80 | <ul> | |||
|
81 | <li><code>json</code> which will set the mode to expect JSON | |||
|
82 | data rather than a JavaScript program.</li> | |||
|
83 | <li><code>typescript</code> which will activate additional | |||
|
84 | syntax highlighting and some other things for TypeScript code | |||
|
85 | (<a href="typescript.html">demo</a>).</li> | |||
|
86 | <li><code>statementIndent</code> which (given a number) will | |||
|
87 | determine the amount of indentation to use for statements | |||
|
88 | continued on a new line.</li> | |||
|
89 | </ul> | |||
|
90 | </p> | |||
|
91 | ||||
|
92 | <p><strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>, <code>text/typescript</code>, <code>application/typescript</code>.</p> | |||
|
93 | </body> | |||
|
94 | </html> |
@@ -0,0 +1,476 b'' | |||||
|
1 | // TODO actually recognize syntax of TypeScript constructs | |||
|
2 | ||||
|
3 | CodeMirror.defineMode("javascript", function(config, parserConfig) { | |||
|
4 | var indentUnit = config.indentUnit; | |||
|
5 | var statementIndent = parserConfig.statementIndent; | |||
|
6 | var jsonMode = parserConfig.json; | |||
|
7 | var isTS = parserConfig.typescript; | |||
|
8 | ||||
|
9 | // Tokenizer | |||
|
10 | ||||
|
11 | var keywords = function(){ | |||
|
12 | function kw(type) {return {type: type, style: "keyword"};} | |||
|
13 | var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"); | |||
|
14 | var operator = kw("operator"), atom = {type: "atom", style: "atom"}; | |||
|
15 | ||||
|
16 | var jsKeywords = { | |||
|
17 | "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, | |||
|
18 | "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, | |||
|
19 | "var": kw("var"), "const": kw("var"), "let": kw("var"), | |||
|
20 | "function": kw("function"), "catch": kw("catch"), | |||
|
21 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), | |||
|
22 | "in": operator, "typeof": operator, "instanceof": operator, | |||
|
23 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, | |||
|
24 | "this": kw("this") | |||
|
25 | }; | |||
|
26 | ||||
|
27 | // Extend the 'normal' keywords with the TypeScript language extensions | |||
|
28 | if (isTS) { | |||
|
29 | var type = {type: "variable", style: "variable-3"}; | |||
|
30 | var tsKeywords = { | |||
|
31 | // object-like things | |||
|
32 | "interface": kw("interface"), | |||
|
33 | "class": kw("class"), | |||
|
34 | "extends": kw("extends"), | |||
|
35 | "constructor": kw("constructor"), | |||
|
36 | ||||
|
37 | // scope modifiers | |||
|
38 | "public": kw("public"), | |||
|
39 | "private": kw("private"), | |||
|
40 | "protected": kw("protected"), | |||
|
41 | "static": kw("static"), | |||
|
42 | ||||
|
43 | "super": kw("super"), | |||
|
44 | ||||
|
45 | // types | |||
|
46 | "string": type, "number": type, "bool": type, "any": type | |||
|
47 | }; | |||
|
48 | ||||
|
49 | for (var attr in tsKeywords) { | |||
|
50 | jsKeywords[attr] = tsKeywords[attr]; | |||
|
51 | } | |||
|
52 | } | |||
|
53 | ||||
|
54 | return jsKeywords; | |||
|
55 | }(); | |||
|
56 | ||||
|
57 | var isOperatorChar = /[+\-*&%=<>!?|~^]/; | |||
|
58 | ||||
|
59 | function chain(stream, state, f) { | |||
|
60 | state.tokenize = f; | |||
|
61 | return f(stream, state); | |||
|
62 | } | |||
|
63 | ||||
|
64 | function nextUntilUnescaped(stream, end) { | |||
|
65 | var escaped = false, next; | |||
|
66 | while ((next = stream.next()) != null) { | |||
|
67 | if (next == end && !escaped) | |||
|
68 | return false; | |||
|
69 | escaped = !escaped && next == "\\"; | |||
|
70 | } | |||
|
71 | return escaped; | |||
|
72 | } | |||
|
73 | ||||
|
74 | // Used as scratch variables to communicate multiple values without | |||
|
75 | // consing up tons of objects. | |||
|
76 | var type, content; | |||
|
77 | function ret(tp, style, cont) { | |||
|
78 | type = tp; content = cont; | |||
|
79 | return style; | |||
|
80 | } | |||
|
81 | ||||
|
82 | function jsTokenBase(stream, state) { | |||
|
83 | var ch = stream.next(); | |||
|
84 | if (ch == '"' || ch == "'") | |||
|
85 | return chain(stream, state, jsTokenString(ch)); | |||
|
86 | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) | |||
|
87 | return ret(ch); | |||
|
88 | else if (ch == "0" && stream.eat(/x/i)) { | |||
|
89 | stream.eatWhile(/[\da-f]/i); | |||
|
90 | return ret("number", "number"); | |||
|
91 | } | |||
|
92 | else if (/\d/.test(ch) || ch == "-" && stream.eat(/\d/)) { | |||
|
93 | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); | |||
|
94 | return ret("number", "number"); | |||
|
95 | } | |||
|
96 | else if (ch == "/") { | |||
|
97 | if (stream.eat("*")) { | |||
|
98 | return chain(stream, state, jsTokenComment); | |||
|
99 | } | |||
|
100 | else if (stream.eat("/")) { | |||
|
101 | stream.skipToEnd(); | |||
|
102 | return ret("comment", "comment"); | |||
|
103 | } | |||
|
104 | else if (state.lastType == "operator" || state.lastType == "keyword c" || | |||
|
105 | /^[\[{}\(,;:]$/.test(state.lastType)) { | |||
|
106 | nextUntilUnescaped(stream, "/"); | |||
|
107 | stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla | |||
|
108 | return ret("regexp", "string-2"); | |||
|
109 | } | |||
|
110 | else { | |||
|
111 | stream.eatWhile(isOperatorChar); | |||
|
112 | return ret("operator", null, stream.current()); | |||
|
113 | } | |||
|
114 | } | |||
|
115 | else if (ch == "#") { | |||
|
116 | stream.skipToEnd(); | |||
|
117 | return ret("error", "error"); | |||
|
118 | } | |||
|
119 | else if (isOperatorChar.test(ch)) { | |||
|
120 | stream.eatWhile(isOperatorChar); | |||
|
121 | return ret("operator", null, stream.current()); | |||
|
122 | } | |||
|
123 | else { | |||
|
124 | stream.eatWhile(/[\w\$_]/); | |||
|
125 | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; | |||
|
126 | return (known && state.lastType != ".") ? ret(known.type, known.style, word) : | |||
|
127 | ret("variable", "variable", word); | |||
|
128 | } | |||
|
129 | } | |||
|
130 | ||||
|
131 | function jsTokenString(quote) { | |||
|
132 | return function(stream, state) { | |||
|
133 | if (!nextUntilUnescaped(stream, quote)) | |||
|
134 | state.tokenize = jsTokenBase; | |||
|
135 | return ret("string", "string"); | |||
|
136 | }; | |||
|
137 | } | |||
|
138 | ||||
|
139 | function jsTokenComment(stream, state) { | |||
|
140 | var maybeEnd = false, ch; | |||
|
141 | while (ch = stream.next()) { | |||
|
142 | if (ch == "/" && maybeEnd) { | |||
|
143 | state.tokenize = jsTokenBase; | |||
|
144 | break; | |||
|
145 | } | |||
|
146 | maybeEnd = (ch == "*"); | |||
|
147 | } | |||
|
148 | return ret("comment", "comment"); | |||
|
149 | } | |||
|
150 | ||||
|
151 | // Parser | |||
|
152 | ||||
|
153 | var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true}; | |||
|
154 | ||||
|
155 | function JSLexical(indented, column, type, align, prev, info) { | |||
|
156 | this.indented = indented; | |||
|
157 | this.column = column; | |||
|
158 | this.type = type; | |||
|
159 | this.prev = prev; | |||
|
160 | this.info = info; | |||
|
161 | if (align != null) this.align = align; | |||
|
162 | } | |||
|
163 | ||||
|
164 | function inScope(state, varname) { | |||
|
165 | for (var v = state.localVars; v; v = v.next) | |||
|
166 | if (v.name == varname) return true; | |||
|
167 | } | |||
|
168 | ||||
|
169 | function parseJS(state, style, type, content, stream) { | |||
|
170 | var cc = state.cc; | |||
|
171 | // Communicate our context to the combinators. | |||
|
172 | // (Less wasteful than consing up a hundred closures on every call.) | |||
|
173 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; | |||
|
174 | ||||
|
175 | if (!state.lexical.hasOwnProperty("align")) | |||
|
176 | state.lexical.align = true; | |||
|
177 | ||||
|
178 | while(true) { | |||
|
179 | var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; | |||
|
180 | if (combinator(type, content)) { | |||
|
181 | while(cc.length && cc[cc.length - 1].lex) | |||
|
182 | cc.pop()(); | |||
|
183 | if (cx.marked) return cx.marked; | |||
|
184 | if (type == "variable" && inScope(state, content)) return "variable-2"; | |||
|
185 | return style; | |||
|
186 | } | |||
|
187 | } | |||
|
188 | } | |||
|
189 | ||||
|
190 | // Combinator utils | |||
|
191 | ||||
|
192 | var cx = {state: null, column: null, marked: null, cc: null}; | |||
|
193 | function pass() { | |||
|
194 | for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); | |||
|
195 | } | |||
|
196 | function cont() { | |||
|
197 | pass.apply(null, arguments); | |||
|
198 | return true; | |||
|
199 | } | |||
|
200 | function register(varname) { | |||
|
201 | function inList(list) { | |||
|
202 | for (var v = list; v; v = v.next) | |||
|
203 | if (v.name == varname) return true; | |||
|
204 | return false; | |||
|
205 | } | |||
|
206 | var state = cx.state; | |||
|
207 | if (state.context) { | |||
|
208 | cx.marked = "def"; | |||
|
209 | if (inList(state.localVars)) return; | |||
|
210 | state.localVars = {name: varname, next: state.localVars}; | |||
|
211 | } else { | |||
|
212 | if (inList(state.globalVars)) return; | |||
|
213 | state.globalVars = {name: varname, next: state.globalVars}; | |||
|
214 | } | |||
|
215 | } | |||
|
216 | ||||
|
217 | // Combinators | |||
|
218 | ||||
|
219 | var defaultVars = {name: "this", next: {name: "arguments"}}; | |||
|
220 | function pushcontext() { | |||
|
221 | cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; | |||
|
222 | cx.state.localVars = defaultVars; | |||
|
223 | } | |||
|
224 | function popcontext() { | |||
|
225 | cx.state.localVars = cx.state.context.vars; | |||
|
226 | cx.state.context = cx.state.context.prev; | |||
|
227 | } | |||
|
228 | function pushlex(type, info) { | |||
|
229 | var result = function() { | |||
|
230 | var state = cx.state, indent = state.indented; | |||
|
231 | if (state.lexical.type == "stat") indent = state.lexical.indented; | |||
|
232 | state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info); | |||
|
233 | }; | |||
|
234 | result.lex = true; | |||
|
235 | return result; | |||
|
236 | } | |||
|
237 | function poplex() { | |||
|
238 | var state = cx.state; | |||
|
239 | if (state.lexical.prev) { | |||
|
240 | if (state.lexical.type == ")") | |||
|
241 | state.indented = state.lexical.indented; | |||
|
242 | state.lexical = state.lexical.prev; | |||
|
243 | } | |||
|
244 | } | |||
|
245 | poplex.lex = true; | |||
|
246 | ||||
|
247 | function expect(wanted) { | |||
|
248 | return function(type) { | |||
|
249 | if (type == wanted) return cont(); | |||
|
250 | else if (wanted == ";") return pass(); | |||
|
251 | else return cont(arguments.callee); | |||
|
252 | }; | |||
|
253 | } | |||
|
254 | ||||
|
255 | function statement(type) { | |||
|
256 | if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex); | |||
|
257 | if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex); | |||
|
258 | if (type == "keyword b") return cont(pushlex("form"), statement, poplex); | |||
|
259 | if (type == "{") return cont(pushlex("}"), block, poplex); | |||
|
260 | if (type == ";") return cont(); | |||
|
261 | if (type == "if") return cont(pushlex("form"), expression, statement, poplex, maybeelse(cx.state.indented)); | |||
|
262 | if (type == "function") return cont(functiondef); | |||
|
263 | if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), | |||
|
264 | poplex, statement, poplex); | |||
|
265 | if (type == "variable") return cont(pushlex("stat"), maybelabel); | |||
|
266 | if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), | |||
|
267 | block, poplex, poplex); | |||
|
268 | if (type == "case") return cont(expression, expect(":")); | |||
|
269 | if (type == "default") return cont(expect(":")); | |||
|
270 | if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), | |||
|
271 | statement, poplex, popcontext); | |||
|
272 | return pass(pushlex("stat"), expression, expect(";"), poplex); | |||
|
273 | } | |||
|
274 | function expression(type) { | |||
|
275 | return expressionInner(type, false); | |||
|
276 | } | |||
|
277 | function expressionNoComma(type) { | |||
|
278 | return expressionInner(type, true); | |||
|
279 | } | |||
|
280 | function expressionInner(type, noComma) { | |||
|
281 | var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma; | |||
|
282 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeop); | |||
|
283 | if (type == "function") return cont(functiondef); | |||
|
284 | if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression); | |||
|
285 | if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop); | |||
|
286 | if (type == "operator") return cont(noComma ? expressionNoComma : expression); | |||
|
287 | if (type == "[") return cont(pushlex("]"), commasep(expressionNoComma, "]"), poplex, maybeop); | |||
|
288 | if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeop); | |||
|
289 | return cont(); | |||
|
290 | } | |||
|
291 | function maybeexpression(type) { | |||
|
292 | if (type.match(/[;\}\)\],]/)) return pass(); | |||
|
293 | return pass(expression); | |||
|
294 | } | |||
|
295 | function maybeexpressionNoComma(type) { | |||
|
296 | if (type.match(/[;\}\)\],]/)) return pass(); | |||
|
297 | return pass(expressionNoComma); | |||
|
298 | } | |||
|
299 | ||||
|
300 | function maybeoperatorComma(type, value) { | |||
|
301 | if (type == ",") return cont(expression); | |||
|
302 | return maybeoperatorNoComma(type, value, maybeoperatorComma); | |||
|
303 | } | |||
|
304 | function maybeoperatorNoComma(type, value, me) { | |||
|
305 | if (!me) me = maybeoperatorNoComma; | |||
|
306 | if (type == "operator") { | |||
|
307 | if (/\+\+|--/.test(value)) return cont(me); | |||
|
308 | if (value == "?") return cont(expression, expect(":"), expression); | |||
|
309 | return cont(expression); | |||
|
310 | } | |||
|
311 | if (type == ";") return; | |||
|
312 | if (type == "(") return cont(pushlex(")", "call"), commasep(expressionNoComma, ")"), poplex, me); | |||
|
313 | if (type == ".") return cont(property, me); | |||
|
314 | if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, me); | |||
|
315 | } | |||
|
316 | function maybelabel(type) { | |||
|
317 | if (type == ":") return cont(poplex, statement); | |||
|
318 | return pass(maybeoperatorComma, expect(";"), poplex); | |||
|
319 | } | |||
|
320 | function property(type) { | |||
|
321 | if (type == "variable") {cx.marked = "property"; return cont();} | |||
|
322 | } | |||
|
323 | function objprop(type, value) { | |||
|
324 | if (type == "variable") { | |||
|
325 | cx.marked = "property"; | |||
|
326 | if (value == "get" || value == "set") return cont(getterSetter); | |||
|
327 | } else if (type == "number" || type == "string") { | |||
|
328 | cx.marked = type + " property"; | |||
|
329 | } | |||
|
330 | if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expressionNoComma); | |||
|
331 | } | |||
|
332 | function getterSetter(type) { | |||
|
333 | if (type == ":") return cont(expression); | |||
|
334 | if (type != "variable") return cont(expect(":"), expression); | |||
|
335 | cx.marked = "property"; | |||
|
336 | return cont(functiondef); | |||
|
337 | } | |||
|
338 | function commasep(what, end) { | |||
|
339 | function proceed(type) { | |||
|
340 | if (type == ",") { | |||
|
341 | var lex = cx.state.lexical; | |||
|
342 | if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; | |||
|
343 | return cont(what, proceed); | |||
|
344 | } | |||
|
345 | if (type == end) return cont(); | |||
|
346 | return cont(expect(end)); | |||
|
347 | } | |||
|
348 | return function(type) { | |||
|
349 | if (type == end) return cont(); | |||
|
350 | else return pass(what, proceed); | |||
|
351 | }; | |||
|
352 | } | |||
|
353 | function block(type) { | |||
|
354 | if (type == "}") return cont(); | |||
|
355 | return pass(statement, block); | |||
|
356 | } | |||
|
357 | function maybetype(type) { | |||
|
358 | if (type == ":") return cont(typedef); | |||
|
359 | return pass(); | |||
|
360 | } | |||
|
361 | function typedef(type) { | |||
|
362 | if (type == "variable"){cx.marked = "variable-3"; return cont();} | |||
|
363 | return pass(); | |||
|
364 | } | |||
|
365 | function vardef1(type, value) { | |||
|
366 | if (type == "variable") { | |||
|
367 | register(value); | |||
|
368 | return isTS ? cont(maybetype, vardef2) : cont(vardef2); | |||
|
369 | } | |||
|
370 | return pass(); | |||
|
371 | } | |||
|
372 | function vardef2(type, value) { | |||
|
373 | if (value == "=") return cont(expressionNoComma, vardef2); | |||
|
374 | if (type == ",") return cont(vardef1); | |||
|
375 | } | |||
|
376 | function maybeelse(indent) { | |||
|
377 | return function(type, value) { | |||
|
378 | if (type == "keyword b" && value == "else") { | |||
|
379 | cx.state.lexical = new JSLexical(indent, 0, "form", null, cx.state.lexical); | |||
|
380 | return cont(statement, poplex); | |||
|
381 | } | |||
|
382 | return pass(); | |||
|
383 | }; | |||
|
384 | } | |||
|
385 | function forspec1(type) { | |||
|
386 | if (type == "var") return cont(vardef1, expect(";"), forspec2); | |||
|
387 | if (type == ";") return cont(forspec2); | |||
|
388 | if (type == "variable") return cont(formaybein); | |||
|
389 | return pass(expression, expect(";"), forspec2); | |||
|
390 | } | |||
|
391 | function formaybein(_type, value) { | |||
|
392 | if (value == "in") return cont(expression); | |||
|
393 | return cont(maybeoperatorComma, forspec2); | |||
|
394 | } | |||
|
395 | function forspec2(type, value) { | |||
|
396 | if (type == ";") return cont(forspec3); | |||
|
397 | if (value == "in") return cont(expression); | |||
|
398 | return pass(expression, expect(";"), forspec3); | |||
|
399 | } | |||
|
400 | function forspec3(type) { | |||
|
401 | if (type != ")") cont(expression); | |||
|
402 | } | |||
|
403 | function functiondef(type, value) { | |||
|
404 | if (type == "variable") {register(value); return cont(functiondef);} | |||
|
405 | if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext); | |||
|
406 | } | |||
|
407 | function funarg(type, value) { | |||
|
408 | if (type == "variable") {register(value); return isTS ? cont(maybetype) : cont();} | |||
|
409 | } | |||
|
410 | ||||
|
411 | // Interface | |||
|
412 | ||||
|
413 | return { | |||
|
414 | startState: function(basecolumn) { | |||
|
415 | return { | |||
|
416 | tokenize: jsTokenBase, | |||
|
417 | lastType: null, | |||
|
418 | cc: [], | |||
|
419 | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), | |||
|
420 | localVars: parserConfig.localVars, | |||
|
421 | globalVars: parserConfig.globalVars, | |||
|
422 | context: parserConfig.localVars && {vars: parserConfig.localVars}, | |||
|
423 | indented: 0 | |||
|
424 | }; | |||
|
425 | }, | |||
|
426 | ||||
|
427 | token: function(stream, state) { | |||
|
428 | if (stream.sol()) { | |||
|
429 | if (!state.lexical.hasOwnProperty("align")) | |||
|
430 | state.lexical.align = false; | |||
|
431 | state.indented = stream.indentation(); | |||
|
432 | } | |||
|
433 | if (state.tokenize != jsTokenComment && stream.eatSpace()) return null; | |||
|
434 | var style = state.tokenize(stream, state); | |||
|
435 | if (type == "comment") return style; | |||
|
436 | state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type; | |||
|
437 | return parseJS(state, style, type, content, stream); | |||
|
438 | }, | |||
|
439 | ||||
|
440 | indent: function(state, textAfter) { | |||
|
441 | if (state.tokenize == jsTokenComment) return CodeMirror.Pass; | |||
|
442 | if (state.tokenize != jsTokenBase) return 0; | |||
|
443 | var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; | |||
|
444 | if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; | |||
|
445 | if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat") | |||
|
446 | lexical = lexical.prev; | |||
|
447 | var type = lexical.type, closing = firstChar == type; | |||
|
448 | ||||
|
449 | if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? 4 : 0); | |||
|
450 | else if (type == "form" && firstChar == "{") return lexical.indented; | |||
|
451 | else if (type == "form") return lexical.indented + indentUnit; | |||
|
452 | else if (type == "stat") | |||
|
453 | return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndent || indentUnit : 0); | |||
|
454 | else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) | |||
|
455 | return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); | |||
|
456 | else if (lexical.align) return lexical.column + (closing ? 0 : 1); | |||
|
457 | else return lexical.indented + (closing ? 0 : indentUnit); | |||
|
458 | }, | |||
|
459 | ||||
|
460 | electricChars: ":{}", | |||
|
461 | blockCommentStart: jsonMode ? null : "/*", | |||
|
462 | blockCommentEnd: jsonMode ? null : "*/", | |||
|
463 | lineComment: jsonMode ? null : "//", | |||
|
464 | ||||
|
465 | jsonMode: jsonMode | |||
|
466 | }; | |||
|
467 | }); | |||
|
468 | ||||
|
469 | CodeMirror.defineMIME("text/javascript", "javascript"); | |||
|
470 | CodeMirror.defineMIME("text/ecmascript", "javascript"); | |||
|
471 | CodeMirror.defineMIME("application/javascript", "javascript"); | |||
|
472 | CodeMirror.defineMIME("application/ecmascript", "javascript"); | |||
|
473 | CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); | |||
|
474 | CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true}); | |||
|
475 | CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); | |||
|
476 | CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true }); |
@@ -0,0 +1,48 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: TypeScript mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="javascript.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: TypeScript mode</h1> | |||
|
14 | ||||
|
15 | <div><textarea id="code" name="code"> | |||
|
16 | class Greeter { | |||
|
17 | greeting: string; | |||
|
18 | constructor (message: string) { | |||
|
19 | this.greeting = message; | |||
|
20 | } | |||
|
21 | greet() { | |||
|
22 | return "Hello, " + this.greeting; | |||
|
23 | } | |||
|
24 | } | |||
|
25 | ||||
|
26 | var greeter = new Greeter("world"); | |||
|
27 | ||||
|
28 | var button = document.createElement('button') | |||
|
29 | button.innerText = "Say Hello" | |||
|
30 | button.onclick = function() { | |||
|
31 | alert(greeter.greet()) | |||
|
32 | } | |||
|
33 | ||||
|
34 | document.body.appendChild(button) | |||
|
35 | ||||
|
36 | </textarea></div> | |||
|
37 | ||||
|
38 | <script> | |||
|
39 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
40 | lineNumbers: true, | |||
|
41 | matchBrackets: true, | |||
|
42 | mode: "text/typescript" | |||
|
43 | }); | |||
|
44 | </script> | |||
|
45 | ||||
|
46 | <p>This is a specialization of the <a href="index.html">JavaScript mode</a>.</p> | |||
|
47 | </body> | |||
|
48 | </html> |
@@ -0,0 +1,38 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Jinja2 mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="jinja2.js"></script> | |||
|
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
10 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Jinja2 mode</h1> | |||
|
14 | <form><textarea id="code" name="code"> | |||
|
15 | <html style="color: green"> | |||
|
16 | <!-- this is a comment --> | |||
|
17 | <head> | |||
|
18 | <title>Jinja2 Example</title> | |||
|
19 | </head> | |||
|
20 | <body> | |||
|
21 | <ul> | |||
|
22 | {# this is a comment #} | |||
|
23 | {%- for item in li -%} | |||
|
24 | <li> | |||
|
25 | {{ item.label }} | |||
|
26 | </li> | |||
|
27 | {% endfor -%} | |||
|
28 | </ul> | |||
|
29 | </body> | |||
|
30 | </html> | |||
|
31 | </textarea></form> | |||
|
32 | <script> | |||
|
33 | var editor = | |||
|
34 | CodeMirror.fromTextArea(document.getElementById("code"), {mode: | |||
|
35 | {name: "jinja2", htmlMode: true}}); | |||
|
36 | </script> | |||
|
37 | </body> | |||
|
38 | </html> |
@@ -0,0 +1,42 b'' | |||||
|
1 | CodeMirror.defineMode("jinja2", function() { | |||
|
2 | var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false", | |||
|
3 | "loop", "none", "self", "super", "if", "as", "not", "and", | |||
|
4 | "else", "import", "with", "without", "context"]; | |||
|
5 | keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); | |||
|
6 | ||||
|
7 | function tokenBase (stream, state) { | |||
|
8 | var ch = stream.next(); | |||
|
9 | if (ch == "{") { | |||
|
10 | if (ch = stream.eat(/\{|%|#/)) { | |||
|
11 | stream.eat("-"); | |||
|
12 | state.tokenize = inTag(ch); | |||
|
13 | return "tag"; | |||
|
14 | } | |||
|
15 | } | |||
|
16 | } | |||
|
17 | function inTag (close) { | |||
|
18 | if (close == "{") { | |||
|
19 | close = "}"; | |||
|
20 | } | |||
|
21 | return function (stream, state) { | |||
|
22 | var ch = stream.next(); | |||
|
23 | if ((ch == close || (ch == "-" && stream.eat(close))) | |||
|
24 | && stream.eat("}")) { | |||
|
25 | state.tokenize = tokenBase; | |||
|
26 | return "tag"; | |||
|
27 | } | |||
|
28 | if (stream.match(keywords)) { | |||
|
29 | return "keyword"; | |||
|
30 | } | |||
|
31 | return close == "#" ? "comment" : "string"; | |||
|
32 | }; | |||
|
33 | } | |||
|
34 | return { | |||
|
35 | startState: function () { | |||
|
36 | return {tokenize: tokenBase}; | |||
|
37 | }, | |||
|
38 | token: function (stream, state) { | |||
|
39 | return state.tokenize(stream, state); | |||
|
40 | } | |||
|
41 | }; | |||
|
42 | }); |
This diff has been collapsed as it changes many lines, (741 lines changed) Show them Hide them | |||||
@@ -0,0 +1,741 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: LESS mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
9 | <script src="less.js"></script> | |||
|
10 | <style>.CodeMirror {background: #f8f8f8; border: 1px solid #ddd; font-size:12px; height: 400px}</style> | |||
|
11 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
12 | <link rel="stylesheet" href="../../theme/lesser-dark.css"> | |||
|
13 | </head> | |||
|
14 | <body> | |||
|
15 | <h1>CodeMirror: LESS mode</h1> | |||
|
16 | <form><textarea id="code" name="code">@media screen and (device-aspect-ratio: 16/9) { … } | |||
|
17 | @media screen and (device-aspect-ratio: 32/18) { … } | |||
|
18 | @media screen and (device-aspect-ratio: 1280/720) { … } | |||
|
19 | @media screen and (device-aspect-ratio: 2560/1440) { … } | |||
|
20 | ||||
|
21 | html:lang(fr-be) | |||
|
22 | html:lang(de) | |||
|
23 | :lang(fr-be) > q | |||
|
24 | :lang(de) > q | |||
|
25 | ||||
|
26 | tr:nth-child(2n+1) /* represents every odd row of an HTML table */ | |||
|
27 | tr:nth-child(odd) /* same */ | |||
|
28 | tr:nth-child(2n+0) /* represents every even row of an HTML table */ | |||
|
29 | tr:nth-child(even) /* same */ | |||
|
30 | ||||
|
31 | /* Alternate paragraph colours in CSS */ | |||
|
32 | p:nth-child(4n+1) { color: navy; } | |||
|
33 | p:nth-child(4n+2) { color: green; } | |||
|
34 | p:nth-child(4n+3) { color: maroon; } | |||
|
35 | p:nth-child(4n+4) { color: purple; } | |||
|
36 | ||||
|
37 | :nth-child(10n-1) /* represents the 9th, 19th, 29th, etc, element */ | |||
|
38 | :nth-child(10n+9) /* Same */ | |||
|
39 | :nth-child(10n+-1) /* Syntactically invalid, and would be ignored */ | |||
|
40 | ||||
|
41 | :nth-child( 3n + 1 ) | |||
|
42 | :nth-child( +3n - 2 ) | |||
|
43 | :nth-child( -n+ 6) | |||
|
44 | :nth-child( +6 ) | |||
|
45 | ||||
|
46 | html|tr:nth-child(-n+6) /* represents the 6 first rows of XHTML tables */ | |||
|
47 | ||||
|
48 | img:nth-of-type(2n+1) { float: right; } | |||
|
49 | img:nth-of-type(2n) { float: left; } | |||
|
50 | ||||
|
51 | body > h2:nth-of-type(n+2):nth-last-of-type(n+2) | |||
|
52 | body > h2:not(:first-of-type):not(:last-of-type) | |||
|
53 | ||||
|
54 | html|*:not(:link):not(:visited) | |||
|
55 | *|*:not(:hover) | |||
|
56 | p::first-line { text-transform: uppercase } | |||
|
57 | ||||
|
58 | p { color: red; font-size: 12pt } | |||
|
59 | p::first-letter { color: green; font-size: 200% } | |||
|
60 | p::first-line { color: blue } | |||
|
61 | ||||
|
62 | p { line-height: 1.1 } | |||
|
63 | p::first-letter { font-size: 3em; font-weight: normal } | |||
|
64 | span { font-weight: bold } | |||
|
65 | ||||
|
66 | * /* a=0 b=0 c=0 -> specificity = 0 */ | |||
|
67 | LI /* a=0 b=0 c=1 -> specificity = 1 */ | |||
|
68 | UL LI /* a=0 b=0 c=2 -> specificity = 2 */ | |||
|
69 | UL OL+LI /* a=0 b=0 c=3 -> specificity = 3 */ | |||
|
70 | H1 + *[REL=up] /* a=0 b=1 c=1 -> specificity = 11 */ | |||
|
71 | UL OL LI.red /* a=0 b=1 c=3 -> specificity = 13 */ | |||
|
72 | LI.red.level /* a=0 b=2 c=1 -> specificity = 21 */ | |||
|
73 | #x34y /* a=1 b=0 c=0 -> specificity = 100 */ | |||
|
74 | #s12:not(FOO) /* a=1 b=0 c=1 -> specificity = 101 */ | |||
|
75 | ||||
|
76 | @namespace foo url(http://www.example.com); | |||
|
77 | foo|h1 { color: blue } /* first rule */ | |||
|
78 | foo|* { color: yellow } /* second rule */ | |||
|
79 | |h1 { color: red } /* ...*/ | |||
|
80 | *|h1 { color: green } | |||
|
81 | h1 { color: green } | |||
|
82 | ||||
|
83 | span[hello="Ocean"][goodbye="Land"] | |||
|
84 | ||||
|
85 | a[rel~="copyright"] { ... } | |||
|
86 | a[href="http://www.w3.org/"] { ... } | |||
|
87 | ||||
|
88 | DIALOGUE[character=romeo] | |||
|
89 | DIALOGUE[character=juliet] | |||
|
90 | ||||
|
91 | [att^=val] | |||
|
92 | [att$=val] | |||
|
93 | [att*=val] | |||
|
94 | ||||
|
95 | @namespace foo "http://www.example.com"; | |||
|
96 | [foo|att=val] { color: blue } | |||
|
97 | [*|att] { color: yellow } | |||
|
98 | [|att] { color: green } | |||
|
99 | [att] { color: green } | |||
|
100 | ||||
|
101 | ||||
|
102 | *:target { color : red } | |||
|
103 | *:target::before { content : url(target.png) } | |||
|
104 | ||||
|
105 | E[foo]{ | |||
|
106 | padding:65px; | |||
|
107 | } | |||
|
108 | E[foo] ~ F{ | |||
|
109 | padding:65px; | |||
|
110 | } | |||
|
111 | E#myid{ | |||
|
112 | padding:65px; | |||
|
113 | } | |||
|
114 | input[type="search"]::-webkit-search-decoration, | |||
|
115 | input[type="search"]::-webkit-search-cancel-button { | |||
|
116 | -webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5 | |||
|
117 | } | |||
|
118 | button::-moz-focus-inner, | |||
|
119 | input::-moz-focus-inner { // Inner padding and border oddities in FF3/4 | |||
|
120 | padding: 0; | |||
|
121 | border: 0; | |||
|
122 | } | |||
|
123 | .btn { | |||
|
124 | // reset here as of 2.0.3 due to Recess property order | |||
|
125 | border-color: #ccc; | |||
|
126 | border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25); | |||
|
127 | } | |||
|
128 | fieldset span button, fieldset span input[type="file"] { | |||
|
129 | font-size:12px; | |||
|
130 | font-family:Arial, Helvetica, sans-serif; | |||
|
131 | } | |||
|
132 | .el tr:nth-child(even):last-child td:first-child{ | |||
|
133 | -moz-border-radius-bottomleft:3px; | |||
|
134 | -webkit-border-bottom-left-radius:3px; | |||
|
135 | border-bottom-left-radius:3px; | |||
|
136 | } | |||
|
137 | ||||
|
138 | /* Some LESS code */ | |||
|
139 | ||||
|
140 | button { | |||
|
141 | width: 32px; | |||
|
142 | height: 32px; | |||
|
143 | border: 0; | |||
|
144 | margin: 4px; | |||
|
145 | cursor: pointer; | |||
|
146 | } | |||
|
147 | button.icon-plus { background: url(http://dahlström.net/tmp/sharp-icons/svg-icon-target.svg#plus) no-repeat; } | |||
|
148 | button.icon-chart { background: url(http://dahlström.net/tmp/sharp-icons/svg-icon-target.svg#chart) no-repeat; } | |||
|
149 | ||||
|
150 | button:hover { background-color: #999; } | |||
|
151 | button:active { background-color: #666; } | |||
|
152 | ||||
|
153 | @test_a: #eeeQQQ;//this is not a valid hex value and thus parsed as an element id | |||
|
154 | @test_b: #eeeFFF //this is a valid hex value but the declaration doesn't end with a semicolon and thus parsed as an element id | |||
|
155 | ||||
|
156 | #eee aaa .box | |||
|
157 | { | |||
|
158 | #test bbb { | |||
|
159 | width: 500px; | |||
|
160 | height: 250px; | |||
|
161 | background-image: url(dir/output/sheep.png), url( betweengrassandsky.png ); | |||
|
162 | background-position: center bottom, left top; | |||
|
163 | background-repeat: no-repeat; | |||
|
164 | } | |||
|
165 | } | |||
|
166 | ||||
|
167 | @base: #f938ab; | |||
|
168 | ||||
|
169 | .box-shadow(@style, @c) when (iscolor(@c)) { | |||
|
170 | box-shadow: @style @c; | |||
|
171 | -webkit-box-shadow: @style @c; | |||
|
172 | -moz-box-shadow: @style @c; | |||
|
173 | } | |||
|
174 | .box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) { | |||
|
175 | .box-shadow(@style, rgba(0, 0, 0, @alpha)); | |||
|
176 | } | |||
|
177 | ||||
|
178 | @color: #4D926F; | |||
|
179 | ||||
|
180 | #header { | |||
|
181 | color: @color; | |||
|
182 | color: #000000; | |||
|
183 | } | |||
|
184 | h2 { | |||
|
185 | color: @color; | |||
|
186 | } | |||
|
187 | ||||
|
188 | .rounded-corners (@radius: 5px) { | |||
|
189 | border-radius: @radius; | |||
|
190 | -webkit-border-radius: @radius; | |||
|
191 | -moz-border-radius: @radius; | |||
|
192 | } | |||
|
193 | ||||
|
194 | #header { | |||
|
195 | .rounded-corners; | |||
|
196 | } | |||
|
197 | #footer { | |||
|
198 | .rounded-corners(10px); | |||
|
199 | } | |||
|
200 | ||||
|
201 | .box-shadow (@x: 0, @y: 0, @blur: 1px, @alpha) { | |||
|
202 | @val: @x @y @blur rgba(0, 0, 0, @alpha); | |||
|
203 | ||||
|
204 | box-shadow: @val; | |||
|
205 | -webkit-box-shadow: @val; | |||
|
206 | -moz-box-shadow: @val; | |||
|
207 | } | |||
|
208 | .box { @base: #f938ab; | |||
|
209 | color: saturate(@base, 5%); | |||
|
210 | border-color: lighten(@base, 30%); | |||
|
211 | div { .box-shadow(0, 0, 5px, 0.4) } | |||
|
212 | } | |||
|
213 | ||||
|
214 | @import url("something.css"); | |||
|
215 | ||||
|
216 | @light-blue: hsl(190, 50%, 65%); | |||
|
217 | @light-yellow: desaturate(#fefec8, 10%); | |||
|
218 | @dark-yellow: desaturate(darken(@light-yellow, 10%), 40%); | |||
|
219 | @darkest: hsl(20, 0%, 15%); | |||
|
220 | @dark: hsl(190, 20%, 30%); | |||
|
221 | @medium: hsl(10, 60%, 30%); | |||
|
222 | @light: hsl(90, 40%, 20%); | |||
|
223 | @lightest: hsl(90, 20%, 90%); | |||
|
224 | @highlight: hsl(80, 50%, 90%); | |||
|
225 | @blue: hsl(210, 60%, 20%); | |||
|
226 | @alpha-blue: hsla(210, 60%, 40%, 0.5); | |||
|
227 | ||||
|
228 | .box-shadow (@x, @y, @blur, @alpha) { | |||
|
229 | @value: @x @y @blur rgba(0, 0, 0, @alpha); | |||
|
230 | box-shadow: @value; | |||
|
231 | -moz-box-shadow: @value; | |||
|
232 | -webkit-box-shadow: @value; | |||
|
233 | } | |||
|
234 | .border-radius (@radius) { | |||
|
235 | border-radius: @radius; | |||
|
236 | -moz-border-radius: @radius; | |||
|
237 | -webkit-border-radius: @radius; | |||
|
238 | } | |||
|
239 | ||||
|
240 | .border-radius (@radius, bottom) { | |||
|
241 | border-top-right-radius: 0; | |||
|
242 | border-top-left-radius: 0; | |||
|
243 | -moz-border-top-right-radius: 0; | |||
|
244 | -moz-border-top-left-radius: 0; | |||
|
245 | -webkit-border-top-left-radius: 0; | |||
|
246 | -webkit-border-top-right-radius: 0; | |||
|
247 | } | |||
|
248 | .border-radius (@radius, right) { | |||
|
249 | border-bottom-left-radius: 0; | |||
|
250 | border-top-left-radius: 0; | |||
|
251 | -moz-border-bottom-left-radius: 0; | |||
|
252 | -moz-border-top-left-radius: 0; | |||
|
253 | -webkit-border-bottom-left-radius: 0; | |||
|
254 | -webkit-border-top-left-radius: 0; | |||
|
255 | } | |||
|
256 | .box-shadow-inset (@x, @y, @blur, @color) { | |||
|
257 | box-shadow: @x @y @blur @color inset; | |||
|
258 | -moz-box-shadow: @x @y @blur @color inset; | |||
|
259 | -webkit-box-shadow: @x @y @blur @color inset; | |||
|
260 | } | |||
|
261 | .code () { | |||
|
262 | font-family: 'Bitstream Vera Sans Mono', | |||
|
263 | 'DejaVu Sans Mono', | |||
|
264 | 'Monaco', | |||
|
265 | Courier, | |||
|
266 | monospace !important; | |||
|
267 | } | |||
|
268 | .wrap () { | |||
|
269 | text-wrap: wrap; | |||
|
270 | white-space: pre-wrap; /* css-3 */ | |||
|
271 | white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ | |||
|
272 | white-space: -pre-wrap; /* Opera 4-6 */ | |||
|
273 | white-space: -o-pre-wrap; /* Opera 7 */ | |||
|
274 | word-wrap: break-word; /* Internet Explorer 5.5+ */ | |||
|
275 | } | |||
|
276 | ||||
|
277 | html { margin: 0 } | |||
|
278 | body { | |||
|
279 | background-color: @darkest; | |||
|
280 | margin: 0 auto; | |||
|
281 | font-family: Arial, sans-serif; | |||
|
282 | font-size: 100%; | |||
|
283 | overflow-x: hidden; | |||
|
284 | } | |||
|
285 | nav, header, footer, section, article { | |||
|
286 | display: block; | |||
|
287 | } | |||
|
288 | a { | |||
|
289 | color: #b83000; | |||
|
290 | } | |||
|
291 | h1 a { | |||
|
292 | color: black; | |||
|
293 | text-decoration: none; | |||
|
294 | } | |||
|
295 | a:hover { | |||
|
296 | text-decoration: underline; | |||
|
297 | } | |||
|
298 | h1, h2, h3, h4 { | |||
|
299 | margin: 0; | |||
|
300 | font-weight: normal; | |||
|
301 | } | |||
|
302 | ul, li { | |||
|
303 | list-style-type: none; | |||
|
304 | } | |||
|
305 | code { .code; } | |||
|
306 | code { | |||
|
307 | .string, .regexp { color: @dark } | |||
|
308 | .keyword { font-weight: bold } | |||
|
309 | .comment { color: rgba(0, 0, 0, 0.5) } | |||
|
310 | .number { color: @blue } | |||
|
311 | .class, .special { color: rgba(0, 50, 100, 0.8) } | |||
|
312 | } | |||
|
313 | pre { | |||
|
314 | padding: 0 30px; | |||
|
315 | .wrap; | |||
|
316 | } | |||
|
317 | blockquote { | |||
|
318 | font-style: italic; | |||
|
319 | } | |||
|
320 | body > footer { | |||
|
321 | text-align: left; | |||
|
322 | margin-left: 10px; | |||
|
323 | font-style: italic; | |||
|
324 | font-size: 18px; | |||
|
325 | color: #888; | |||
|
326 | } | |||
|
327 | ||||
|
328 | #logo { | |||
|
329 | margin-top: 30px; | |||
|
330 | margin-bottom: 30px; | |||
|
331 | display: block; | |||
|
332 | width: 199px; | |||
|
333 | height: 81px; | |||
|
334 | background: url(/images/logo.png) no-repeat; | |||
|
335 | } | |||
|
336 | nav { | |||
|
337 | margin-left: 15px; | |||
|
338 | } | |||
|
339 | nav a, #dropdown li { | |||
|
340 | display: inline-block; | |||
|
341 | color: white; | |||
|
342 | line-height: 42px; | |||
|
343 | margin: 0; | |||
|
344 | padding: 0px 15px; | |||
|
345 | text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.5); | |||
|
346 | text-decoration: none; | |||
|
347 | border: 2px solid transparent; | |||
|
348 | border-width: 0 2px; | |||
|
349 | &:hover { | |||
|
350 | .dark-red; | |||
|
351 | text-decoration: none; | |||
|
352 | } | |||
|
353 | } | |||
|
354 | .dark-red { | |||
|
355 | @red: @medium; | |||
|
356 | border: 2px solid darken(@red, 25%); | |||
|
357 | border-left-color: darken(@red, 15%); | |||
|
358 | border-right-color: darken(@red, 15%); | |||
|
359 | border-bottom: 0; | |||
|
360 | border-top: 0; | |||
|
361 | background-color: darken(@red, 10%); | |||
|
362 | } | |||
|
363 | ||||
|
364 | .content { | |||
|
365 | margin: 0 auto; | |||
|
366 | width: 980px; | |||
|
367 | } | |||
|
368 | ||||
|
369 | #menu { | |||
|
370 | position: absolute; | |||
|
371 | width: 100%; | |||
|
372 | z-index: 3; | |||
|
373 | clear: both; | |||
|
374 | display: block; | |||
|
375 | background-color: @blue; | |||
|
376 | height: 42px; | |||
|
377 | border-top: 2px solid lighten(@alpha-blue, 20%); | |||
|
378 | border-bottom: 2px solid darken(@alpha-blue, 25%); | |||
|
379 | .box-shadow(0, 1px, 8px, 0.6); | |||
|
380 | -moz-box-shadow: 0 0 0 #000; // Because firefox sucks. | |||
|
381 | ||||
|
382 | &.docked { | |||
|
383 | background-color: hsla(210, 60%, 40%, 0.4); | |||
|
384 | } | |||
|
385 | &:hover { | |||
|
386 | background-color: @blue; | |||
|
387 | } | |||
|
388 | ||||
|
389 | #dropdown { | |||
|
390 | margin: 0 0 0 117px; | |||
|
391 | padding: 0; | |||
|
392 | padding-top: 5px; | |||
|
393 | display: none; | |||
|
394 | width: 190px; | |||
|
395 | border-top: 2px solid @medium; | |||
|
396 | color: @highlight; | |||
|
397 | border: 2px solid darken(@medium, 25%); | |||
|
398 | border-left-color: darken(@medium, 15%); | |||
|
399 | border-right-color: darken(@medium, 15%); | |||
|
400 | border-top-width: 0; | |||
|
401 | background-color: darken(@medium, 10%); | |||
|
402 | ul { | |||
|
403 | padding: 0px; | |||
|
404 | } | |||
|
405 | li { | |||
|
406 | font-size: 14px; | |||
|
407 | display: block; | |||
|
408 | text-align: left; | |||
|
409 | padding: 0; | |||
|
410 | border: 0; | |||
|
411 | a { | |||
|
412 | display: block; | |||
|
413 | padding: 0px 15px; | |||
|
414 | text-decoration: none; | |||
|
415 | color: white; | |||
|
416 | &:hover { | |||
|
417 | background-color: darken(@medium, 15%); | |||
|
418 | text-decoration: none; | |||
|
419 | } | |||
|
420 | } | |||
|
421 | } | |||
|
422 | .border-radius(5px, bottom); | |||
|
423 | .box-shadow(0, 6px, 8px, 0.5); | |||
|
424 | } | |||
|
425 | } | |||
|
426 | ||||
|
427 | #main { | |||
|
428 | margin: 0 auto; | |||
|
429 | width: 100%; | |||
|
430 | background-color: @light-blue; | |||
|
431 | border-top: 8px solid darken(@light-blue, 5%); | |||
|
432 | ||||
|
433 | #intro { | |||
|
434 | background-color: lighten(@light-blue, 25%); | |||
|
435 | float: left; | |||
|
436 | margin-top: -8px; | |||
|
437 | margin-right: 5px; | |||
|
438 | ||||
|
439 | height: 380px; | |||
|
440 | position: relative; | |||
|
441 | z-index: 2; | |||
|
442 | font-family: 'Droid Serif', 'Georgia'; | |||
|
443 | width: 395px; | |||
|
444 | padding: 45px 20px 23px 30px; | |||
|
445 | border: 2px dashed darken(@light-blue, 10%); | |||
|
446 | .box-shadow(1px, 0px, 6px, 0.5); | |||
|
447 | border-bottom: 0; | |||
|
448 | border-top: 0; | |||
|
449 | #download { color: transparent; border: 0; float: left; display: inline-block; margin: 15px 0 15px -5px; } | |||
|
450 | #download img { display: inline-block} | |||
|
451 | #download-info { | |||
|
452 | code { | |||
|
453 | font-size: 13px; | |||
|
454 | } | |||
|
455 | color: @blue + #333; display: inline; float: left; margin: 36px 0 0 15px } | |||
|
456 | } | |||
|
457 | h2 { | |||
|
458 | span { | |||
|
459 | color: @medium; | |||
|
460 | } | |||
|
461 | color: @blue; | |||
|
462 | margin: 20px 0; | |||
|
463 | font-size: 24px; | |||
|
464 | line-height: 1.2em; | |||
|
465 | } | |||
|
466 | h3 { | |||
|
467 | color: @blue; | |||
|
468 | line-height: 1.4em; | |||
|
469 | margin: 30px 0 15px 0; | |||
|
470 | font-size: 1em; | |||
|
471 | text-shadow: 0px 0px 0px @lightest; | |||
|
472 | span { color: @medium } | |||
|
473 | } | |||
|
474 | #example { | |||
|
475 | p { | |||
|
476 | font-size: 18px; | |||
|
477 | color: @blue; | |||
|
478 | font-weight: bold; | |||
|
479 | text-shadow: 0px 1px 1px @lightest; | |||
|
480 | } | |||
|
481 | pre { | |||
|
482 | margin: 0; | |||
|
483 | text-shadow: 0 -1px 1px @darkest; | |||
|
484 | margin-top: 20px; | |||
|
485 | background-color: desaturate(@darkest, 8%); | |||
|
486 | border: 0; | |||
|
487 | width: 450px; | |||
|
488 | color: lighten(@lightest, 2%); | |||
|
489 | background-repeat: repeat; | |||
|
490 | padding: 15px; | |||
|
491 | border: 1px dashed @lightest; | |||
|
492 | line-height: 15px; | |||
|
493 | .box-shadow(0, 0px, 15px, 0.5); | |||
|
494 | .code; | |||
|
495 | .border-radius(2px); | |||
|
496 | code .attribute { color: hsl(40, 50%, 70%) } | |||
|
497 | code .variable { color: hsl(120, 10%, 50%) } | |||
|
498 | code .element { color: hsl(170, 20%, 50%) } | |||
|
499 | ||||
|
500 | code .string, .regexp { color: hsl(75, 50%, 65%) } | |||
|
501 | code .class { color: hsl(40, 40%, 60%); font-weight: normal } | |||
|
502 | code .id { color: hsl(50, 40%, 60%); font-weight: normal } | |||
|
503 | code .comment { color: rgba(255, 255, 255, 0.2) } | |||
|
504 | code .number, .color { color: hsl(10, 40%, 50%) } | |||
|
505 | code .class, code .mixin, .special { color: hsl(190, 20%, 50%) } | |||
|
506 | #time { color: #aaa } | |||
|
507 | } | |||
|
508 | float: right; | |||
|
509 | font-size: 12px; | |||
|
510 | margin: 0; | |||
|
511 | margin-top: 15px; | |||
|
512 | padding: 0; | |||
|
513 | width: 500px; | |||
|
514 | } | |||
|
515 | } | |||
|
516 | ||||
|
517 | ||||
|
518 | .page { | |||
|
519 | .content { | |||
|
520 | width: 870px; | |||
|
521 | padding: 45px; | |||
|
522 | } | |||
|
523 | margin: 0 auto; | |||
|
524 | font-family: 'Georgia', serif; | |||
|
525 | font-size: 18px; | |||
|
526 | line-height: 26px; | |||
|
527 | padding: 0 60px; | |||
|
528 | code { | |||
|
529 | font-size: 16px; | |||
|
530 | } | |||
|
531 | pre { | |||
|
532 | border-width: 1px; | |||
|
533 | border-style: dashed; | |||
|
534 | padding: 15px; | |||
|
535 | margin: 15px 0; | |||
|
536 | } | |||
|
537 | h1 { | |||
|
538 | text-align: left; | |||
|
539 | font-size: 40px; | |||
|
540 | margin-top: 15px; | |||
|
541 | margin-bottom: 35px; | |||
|
542 | } | |||
|
543 | p + h1 { margin-top: 60px } | |||
|
544 | h2, h3 { | |||
|
545 | margin: 30px 0 15px 0; | |||
|
546 | } | |||
|
547 | p + h2, pre + h2, code + h2 { | |||
|
548 | border-top: 6px solid rgba(255, 255, 255, 0.1); | |||
|
549 | padding-top: 30px; | |||
|
550 | } | |||
|
551 | h3 { | |||
|
552 | margin: 15px 0; | |||
|
553 | } | |||
|
554 | } | |||
|
555 | ||||
|
556 | ||||
|
557 | #docs { | |||
|
558 | @bg: lighten(@light-blue, 5%); | |||
|
559 | border-top: 2px solid lighten(@bg, 5%); | |||
|
560 | color: @blue; | |||
|
561 | background-color: @light-blue; | |||
|
562 | .box-shadow(0, -2px, 5px, 0.2); | |||
|
563 | ||||
|
564 | h1 { | |||
|
565 | font-family: 'Droid Serif', 'Georgia', serif; | |||
|
566 | padding-top: 30px; | |||
|
567 | padding-left: 45px; | |||
|
568 | font-size: 44px; | |||
|
569 | text-align: left; | |||
|
570 | margin: 30px 0 !important; | |||
|
571 | text-shadow: 0px 1px 1px @lightest; | |||
|
572 | font-weight: bold; | |||
|
573 | } | |||
|
574 | .content { | |||
|
575 | clear: both; | |||
|
576 | border-color: transparent; | |||
|
577 | background-color: lighten(@light-blue, 25%); | |||
|
578 | .box-shadow(0, 5px, 5px, 0.4); | |||
|
579 | } | |||
|
580 | pre { | |||
|
581 | @background: lighten(@bg, 30%); | |||
|
582 | color: lighten(@blue, 10%); | |||
|
583 | background-color: @background; | |||
|
584 | border-color: lighten(@light-blue, 25%); | |||
|
585 | border-width: 2px; | |||
|
586 | code .attribute { color: hsl(40, 50%, 30%) } | |||
|
587 | code .variable { color: hsl(120, 10%, 30%) } | |||
|
588 | code .element { color: hsl(170, 20%, 30%) } | |||
|
589 | ||||
|
590 | code .string, .regexp { color: hsl(75, 50%, 35%) } | |||
|
591 | code .class { color: hsl(40, 40%, 30%); font-weight: normal } | |||
|
592 | code .id { color: hsl(50, 40%, 30%); font-weight: normal } | |||
|
593 | code .comment { color: rgba(0, 0, 0, 0.4) } | |||
|
594 | code .number, .color { color: hsl(10, 40%, 30%) } | |||
|
595 | code .class, code .mixin, .special { color: hsl(190, 20%, 30%) } | |||
|
596 | } | |||
|
597 | pre code { font-size: 15px } | |||
|
598 | p + h2, pre + h2, code + h2 { border-top-color: rgba(0, 0, 0, 0.1) } | |||
|
599 | } | |||
|
600 | ||||
|
601 | td { | |||
|
602 | padding-right: 30px; | |||
|
603 | } | |||
|
604 | #synopsis { | |||
|
605 | .box-shadow(0, 5px, 5px, 0.2); | |||
|
606 | } | |||
|
607 | #synopsis, #about { | |||
|
608 | h2 { | |||
|
609 | font-size: 30px; | |||
|
610 | padding: 10px 0; | |||
|
611 | } | |||
|
612 | h1 + h2 { | |||
|
613 | margin-top: 15px; | |||
|
614 | } | |||
|
615 | h3 { font-size: 22px } | |||
|
616 | ||||
|
617 | .code-example { | |||
|
618 | border-spacing: 0; | |||
|
619 | border-width: 1px; | |||
|
620 | border-style: dashed; | |||
|
621 | padding: 0; | |||
|
622 | pre { border: 0; margin: 0 } | |||
|
623 | td { | |||
|
624 | border: 0; | |||
|
625 | margin: 0; | |||
|
626 | background-color: desaturate(darken(@darkest, 5%), 20%); | |||
|
627 | vertical-align: top; | |||
|
628 | padding: 0; | |||
|
629 | } | |||
|
630 | tr { padding: 0 } | |||
|
631 | } | |||
|
632 | .css-output { | |||
|
633 | td { | |||
|
634 | border-left: 0; | |||
|
635 | } | |||
|
636 | } | |||
|
637 | .less-example { | |||
|
638 | //border-right: 1px dotted rgba(255, 255, 255, 0.5) !important; | |||
|
639 | } | |||
|
640 | .css-output, .less-example { | |||
|
641 | width: 390px; | |||
|
642 | } | |||
|
643 | pre { | |||
|
644 | padding: 20px; | |||
|
645 | line-height: 20px; | |||
|
646 | font-size: 14px; | |||
|
647 | } | |||
|
648 | } | |||
|
649 | #about, #synopsis, #guide { | |||
|
650 | a { | |||
|
651 | text-decoration: none; | |||
|
652 | color: @light-yellow; | |||
|
653 | border-bottom: 1px dashed rgba(255, 255, 255, 0.2); | |||
|
654 | &:hover { | |||
|
655 | text-decoration: none; | |||
|
656 | border-bottom: 1px dashed @light-yellow; | |||
|
657 | } | |||
|
658 | } | |||
|
659 | @bg: desaturate(darken(@darkest, 5%), 20%); | |||
|
660 | text-shadow: 0 -1px 1px lighten(@bg, 5%); | |||
|
661 | color: @highlight; | |||
|
662 | background-color: @bg; | |||
|
663 | .content { | |||
|
664 | background-color: desaturate(@darkest, 20%); | |||
|
665 | clear: both; | |||
|
666 | .box-shadow(0, 5px, 5px, 0.4); | |||
|
667 | } | |||
|
668 | h1, h2, h3 { | |||
|
669 | color: @dark-yellow; | |||
|
670 | } | |||
|
671 | pre { | |||
|
672 | code .attribute { color: hsl(40, 50%, 70%) } | |||
|
673 | code .variable { color: hsl(120, 10%, 50%) } | |||
|
674 | code .element { color: hsl(170, 20%, 50%) } | |||
|
675 | ||||
|
676 | code .string, .regexp { color: hsl(75, 50%, 65%) } | |||
|
677 | code .class { color: hsl(40, 40%, 60%); font-weight: normal } | |||
|
678 | code .id { color: hsl(50, 40%, 60%); font-weight: normal } | |||
|
679 | code .comment { color: rgba(255, 255, 255, 0.2) } | |||
|
680 | code .number, .color { color: hsl(10, 40%, 50%) } | |||
|
681 | code .class, code .mixin, .special { color: hsl(190, 20%, 50%) } | |||
|
682 | background-color: @bg; | |||
|
683 | border-color: darken(@light-yellow, 5%); | |||
|
684 | } | |||
|
685 | code { | |||
|
686 | color: darken(@dark-yellow, 5%); | |||
|
687 | .string, .regexp { color: desaturate(@light-blue, 15%) } | |||
|
688 | .keyword { color: hsl(40, 40%, 60%); font-weight: normal } | |||
|
689 | .comment { color: rgba(255, 255, 255, 0.2) } | |||
|
690 | .number { color: lighten(@blue, 10%) } | |||
|
691 | .class, .special { color: hsl(190, 20%, 50%) } | |||
|
692 | } | |||
|
693 | } | |||
|
694 | #guide { | |||
|
695 | background-color: @darkest; | |||
|
696 | .content { | |||
|
697 | background-color: transparent; | |||
|
698 | } | |||
|
699 | ||||
|
700 | } | |||
|
701 | ||||
|
702 | #about { | |||
|
703 | background-color: @darkest !important; | |||
|
704 | .content { | |||
|
705 | background-color: desaturate(lighten(@darkest, 3%), 5%); | |||
|
706 | } | |||
|
707 | } | |||
|
708 | #synopsis { | |||
|
709 | background-color: desaturate(lighten(@darkest, 3%), 5%) !important; | |||
|
710 | .content { | |||
|
711 | background-color: desaturate(lighten(@darkest, 3%), 5%); | |||
|
712 | } | |||
|
713 | pre {} | |||
|
714 | } | |||
|
715 | #synopsis, #guide { | |||
|
716 | .content { | |||
|
717 | .box-shadow(0, 0px, 0px, 0.0); | |||
|
718 | } | |||
|
719 | } | |||
|
720 | #about footer { | |||
|
721 | margin-top: 30px; | |||
|
722 | padding-top: 30px; | |||
|
723 | border-top: 6px solid rgba(0, 0, 0, 0.1); | |||
|
724 | text-align: center; | |||
|
725 | font-size: 16px; | |||
|
726 | color: rgba(255, 255, 255, 0.35); | |||
|
727 | #copy { font-size: 12px } | |||
|
728 | text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.02); | |||
|
729 | } | |||
|
730 | </textarea></form> | |||
|
731 | <script> | |||
|
732 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
733 | theme: "lesser-dark", | |||
|
734 | lineNumbers : true, | |||
|
735 | matchBrackets : true | |||
|
736 | }); | |||
|
737 | </script> | |||
|
738 | ||||
|
739 | <p><strong>MIME types defined:</strong> <code>text/x-less</code>, <code>text/css</code> (if not previously defined).</p> | |||
|
740 | </body> | |||
|
741 | </html> |
@@ -0,0 +1,258 b'' | |||||
|
1 | /* | |||
|
2 | LESS mode - http://www.lesscss.org/ | |||
|
3 | Ported to CodeMirror by Peter Kroon <plakroon@gmail.com> | |||
|
4 | Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues GitHub: @peterkroon | |||
|
5 | */ | |||
|
6 | ||||
|
7 | CodeMirror.defineMode("less", function(config) { | |||
|
8 | var indentUnit = config.indentUnit, type; | |||
|
9 | function ret(style, tp) {type = tp; return style;} | |||
|
10 | ||||
|
11 | var selectors = /(^\:root$|^\:nth\-child$|^\:nth\-last\-child$|^\:nth\-of\-type$|^\:nth\-last\-of\-type$|^\:first\-child$|^\:last\-child$|^\:first\-of\-type$|^\:last\-of\-type$|^\:only\-child$|^\:only\-of\-type$|^\:empty$|^\:link|^\:visited$|^\:active$|^\:hover$|^\:focus$|^\:target$|^\:lang$|^\:enabled^\:disabled$|^\:checked$|^\:first\-line$|^\:first\-letter$|^\:before$|^\:after$|^\:not$|^\:required$|^\:invalid$)/; | |||
|
12 | ||||
|
13 | function tokenBase(stream, state) { | |||
|
14 | var ch = stream.next(); | |||
|
15 | ||||
|
16 | if (ch == "@") {stream.eatWhile(/[\w\-]/); return ret("meta", stream.current());} | |||
|
17 | else if (ch == "/" && stream.eat("*")) { | |||
|
18 | state.tokenize = tokenCComment; | |||
|
19 | return tokenCComment(stream, state); | |||
|
20 | } | |||
|
21 | else if (ch == "<" && stream.eat("!")) { | |||
|
22 | state.tokenize = tokenSGMLComment; | |||
|
23 | return tokenSGMLComment(stream, state); | |||
|
24 | } | |||
|
25 | else if (ch == "=") ret(null, "compare"); | |||
|
26 | else if (ch == "|" && stream.eat("=")) return ret(null, "compare"); | |||
|
27 | else if (ch == "\"" || ch == "'") { | |||
|
28 | state.tokenize = tokenString(ch); | |||
|
29 | return state.tokenize(stream, state); | |||
|
30 | } | |||
|
31 | else if (ch == "/") { // e.g.: .png will not be parsed as a class | |||
|
32 | if(stream.eat("/")){ | |||
|
33 | state.tokenize = tokenSComment; | |||
|
34 | return tokenSComment(stream, state); | |||
|
35 | }else{ | |||
|
36 | if(type == "string" || type == "(")return ret("string", "string"); | |||
|
37 | if(state.stack[state.stack.length-1] != undefined)return ret(null, ch); | |||
|
38 | stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/); | |||
|
39 | if( /\/|\)|#/.test(stream.peek() || (stream.eatSpace() && stream.peek() == ")")) || stream.eol() )return ret("string", "string"); // let url(/images/logo.png) without quotes return as string | |||
|
40 | } | |||
|
41 | } | |||
|
42 | else if (ch == "!") { | |||
|
43 | stream.match(/^\s*\w*/); | |||
|
44 | return ret("keyword", "important"); | |||
|
45 | } | |||
|
46 | else if (/\d/.test(ch)) { | |||
|
47 | stream.eatWhile(/[\w.%]/); | |||
|
48 | return ret("number", "unit"); | |||
|
49 | } | |||
|
50 | else if (/[,+<>*\/]/.test(ch)) { | |||
|
51 | if(stream.peek() == "=" || type == "a")return ret("string", "string"); | |||
|
52 | return ret(null, "select-op"); | |||
|
53 | } | |||
|
54 | else if (/[;{}:\[\]()~\|]/.test(ch)) { | |||
|
55 | if(ch == ":"){ | |||
|
56 | stream.eatWhile(/[a-z\\\-]/); | |||
|
57 | if( selectors.test(stream.current()) ){ | |||
|
58 | return ret("tag", "tag"); | |||
|
59 | }else if(stream.peek() == ":"){//::-webkit-search-decoration | |||
|
60 | stream.next(); | |||
|
61 | stream.eatWhile(/[a-z\\\-]/); | |||
|
62 | if(stream.current().match(/\:\:\-(o|ms|moz|webkit)\-/))return ret("string", "string"); | |||
|
63 | if( selectors.test(stream.current().substring(1)) )return ret("tag", "tag"); | |||
|
64 | return ret(null, ch); | |||
|
65 | }else{ | |||
|
66 | return ret(null, ch); | |||
|
67 | } | |||
|
68 | }else if(ch == "~"){ | |||
|
69 | if(type == "r")return ret("string", "string"); | |||
|
70 | }else{ | |||
|
71 | return ret(null, ch); | |||
|
72 | } | |||
|
73 | } | |||
|
74 | else if (ch == ".") { | |||
|
75 | if(type == "(" || type == "string")return ret("string", "string"); // allow url(../image.png) | |||
|
76 | stream.eatWhile(/[\a-zA-Z0-9\-_]/); | |||
|
77 | if(stream.peek() == " ")stream.eatSpace(); | |||
|
78 | if(stream.peek() == ")")return ret("number", "unit");//rgba(0,0,0,.25); | |||
|
79 | return ret("tag", "tag"); | |||
|
80 | } | |||
|
81 | else if (ch == "#") { | |||
|
82 | //we don't eat white-space, we want the hex color and or id only | |||
|
83 | stream.eatWhile(/[A-Za-z0-9]/); | |||
|
84 | //check if there is a proper hex color length e.g. #eee || #eeeEEE | |||
|
85 | if(stream.current().length == 4 || stream.current().length == 7){ | |||
|
86 | if(stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false) != null){//is there a valid hex color value present in the current stream | |||
|
87 | //when not a valid hex value, parse as id | |||
|
88 | if(stream.current().substring(1) != stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false))return ret("atom", "tag"); | |||
|
89 | //eat white-space | |||
|
90 | stream.eatSpace(); | |||
|
91 | //when hex value declaration doesn't end with [;,] but is does with a slash/cc comment treat it as an id, just like the other hex values that don't end with[;,] | |||
|
92 | if( /[\/<>.(){!$%^&*_\-\\?=+\|#'~`]/.test(stream.peek()) )return ret("atom", "tag"); | |||
|
93 | //#time { color: #aaa } | |||
|
94 | else if(stream.peek() == "}" )return ret("number", "unit"); | |||
|
95 | //we have a valid hex color value, parse as id whenever an element/class is defined after the hex(id) value e.g. #eee aaa || #eee .aaa | |||
|
96 | else if( /[a-zA-Z\\]/.test(stream.peek()) )return ret("atom", "tag"); | |||
|
97 | //when a hex value is on the end of a line, parse as id | |||
|
98 | else if(stream.eol())return ret("atom", "tag"); | |||
|
99 | //default | |||
|
100 | else return ret("number", "unit"); | |||
|
101 | }else{//when not a valid hexvalue in the current stream e.g. #footer | |||
|
102 | stream.eatWhile(/[\w\\\-]/); | |||
|
103 | return ret("atom", "tag"); | |||
|
104 | } | |||
|
105 | }else{//when not a valid hexvalue length | |||
|
106 | stream.eatWhile(/[\w\\\-]/); | |||
|
107 | return ret("atom", "tag"); | |||
|
108 | } | |||
|
109 | } | |||
|
110 | else if (ch == "&") { | |||
|
111 | stream.eatWhile(/[\w\-]/); | |||
|
112 | return ret(null, ch); | |||
|
113 | } | |||
|
114 | else { | |||
|
115 | stream.eatWhile(/[\w\\\-_%.{]/); | |||
|
116 | if(type == "string"){ | |||
|
117 | return ret("string", "string"); | |||
|
118 | }else if(stream.current().match(/(^http$|^https$)/) != null){ | |||
|
119 | stream.eatWhile(/[\w\\\-_%.{:\/]/); | |||
|
120 | return ret("string", "string"); | |||
|
121 | }else if(stream.peek() == "<" || stream.peek() == ">"){ | |||
|
122 | return ret("tag", "tag"); | |||
|
123 | }else if( /\(/.test(stream.peek()) ){ | |||
|
124 | return ret(null, ch); | |||
|
125 | }else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png) | |||
|
126 | return ret("string", "string"); | |||
|
127 | }else if( stream.current().match(/\-\d|\-.\d/) ){ // match e.g.: -5px -0.4 etc... only colorize the minus sign | |||
|
128 | //commment out these 2 comment if you want the minus sign to be parsed as null -500px | |||
|
129 | //stream.backUp(stream.current().length-1); | |||
|
130 | //return ret(null, ch); //console.log( stream.current() ); | |||
|
131 | return ret("number", "unit"); | |||
|
132 | }else if( /\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == "/")) && stream.current().indexOf(".") !== -1){ | |||
|
133 | if(stream.current().substring(stream.current().length-1,stream.current().length) == "{"){ | |||
|
134 | stream.backUp(1); | |||
|
135 | return ret("tag", "tag"); | |||
|
136 | }//end if | |||
|
137 | stream.eatSpace(); | |||
|
138 | if( /[{<>.a-zA-Z\/]/.test(stream.peek()) || stream.eol() )return ret("tag", "tag"); // e.g. button.icon-plus | |||
|
139 | return ret("string", "string"); // let url(/images/logo.png) without quotes return as string | |||
|
140 | }else if( stream.eol() || stream.peek() == "[" || stream.peek() == "#" || type == "tag" ){ | |||
|
141 | if(stream.current().substring(stream.current().length-1,stream.current().length) == "{")stream.backUp(1); | |||
|
142 | return ret("tag", "tag"); | |||
|
143 | }else if(type == "compare" || type == "a" || type == "("){ | |||
|
144 | return ret("string", "string"); | |||
|
145 | }else if(type == "|" || stream.current() == "-" || type == "["){ | |||
|
146 | return ret(null, ch); | |||
|
147 | }else if(stream.peek() == ":") { | |||
|
148 | stream.next(); | |||
|
149 | var t_v = stream.peek() == ":" ? true : false; | |||
|
150 | if(!t_v){ | |||
|
151 | var old_pos = stream.pos; | |||
|
152 | var sc = stream.current().length; | |||
|
153 | stream.eatWhile(/[a-z\\\-]/); | |||
|
154 | var new_pos = stream.pos; | |||
|
155 | if(stream.current().substring(sc-1).match(selectors) != null){ | |||
|
156 | stream.backUp(new_pos-(old_pos-1)); | |||
|
157 | return ret("tag", "tag"); | |||
|
158 | } else stream.backUp(new_pos-(old_pos-1)); | |||
|
159 | }else{ | |||
|
160 | stream.backUp(1); | |||
|
161 | } | |||
|
162 | if(t_v)return ret("tag", "tag"); else return ret("variable", "variable"); | |||
|
163 | }else{ | |||
|
164 | return ret("variable", "variable"); | |||
|
165 | } | |||
|
166 | } | |||
|
167 | } | |||
|
168 | ||||
|
169 | function tokenSComment(stream, state) { // SComment = Slash comment | |||
|
170 | stream.skipToEnd(); | |||
|
171 | state.tokenize = tokenBase; | |||
|
172 | return ret("comment", "comment"); | |||
|
173 | } | |||
|
174 | ||||
|
175 | function tokenCComment(stream, state) { | |||
|
176 | var maybeEnd = false, ch; | |||
|
177 | while ((ch = stream.next()) != null) { | |||
|
178 | if (maybeEnd && ch == "/") { | |||
|
179 | state.tokenize = tokenBase; | |||
|
180 | break; | |||
|
181 | } | |||
|
182 | maybeEnd = (ch == "*"); | |||
|
183 | } | |||
|
184 | return ret("comment", "comment"); | |||
|
185 | } | |||
|
186 | ||||
|
187 | function tokenSGMLComment(stream, state) { | |||
|
188 | var dashes = 0, ch; | |||
|
189 | while ((ch = stream.next()) != null) { | |||
|
190 | if (dashes >= 2 && ch == ">") { | |||
|
191 | state.tokenize = tokenBase; | |||
|
192 | break; | |||
|
193 | } | |||
|
194 | dashes = (ch == "-") ? dashes + 1 : 0; | |||
|
195 | } | |||
|
196 | return ret("comment", "comment"); | |||
|
197 | } | |||
|
198 | ||||
|
199 | function tokenString(quote) { | |||
|
200 | return function(stream, state) { | |||
|
201 | var escaped = false, ch; | |||
|
202 | while ((ch = stream.next()) != null) { | |||
|
203 | if (ch == quote && !escaped) | |||
|
204 | break; | |||
|
205 | escaped = !escaped && ch == "\\"; | |||
|
206 | } | |||
|
207 | if (!escaped) state.tokenize = tokenBase; | |||
|
208 | return ret("string", "string"); | |||
|
209 | }; | |||
|
210 | } | |||
|
211 | ||||
|
212 | return { | |||
|
213 | startState: function(base) { | |||
|
214 | return {tokenize: tokenBase, | |||
|
215 | baseIndent: base || 0, | |||
|
216 | stack: []}; | |||
|
217 | }, | |||
|
218 | ||||
|
219 | token: function(stream, state) { | |||
|
220 | if (stream.eatSpace()) return null; | |||
|
221 | var style = state.tokenize(stream, state); | |||
|
222 | ||||
|
223 | var context = state.stack[state.stack.length-1]; | |||
|
224 | if (type == "hash" && context == "rule") style = "atom"; | |||
|
225 | else if (style == "variable") { | |||
|
226 | if (context == "rule") style = null; //"tag" | |||
|
227 | else if (!context || context == "@media{") { | |||
|
228 | style = stream.current() == "when" ? "variable" : | |||
|
229 | /[\s,|\s\)|\s]/.test(stream.peek()) ? "tag" : type; | |||
|
230 | } | |||
|
231 | } | |||
|
232 | ||||
|
233 | if (context == "rule" && /^[\{\};]$/.test(type)) | |||
|
234 | state.stack.pop(); | |||
|
235 | if (type == "{") { | |||
|
236 | if (context == "@media") state.stack[state.stack.length-1] = "@media{"; | |||
|
237 | else state.stack.push("{"); | |||
|
238 | } | |||
|
239 | else if (type == "}") state.stack.pop(); | |||
|
240 | else if (type == "@media") state.stack.push("@media"); | |||
|
241 | else if (context == "{" && type != "comment") state.stack.push("rule"); | |||
|
242 | return style; | |||
|
243 | }, | |||
|
244 | ||||
|
245 | indent: function(state, textAfter) { | |||
|
246 | var n = state.stack.length; | |||
|
247 | if (/^\}/.test(textAfter)) | |||
|
248 | n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1; | |||
|
249 | return state.baseIndent + n * indentUnit; | |||
|
250 | }, | |||
|
251 | ||||
|
252 | electricChars: "}" | |||
|
253 | }; | |||
|
254 | }); | |||
|
255 | ||||
|
256 | CodeMirror.defineMIME("text/x-less", "less"); | |||
|
257 | if (!CodeMirror.mimeModes.hasOwnProperty("text/css")) | |||
|
258 | CodeMirror.defineMIME("text/css", "less"); |
@@ -0,0 +1,23 b'' | |||||
|
1 | The MIT License | |||
|
2 | ||||
|
3 | Copyright (c) 2013 Kenneth Bentley | |||
|
4 | Modified from the CoffeeScript CodeMirror mode, Copyright (c) 2011 Jeff Pickhardt | |||
|
5 | Modified from the Python CodeMirror mode, Copyright (c) 2010 Timothy Farrell | |||
|
6 | ||||
|
7 | Permission is hereby granted, free of charge, to any person obtaining a copy | |||
|
8 | of this software and associated documentation files (the "Software"), to deal | |||
|
9 | in the Software without restriction, including without limitation the rights | |||
|
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
|
11 | copies of the Software, and to permit persons to whom the Software is | |||
|
12 | furnished to do so, subject to the following conditions: | |||
|
13 | ||||
|
14 | The above copyright notice and this permission notice shall be included in | |||
|
15 | all copies or substantial portions of the Software. | |||
|
16 | ||||
|
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
|
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
|
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
|
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
|
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
|
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
|
23 | THE SOFTWARE. |
@@ -0,0 +1,446 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <title>CodeMirror: LiveScript mode</title> | |||
|
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
6 | <script src="../../lib/codemirror.js"></script> | |||
|
7 | <script src="livescript.js"></script> | |||
|
8 | <style>.CodeMirror {font-size: 80%;border-top: 1px solid silver; border-bottom: 1px solid silver;}</style> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <link rel="stylesheet" href="../../theme/solarized.css"> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: LiveScript mode</h1> | |||
|
14 | <form><textarea id="code" name="code"> | |||
|
15 | # LiveScript mode for CodeMirror | |||
|
16 | # The following script, prelude.ls, is used to | |||
|
17 | # demonstrate LiveScript mode for CodeMirror. | |||
|
18 | # https://github.com/gkz/prelude-ls | |||
|
19 | ||||
|
20 | export objToFunc = objToFunc = (obj) -> | |||
|
21 | (key) -> obj[key] | |||
|
22 | ||||
|
23 | export each = (f, xs) --> | |||
|
24 | if typeof! xs is \Object | |||
|
25 | for , x of xs then f x | |||
|
26 | else | |||
|
27 | for x in xs then f x | |||
|
28 | xs | |||
|
29 | ||||
|
30 | export map = (f, xs) --> | |||
|
31 | f = objToFunc f if typeof! f isnt \Function | |||
|
32 | type = typeof! xs | |||
|
33 | if type is \Object | |||
|
34 | {[key, f x] for key, x of xs} | |||
|
35 | else | |||
|
36 | result = [f x for x in xs] | |||
|
37 | if type is \String then result * '' else result | |||
|
38 | ||||
|
39 | export filter = (f, xs) --> | |||
|
40 | f = objToFunc f if typeof! f isnt \Function | |||
|
41 | type = typeof! xs | |||
|
42 | if type is \Object | |||
|
43 | {[key, x] for key, x of xs when f x} | |||
|
44 | else | |||
|
45 | result = [x for x in xs when f x] | |||
|
46 | if type is \String then result * '' else result | |||
|
47 | ||||
|
48 | export reject = (f, xs) --> | |||
|
49 | f = objToFunc f if typeof! f isnt \Function | |||
|
50 | type = typeof! xs | |||
|
51 | if type is \Object | |||
|
52 | {[key, x] for key, x of xs when not f x} | |||
|
53 | else | |||
|
54 | result = [x for x in xs when not f x] | |||
|
55 | if type is \String then result * '' else result | |||
|
56 | ||||
|
57 | export partition = (f, xs) --> | |||
|
58 | f = objToFunc f if typeof! f isnt \Function | |||
|
59 | type = typeof! xs | |||
|
60 | if type is \Object | |||
|
61 | passed = {} | |||
|
62 | failed = {} | |||
|
63 | for key, x of xs | |||
|
64 | (if f x then passed else failed)[key] = x | |||
|
65 | else | |||
|
66 | passed = [] | |||
|
67 | failed = [] | |||
|
68 | for x in xs | |||
|
69 | (if f x then passed else failed)push x | |||
|
70 | if type is \String | |||
|
71 | passed *= '' | |||
|
72 | failed *= '' | |||
|
73 | [passed, failed] | |||
|
74 | ||||
|
75 | export find = (f, xs) --> | |||
|
76 | f = objToFunc f if typeof! f isnt \Function | |||
|
77 | if typeof! xs is \Object | |||
|
78 | for , x of xs when f x then return x | |||
|
79 | else | |||
|
80 | for x in xs when f x then return x | |||
|
81 | void | |||
|
82 | ||||
|
83 | export head = export first = (xs) -> | |||
|
84 | return void if not xs.length | |||
|
85 | xs.0 | |||
|
86 | ||||
|
87 | export tail = (xs) -> | |||
|
88 | return void if not xs.length | |||
|
89 | xs.slice 1 | |||
|
90 | ||||
|
91 | export last = (xs) -> | |||
|
92 | return void if not xs.length | |||
|
93 | xs[*-1] | |||
|
94 | ||||
|
95 | export initial = (xs) -> | |||
|
96 | return void if not xs.length | |||
|
97 | xs.slice 0 xs.length - 1 | |||
|
98 | ||||
|
99 | export empty = (xs) -> | |||
|
100 | if typeof! xs is \Object | |||
|
101 | for x of xs then return false | |||
|
102 | return yes | |||
|
103 | not xs.length | |||
|
104 | ||||
|
105 | export values = (obj) -> | |||
|
106 | [x for , x of obj] | |||
|
107 | ||||
|
108 | export keys = (obj) -> | |||
|
109 | [x for x of obj] | |||
|
110 | ||||
|
111 | export len = (xs) -> | |||
|
112 | xs = values xs if typeof! xs is \Object | |||
|
113 | xs.length | |||
|
114 | ||||
|
115 | export cons = (x, xs) --> | |||
|
116 | if typeof! xs is \String then x + xs else [x] ++ xs | |||
|
117 | ||||
|
118 | export append = (xs, ys) --> | |||
|
119 | if typeof! ys is \String then xs + ys else xs ++ ys | |||
|
120 | ||||
|
121 | export join = (sep, xs) --> | |||
|
122 | xs = values xs if typeof! xs is \Object | |||
|
123 | xs.join sep | |||
|
124 | ||||
|
125 | export reverse = (xs) -> | |||
|
126 | if typeof! xs is \String | |||
|
127 | then (xs / '')reverse! * '' | |||
|
128 | else xs.slice!reverse! | |||
|
129 | ||||
|
130 | export fold = export foldl = (f, memo, xs) --> | |||
|
131 | if typeof! xs is \Object | |||
|
132 | for , x of xs then memo = f memo, x | |||
|
133 | else | |||
|
134 | for x in xs then memo = f memo, x | |||
|
135 | memo | |||
|
136 | ||||
|
137 | export fold1 = export foldl1 = (f, xs) --> fold f, xs.0, xs.slice 1 | |||
|
138 | ||||
|
139 | export foldr = (f, memo, xs) --> fold f, memo, xs.slice!reverse! | |||
|
140 | ||||
|
141 | export foldr1 = (f, xs) --> | |||
|
142 | xs.=slice!reverse! | |||
|
143 | fold f, xs.0, xs.slice 1 | |||
|
144 | ||||
|
145 | export unfoldr = export unfold = (f, b) --> | |||
|
146 | if (f b)? | |||
|
147 | [that.0] ++ unfoldr f, that.1 | |||
|
148 | else | |||
|
149 | [] | |||
|
150 | ||||
|
151 | export andList = (xs) -> | |||
|
152 | for x in xs when not x | |||
|
153 | return false | |||
|
154 | true | |||
|
155 | ||||
|
156 | export orList = (xs) -> | |||
|
157 | for x in xs when x | |||
|
158 | return true | |||
|
159 | false | |||
|
160 | ||||
|
161 | export any = (f, xs) --> | |||
|
162 | f = objToFunc f if typeof! f isnt \Function | |||
|
163 | for x in xs when f x | |||
|
164 | return yes | |||
|
165 | no | |||
|
166 | ||||
|
167 | export all = (f, xs) --> | |||
|
168 | f = objToFunc f if typeof! f isnt \Function | |||
|
169 | for x in xs when not f x | |||
|
170 | return no | |||
|
171 | yes | |||
|
172 | ||||
|
173 | export unique = (xs) -> | |||
|
174 | result = [] | |||
|
175 | if typeof! xs is \Object | |||
|
176 | for , x of xs when x not in result then result.push x | |||
|
177 | else | |||
|
178 | for x in xs when x not in result then result.push x | |||
|
179 | if typeof! xs is \String then result * '' else result | |||
|
180 | ||||
|
181 | export sort = (xs) -> | |||
|
182 | xs.concat!sort (x, y) -> | |||
|
183 | | x > y => 1 | |||
|
184 | | x < y => -1 | |||
|
185 | | _ => 0 | |||
|
186 | ||||
|
187 | export sortBy = (f, xs) --> | |||
|
188 | return [] unless xs.length | |||
|
189 | xs.concat!sort f | |||
|
190 | ||||
|
191 | export compare = (f, x, y) --> | |||
|
192 | | (f x) > (f y) => 1 | |||
|
193 | | (f x) < (f y) => -1 | |||
|
194 | | otherwise => 0 | |||
|
195 | ||||
|
196 | export sum = (xs) -> | |||
|
197 | result = 0 | |||
|
198 | if typeof! xs is \Object | |||
|
199 | for , x of xs then result += x | |||
|
200 | else | |||
|
201 | for x in xs then result += x | |||
|
202 | result | |||
|
203 | ||||
|
204 | export product = (xs) -> | |||
|
205 | result = 1 | |||
|
206 | if typeof! xs is \Object | |||
|
207 | for , x of xs then result *= x | |||
|
208 | else | |||
|
209 | for x in xs then result *= x | |||
|
210 | result | |||
|
211 | ||||
|
212 | export mean = export average = (xs) -> (sum xs) / len xs | |||
|
213 | ||||
|
214 | export concat = (xss) -> fold append, [], xss | |||
|
215 | ||||
|
216 | export concatMap = (f, xs) --> fold ((memo, x) -> append memo, f x), [], xs | |||
|
217 | ||||
|
218 | export listToObj = (xs) -> | |||
|
219 | {[x.0, x.1] for x in xs} | |||
|
220 | ||||
|
221 | export maximum = (xs) -> fold1 (>?), xs | |||
|
222 | ||||
|
223 | export minimum = (xs) -> fold1 (<?), xs | |||
|
224 | ||||
|
225 | export scan = export scanl = (f, memo, xs) --> | |||
|
226 | last = memo | |||
|
227 | if typeof! xs is \Object | |||
|
228 | then [memo] ++ [last = f last, x for , x of xs] | |||
|
229 | else [memo] ++ [last = f last, x for x in xs] | |||
|
230 | ||||
|
231 | export scan1 = export scanl1 = (f, xs) --> scan f, xs.0, xs.slice 1 | |||
|
232 | ||||
|
233 | export scanr = (f, memo, xs) --> | |||
|
234 | xs.=slice!reverse! | |||
|
235 | scan f, memo, xs .reverse! | |||
|
236 | ||||
|
237 | export scanr1 = (f, xs) --> | |||
|
238 | xs.=slice!reverse! | |||
|
239 | scan f, xs.0, xs.slice 1 .reverse! | |||
|
240 | ||||
|
241 | export replicate = (n, x) --> | |||
|
242 | result = [] | |||
|
243 | i = 0 | |||
|
244 | while i < n, ++i then result.push x | |||
|
245 | result | |||
|
246 | ||||
|
247 | export take = (n, xs) --> | |||
|
248 | | n <= 0 | |||
|
249 | if typeof! xs is \String then '' else [] | |||
|
250 | | not xs.length => xs | |||
|
251 | | otherwise => xs.slice 0, n | |||
|
252 | ||||
|
253 | export drop = (n, xs) --> | |||
|
254 | | n <= 0 => xs | |||
|
255 | | not xs.length => xs | |||
|
256 | | otherwise => xs.slice n | |||
|
257 | ||||
|
258 | export splitAt = (n, xs) --> [(take n, xs), (drop n, xs)] | |||
|
259 | ||||
|
260 | export takeWhile = (p, xs) --> | |||
|
261 | return xs if not xs.length | |||
|
262 | p = objToFunc p if typeof! p isnt \Function | |||
|
263 | result = [] | |||
|
264 | for x in xs | |||
|
265 | break if not p x | |||
|
266 | result.push x | |||
|
267 | if typeof! xs is \String then result * '' else result | |||
|
268 | ||||
|
269 | export dropWhile = (p, xs) --> | |||
|
270 | return xs if not xs.length | |||
|
271 | p = objToFunc p if typeof! p isnt \Function | |||
|
272 | i = 0 | |||
|
273 | for x in xs | |||
|
274 | break if not p x | |||
|
275 | ++i | |||
|
276 | drop i, xs | |||
|
277 | ||||
|
278 | export span = (p, xs) --> [(takeWhile p, xs), (dropWhile p, xs)] | |||
|
279 | ||||
|
280 | export breakIt = (p, xs) --> span (not) << p, xs | |||
|
281 | ||||
|
282 | export zip = (xs, ys) --> | |||
|
283 | result = [] | |||
|
284 | for zs, i in [xs, ys] | |||
|
285 | for z, j in zs | |||
|
286 | result.push [] if i is 0 | |||
|
287 | result[j]?push z | |||
|
288 | result | |||
|
289 | ||||
|
290 | export zipWith = (f,xs, ys) --> | |||
|
291 | f = objToFunc f if typeof! f isnt \Function | |||
|
292 | if not xs.length or not ys.length | |||
|
293 | [] | |||
|
294 | else | |||
|
295 | [f.apply this, zs for zs in zip.call this, xs, ys] | |||
|
296 | ||||
|
297 | export zipAll = (...xss) -> | |||
|
298 | result = [] | |||
|
299 | for xs, i in xss | |||
|
300 | for x, j in xs | |||
|
301 | result.push [] if i is 0 | |||
|
302 | result[j]?push x | |||
|
303 | result | |||
|
304 | ||||
|
305 | export zipAllWith = (f, ...xss) -> | |||
|
306 | f = objToFunc f if typeof! f isnt \Function | |||
|
307 | if not xss.0.length or not xss.1.length | |||
|
308 | [] | |||
|
309 | else | |||
|
310 | [f.apply this, xs for xs in zipAll.apply this, xss] | |||
|
311 | ||||
|
312 | export compose = (...funcs) -> | |||
|
313 | -> | |||
|
314 | args = arguments | |||
|
315 | for f in funcs | |||
|
316 | args = [f.apply this, args] | |||
|
317 | args.0 | |||
|
318 | ||||
|
319 | export curry = (f) -> | |||
|
320 | curry$ f # using util method curry$ from livescript | |||
|
321 | ||||
|
322 | export id = (x) -> x | |||
|
323 | ||||
|
324 | export flip = (f, x, y) --> f y, x | |||
|
325 | ||||
|
326 | export fix = (f) -> | |||
|
327 | ( (g, x) -> -> f(g g) ...arguments ) do | |||
|
328 | (g, x) -> -> f(g g) ...arguments | |||
|
329 | ||||
|
330 | export lines = (str) -> | |||
|
331 | return [] if not str.length | |||
|
332 | str / \\n | |||
|
333 | ||||
|
334 | export unlines = (strs) -> strs * \\n | |||
|
335 | ||||
|
336 | export words = (str) -> | |||
|
337 | return [] if not str.length | |||
|
338 | str / /[ ]+/ | |||
|
339 | ||||
|
340 | export unwords = (strs) -> strs * ' ' | |||
|
341 | ||||
|
342 | export max = (>?) | |||
|
343 | ||||
|
344 | export min = (<?) | |||
|
345 | ||||
|
346 | export negate = (x) -> -x | |||
|
347 | ||||
|
348 | export abs = Math.abs | |||
|
349 | ||||
|
350 | export signum = (x) -> | |||
|
351 | | x < 0 => -1 | |||
|
352 | | x > 0 => 1 | |||
|
353 | | otherwise => 0 | |||
|
354 | ||||
|
355 | export quot = (x, y) --> ~~(x / y) | |||
|
356 | ||||
|
357 | export rem = (%) | |||
|
358 | ||||
|
359 | export div = (x, y) --> Math.floor x / y | |||
|
360 | ||||
|
361 | export mod = (%%) | |||
|
362 | ||||
|
363 | export recip = (1 /) | |||
|
364 | ||||
|
365 | export pi = Math.PI | |||
|
366 | ||||
|
367 | export tau = pi * 2 | |||
|
368 | ||||
|
369 | export exp = Math.exp | |||
|
370 | ||||
|
371 | export sqrt = Math.sqrt | |||
|
372 | ||||
|
373 | # changed from log as log is a | |||
|
374 | # common function for logging things | |||
|
375 | export ln = Math.log | |||
|
376 | ||||
|
377 | export pow = (^) | |||
|
378 | ||||
|
379 | export sin = Math.sin | |||
|
380 | ||||
|
381 | export tan = Math.tan | |||
|
382 | ||||
|
383 | export cos = Math.cos | |||
|
384 | ||||
|
385 | export asin = Math.asin | |||
|
386 | ||||
|
387 | export acos = Math.acos | |||
|
388 | ||||
|
389 | export atan = Math.atan | |||
|
390 | ||||
|
391 | export atan2 = (x, y) --> Math.atan2 x, y | |||
|
392 | ||||
|
393 | # sinh | |||
|
394 | # tanh | |||
|
395 | # cosh | |||
|
396 | # asinh | |||
|
397 | # atanh | |||
|
398 | # acosh | |||
|
399 | ||||
|
400 | export truncate = (x) -> ~~x | |||
|
401 | ||||
|
402 | export round = Math.round | |||
|
403 | ||||
|
404 | export ceiling = Math.ceil | |||
|
405 | ||||
|
406 | export floor = Math.floor | |||
|
407 | ||||
|
408 | export isItNaN = (x) -> x isnt x | |||
|
409 | ||||
|
410 | export even = (x) -> x % 2 == 0 | |||
|
411 | ||||
|
412 | export odd = (x) -> x % 2 != 0 | |||
|
413 | ||||
|
414 | export gcd = (x, y) --> | |||
|
415 | x = Math.abs x | |||
|
416 | y = Math.abs y | |||
|
417 | until y is 0 | |||
|
418 | z = x % y | |||
|
419 | x = y | |||
|
420 | y = z | |||
|
421 | x | |||
|
422 | ||||
|
423 | export lcm = (x, y) --> | |||
|
424 | Math.abs Math.floor (x / (gcd x, y) * y) | |||
|
425 | ||||
|
426 | # meta | |||
|
427 | export installPrelude = !(target) -> | |||
|
428 | unless target.prelude?isInstalled | |||
|
429 | target <<< out$ # using out$ generated by livescript | |||
|
430 | target <<< target.prelude.isInstalled = true | |||
|
431 | ||||
|
432 | export prelude = out$ | |||
|
433 | </textarea></form> | |||
|
434 | <script> | |||
|
435 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
436 | theme: "solarized light", | |||
|
437 | lineNumbers: true | |||
|
438 | }); | |||
|
439 | </script> | |||
|
440 | ||||
|
441 | <p><strong>MIME types defined:</strong> <code>text/x-livescript</code>.</p> | |||
|
442 | ||||
|
443 | <p>The LiveScript mode was written by Kenneth Bentley (<a href="LICENSE">license</a>).</p> | |||
|
444 | ||||
|
445 | </body> | |||
|
446 | </html> |
@@ -0,0 +1,267 b'' | |||||
|
1 | /** | |||
|
2 | * Link to the project's GitHub page: | |||
|
3 | * https://github.com/duralog/CodeMirror | |||
|
4 | */ | |||
|
5 | (function() { | |||
|
6 | CodeMirror.defineMode('livescript', function(){ | |||
|
7 | var tokenBase, external; | |||
|
8 | tokenBase = function(stream, state){ | |||
|
9 | var next_rule, nr, i$, len$, r, m; | |||
|
10 | if (next_rule = state.next || 'start') { | |||
|
11 | state.next = state.next; | |||
|
12 | if (Array.isArray(nr = Rules[next_rule])) { | |||
|
13 | for (i$ = 0, len$ = nr.length; i$ < len$; ++i$) { | |||
|
14 | r = nr[i$]; | |||
|
15 | if (r.regex && (m = stream.match(r.regex))) { | |||
|
16 | state.next = r.next; | |||
|
17 | return r.token; | |||
|
18 | } | |||
|
19 | } | |||
|
20 | stream.next(); | |||
|
21 | return 'error'; | |||
|
22 | } | |||
|
23 | if (stream.match(r = Rules[next_rule])) { | |||
|
24 | if (r.regex && stream.match(r.regex)) { | |||
|
25 | state.next = r.next; | |||
|
26 | return r.token; | |||
|
27 | } else { | |||
|
28 | stream.next(); | |||
|
29 | return 'error'; | |||
|
30 | } | |||
|
31 | } | |||
|
32 | } | |||
|
33 | stream.next(); | |||
|
34 | return 'error'; | |||
|
35 | }; | |||
|
36 | external = { | |||
|
37 | startState: function(){ | |||
|
38 | return { | |||
|
39 | next: 'start', | |||
|
40 | lastToken: null | |||
|
41 | }; | |||
|
42 | }, | |||
|
43 | token: function(stream, state){ | |||
|
44 | var style; | |||
|
45 | style = tokenBase(stream, state); | |||
|
46 | state.lastToken = { | |||
|
47 | style: style, | |||
|
48 | indent: stream.indentation(), | |||
|
49 | content: stream.current() | |||
|
50 | }; | |||
|
51 | return style.replace(/\./g, ' '); | |||
|
52 | }, | |||
|
53 | indent: function(state){ | |||
|
54 | var indentation; | |||
|
55 | indentation = state.lastToken.indent; | |||
|
56 | if (state.lastToken.content.match(indenter)) { | |||
|
57 | indentation += 2; | |||
|
58 | } | |||
|
59 | return indentation; | |||
|
60 | } | |||
|
61 | }; | |||
|
62 | return external; | |||
|
63 | }); | |||
|
64 | ||||
|
65 | var identifier = '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*'; | |||
|
66 | var indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$'); | |||
|
67 | var keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))'; | |||
|
68 | var stringfill = { | |||
|
69 | token: 'string', | |||
|
70 | regex: '.+' | |||
|
71 | }; | |||
|
72 | var Rules = { | |||
|
73 | start: [ | |||
|
74 | { | |||
|
75 | token: 'comment.doc', | |||
|
76 | regex: '/\\*', | |||
|
77 | next: 'comment' | |||
|
78 | }, { | |||
|
79 | token: 'comment', | |||
|
80 | regex: '#.*' | |||
|
81 | }, { | |||
|
82 | token: 'keyword', | |||
|
83 | regex: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend | |||
|
84 | }, { | |||
|
85 | token: 'constant.language', | |||
|
86 | regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend | |||
|
87 | }, { | |||
|
88 | token: 'invalid.illegal', | |||
|
89 | regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend | |||
|
90 | }, { | |||
|
91 | token: 'language.support.class', | |||
|
92 | regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend | |||
|
93 | }, { | |||
|
94 | token: 'language.support.function', | |||
|
95 | regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend | |||
|
96 | }, { | |||
|
97 | token: 'variable.language', | |||
|
98 | regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend | |||
|
99 | }, { | |||
|
100 | token: 'identifier', | |||
|
101 | regex: identifier + '\\s*:(?![:=])' | |||
|
102 | }, { | |||
|
103 | token: 'variable', | |||
|
104 | regex: identifier | |||
|
105 | }, { | |||
|
106 | token: 'keyword.operator', | |||
|
107 | regex: '(?:\\.{3}|\\s+\\?)' | |||
|
108 | }, { | |||
|
109 | token: 'keyword.variable', | |||
|
110 | regex: '(?:@+|::|\\.\\.)', | |||
|
111 | next: 'key' | |||
|
112 | }, { | |||
|
113 | token: 'keyword.operator', | |||
|
114 | regex: '\\.\\s*', | |||
|
115 | next: 'key' | |||
|
116 | }, { | |||
|
117 | token: 'string', | |||
|
118 | regex: '\\\\\\S[^\\s,;)}\\]]*' | |||
|
119 | }, { | |||
|
120 | token: 'string.doc', | |||
|
121 | regex: '\'\'\'', | |||
|
122 | next: 'qdoc' | |||
|
123 | }, { | |||
|
124 | token: 'string.doc', | |||
|
125 | regex: '"""', | |||
|
126 | next: 'qqdoc' | |||
|
127 | }, { | |||
|
128 | token: 'string', | |||
|
129 | regex: '\'', | |||
|
130 | next: 'qstring' | |||
|
131 | }, { | |||
|
132 | token: 'string', | |||
|
133 | regex: '"', | |||
|
134 | next: 'qqstring' | |||
|
135 | }, { | |||
|
136 | token: 'string', | |||
|
137 | regex: '`', | |||
|
138 | next: 'js' | |||
|
139 | }, { | |||
|
140 | token: 'string', | |||
|
141 | regex: '<\\[', | |||
|
142 | next: 'words' | |||
|
143 | }, { | |||
|
144 | token: 'string.regex', | |||
|
145 | regex: '//', | |||
|
146 | next: 'heregex' | |||
|
147 | }, { | |||
|
148 | token: 'string.regex', | |||
|
149 | regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}', | |||
|
150 | next: 'key' | |||
|
151 | }, { | |||
|
152 | token: 'constant.numeric', | |||
|
153 | regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)' | |||
|
154 | }, { | |||
|
155 | token: 'lparen', | |||
|
156 | regex: '[({[]' | |||
|
157 | }, { | |||
|
158 | token: 'rparen', | |||
|
159 | regex: '[)}\\]]', | |||
|
160 | next: 'key' | |||
|
161 | }, { | |||
|
162 | token: 'keyword.operator', | |||
|
163 | regex: '\\S+' | |||
|
164 | }, { | |||
|
165 | token: 'text', | |||
|
166 | regex: '\\s+' | |||
|
167 | } | |||
|
168 | ], | |||
|
169 | heregex: [ | |||
|
170 | { | |||
|
171 | token: 'string.regex', | |||
|
172 | regex: '.*?//[gimy$?]{0,4}', | |||
|
173 | next: 'start' | |||
|
174 | }, { | |||
|
175 | token: 'string.regex', | |||
|
176 | regex: '\\s*#{' | |||
|
177 | }, { | |||
|
178 | token: 'comment.regex', | |||
|
179 | regex: '\\s+(?:#.*)?' | |||
|
180 | }, { | |||
|
181 | token: 'string.regex', | |||
|
182 | regex: '\\S+' | |||
|
183 | } | |||
|
184 | ], | |||
|
185 | key: [ | |||
|
186 | { | |||
|
187 | token: 'keyword.operator', | |||
|
188 | regex: '[.?@!]+' | |||
|
189 | }, { | |||
|
190 | token: 'identifier', | |||
|
191 | regex: identifier, | |||
|
192 | next: 'start' | |||
|
193 | }, { | |||
|
194 | token: 'text', | |||
|
195 | regex: '.', | |||
|
196 | next: 'start' | |||
|
197 | } | |||
|
198 | ], | |||
|
199 | comment: [ | |||
|
200 | { | |||
|
201 | token: 'comment.doc', | |||
|
202 | regex: '.*?\\*/', | |||
|
203 | next: 'start' | |||
|
204 | }, { | |||
|
205 | token: 'comment.doc', | |||
|
206 | regex: '.+' | |||
|
207 | } | |||
|
208 | ], | |||
|
209 | qdoc: [ | |||
|
210 | { | |||
|
211 | token: 'string', | |||
|
212 | regex: ".*?'''", | |||
|
213 | next: 'key' | |||
|
214 | }, stringfill | |||
|
215 | ], | |||
|
216 | qqdoc: [ | |||
|
217 | { | |||
|
218 | token: 'string', | |||
|
219 | regex: '.*?"""', | |||
|
220 | next: 'key' | |||
|
221 | }, stringfill | |||
|
222 | ], | |||
|
223 | qstring: [ | |||
|
224 | { | |||
|
225 | token: 'string', | |||
|
226 | regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'', | |||
|
227 | next: 'key' | |||
|
228 | }, stringfill | |||
|
229 | ], | |||
|
230 | qqstring: [ | |||
|
231 | { | |||
|
232 | token: 'string', | |||
|
233 | regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"', | |||
|
234 | next: 'key' | |||
|
235 | }, stringfill | |||
|
236 | ], | |||
|
237 | js: [ | |||
|
238 | { | |||
|
239 | token: 'string', | |||
|
240 | regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`', | |||
|
241 | next: 'key' | |||
|
242 | }, stringfill | |||
|
243 | ], | |||
|
244 | words: [ | |||
|
245 | { | |||
|
246 | token: 'string', | |||
|
247 | regex: '.*?\\]>', | |||
|
248 | next: 'key' | |||
|
249 | }, stringfill | |||
|
250 | ] | |||
|
251 | }; | |||
|
252 | for (var idx in Rules) { | |||
|
253 | var r = Rules[idx]; | |||
|
254 | if (Array.isArray(r)) { | |||
|
255 | for (var i = 0, len = r.length; i < len; ++i) { | |||
|
256 | var rr = r[i]; | |||
|
257 | if (rr.regex) { | |||
|
258 | Rules[idx][i].regex = new RegExp('^' + rr.regex); | |||
|
259 | } | |||
|
260 | } | |||
|
261 | } else if (r.regex) { | |||
|
262 | Rules[idx].regex = new RegExp('^' + r.regex); | |||
|
263 | } | |||
|
264 | } | |||
|
265 | })(); | |||
|
266 | ||||
|
267 | CodeMirror.defineMIME('text/x-livescript', 'livescript'); |
@@ -0,0 +1,266 b'' | |||||
|
1 | /** | |||
|
2 | * Link to the project's GitHub page: | |||
|
3 | * https://github.com/duralog/CodeMirror | |||
|
4 | */ | |||
|
5 | CodeMirror.defineMode 'livescript', (conf) -> | |||
|
6 | tokenBase = (stream, state) -> | |||
|
7 | #indent = | |||
|
8 | if next_rule = state.next or \start | |||
|
9 | state.next = state.next | |||
|
10 | if Array.isArray nr = Rules[next_rule] | |||
|
11 | for r in nr | |||
|
12 | if r.regex and m = stream.match r.regex | |||
|
13 | state.next = r.next | |||
|
14 | return r.token | |||
|
15 | stream.next! | |||
|
16 | return \error | |||
|
17 | if stream.match r = Rules[next_rule] | |||
|
18 | if r.regex and stream.match r.regex | |||
|
19 | state.next = r.next | |||
|
20 | return r.token | |||
|
21 | else | |||
|
22 | stream.next! | |||
|
23 | return \error | |||
|
24 | stream.next! | |||
|
25 | return 'error' | |||
|
26 | external = { | |||
|
27 | startState: (basecolumn) -> | |||
|
28 | { | |||
|
29 | next: \start | |||
|
30 | lastToken: null | |||
|
31 | } | |||
|
32 | token: (stream, state) -> | |||
|
33 | style = tokenBase stream, state #tokenLexer stream, state | |||
|
34 | state.lastToken = { | |||
|
35 | style: style | |||
|
36 | indent: stream.indentation! | |||
|
37 | content: stream.current! | |||
|
38 | } | |||
|
39 | style.replace /\./g, ' ' | |||
|
40 | indent: (state, textAfter) -> | |||
|
41 | # XXX this won't work with backcalls | |||
|
42 | indentation = state.lastToken.indent | |||
|
43 | if state.lastToken.content.match indenter then indentation += 2 | |||
|
44 | return indentation | |||
|
45 | } | |||
|
46 | external | |||
|
47 | ||||
|
48 | ### Highlight Rules | |||
|
49 | # taken from mode-ls.ls | |||
|
50 | ||||
|
51 | indenter = // (? | |||
|
52 | : [({[=:] | |||
|
53 | | [-~]> | |||
|
54 | | \b (?: e(?:lse|xport) | d(?:o|efault) | t(?:ry|hen) | finally | | |||
|
55 | import (?:\s* all)? | const | var | | |||
|
56 | let | new | catch (?:\s* #identifier)? ) | |||
|
57 | ) \s* $ // | |||
|
58 | ||||
|
59 | identifier = /(?![\d\s])[$\w\xAA-\uFFDC](?:(?!\s)[$\w\xAA-\uFFDC]|-[A-Za-z])*/$ | |||
|
60 | keywordend = /(?![$\w]|-[A-Za-z]|\s*:(?![:=]))/$ | |||
|
61 | stringfill = token: \string, regex: '.+' | |||
|
62 | ||||
|
63 | Rules = | |||
|
64 | start: | |||
|
65 | * token: \comment.doc | |||
|
66 | regex: '/\\*' | |||
|
67 | next : \comment | |||
|
68 | ||||
|
69 | * token: \comment | |||
|
70 | regex: '#.*' | |||
|
71 | ||||
|
72 | * token: \keyword | |||
|
73 | regex: //(? | |||
|
74 | :t(?:h(?:is|row|en)|ry|ypeof!?) | |||
|
75 | |c(?:on(?:tinue|st)|a(?:se|tch)|lass) | |||
|
76 | |i(?:n(?:stanceof)?|mp(?:ort(?:\s+all)?|lements)|[fs]) | |||
|
77 | |d(?:e(?:fault|lete|bugger)|o) | |||
|
78 | |f(?:or(?:\s+own)?|inally|unction) | |||
|
79 | |s(?:uper|witch) | |||
|
80 | |e(?:lse|x(?:tends|port)|val) | |||
|
81 | |a(?:nd|rguments) | |||
|
82 | |n(?:ew|ot) | |||
|
83 | |un(?:less|til) | |||
|
84 | |w(?:hile|ith) | |||
|
85 | |o[fr]|return|break|let|var|loop | |||
|
86 | )//$ + keywordend | |||
|
87 | ||||
|
88 | * token: \constant.language | |||
|
89 | regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend | |||
|
90 | ||||
|
91 | * token: \invalid.illegal | |||
|
92 | regex: '(? | |||
|
93 | :p(?:ackage|r(?:ivate|otected)|ublic) | |||
|
94 | |i(?:mplements|nterface) | |||
|
95 | |enum|static|yield | |||
|
96 | )' + keywordend | |||
|
97 | ||||
|
98 | * token: \language.support.class | |||
|
99 | regex: '(? | |||
|
100 | :R(?:e(?:gExp|ferenceError)|angeError) | |||
|
101 | |S(?:tring|yntaxError) | |||
|
102 | |E(?:rror|valError) | |||
|
103 | |Array|Boolean|Date|Function|Number|Object|TypeError|URIError | |||
|
104 | )' + keywordend | |||
|
105 | ||||
|
106 | * token: \language.support.function | |||
|
107 | regex: '(? | |||
|
108 | :is(?:NaN|Finite) | |||
|
109 | |parse(?:Int|Float) | |||
|
110 | |Math|JSON | |||
|
111 | |(?:en|de)codeURI(?:Component)? | |||
|
112 | )' + keywordend | |||
|
113 | ||||
|
114 | * token: \variable.language | |||
|
115 | regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend | |||
|
116 | ||||
|
117 | * token: \identifier | |||
|
118 | regex: identifier + /\s*:(?![:=])/$ | |||
|
119 | ||||
|
120 | * token: \variable | |||
|
121 | regex: identifier | |||
|
122 | ||||
|
123 | * token: \keyword.operator | |||
|
124 | regex: /(?:\.{3}|\s+\?)/$ | |||
|
125 | ||||
|
126 | * token: \keyword.variable | |||
|
127 | regex: /(?:@+|::|\.\.)/$ | |||
|
128 | next : \key | |||
|
129 | ||||
|
130 | * token: \keyword.operator | |||
|
131 | regex: /\.\s*/$ | |||
|
132 | next : \key | |||
|
133 | ||||
|
134 | * token: \string | |||
|
135 | regex: /\\\S[^\s,;)}\]]*/$ | |||
|
136 | ||||
|
137 | * token: \string.doc | |||
|
138 | regex: \''' | |||
|
139 | next : \qdoc | |||
|
140 | ||||
|
141 | * token: \string.doc | |||
|
142 | regex: \""" | |||
|
143 | next : \qqdoc | |||
|
144 | ||||
|
145 | * token: \string | |||
|
146 | regex: \' | |||
|
147 | next : \qstring | |||
|
148 | ||||
|
149 | * token: \string | |||
|
150 | regex: \" | |||
|
151 | next : \qqstring | |||
|
152 | ||||
|
153 | * token: \string | |||
|
154 | regex: \` | |||
|
155 | next : \js | |||
|
156 | ||||
|
157 | * token: \string | |||
|
158 | regex: '<\\[' | |||
|
159 | next : \words | |||
|
160 | ||||
|
161 | * token: \string.regex | |||
|
162 | regex: \// | |||
|
163 | next : \heregex | |||
|
164 | ||||
|
165 | * token: \string.regex | |||
|
166 | regex: // | |||
|
167 | /(?: [^ [ / \n \\ ]* | |||
|
168 | (?: (?: \\. | |||
|
169 | | \[ [^\]\n\\]* (?:\\.[^\]\n\\]*)* \] | |||
|
170 | ) [^ [ / \n \\ ]* | |||
|
171 | )* | |||
|
172 | )/ [gimy$]{0,4} | |||
|
173 | //$ | |||
|
174 | next : \key | |||
|
175 | ||||
|
176 | * token: \constant.numeric | |||
|
177 | regex: '(?:0x[\\da-fA-F][\\da-fA-F_]* | |||
|
178 | |(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]* | |||
|
179 | |(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*) | |||
|
180 | (?:e[+-]?\\d[\\d_]*)?[\\w$]*)' | |||
|
181 | ||||
|
182 | * token: \lparen | |||
|
183 | regex: '[({[]' | |||
|
184 | ||||
|
185 | * token: \rparen | |||
|
186 | regex: '[)}\\]]' | |||
|
187 | next : \key | |||
|
188 | ||||
|
189 | * token: \keyword.operator | |||
|
190 | regex: \\\S+ | |||
|
191 | ||||
|
192 | * token: \text | |||
|
193 | regex: \\\s+ | |||
|
194 | ||||
|
195 | heregex: | |||
|
196 | * token: \string.regex | |||
|
197 | regex: '.*?//[gimy$?]{0,4}' | |||
|
198 | next : \start | |||
|
199 | * token: \string.regex | |||
|
200 | regex: '\\s*#{' | |||
|
201 | * token: \comment.regex | |||
|
202 | regex: '\\s+(?:#.*)?' | |||
|
203 | * token: \string.regex | |||
|
204 | regex: '\\S+' | |||
|
205 | ||||
|
206 | key: | |||
|
207 | * token: \keyword.operator | |||
|
208 | regex: '[.?@!]+' | |||
|
209 | * token: \identifier | |||
|
210 | regex: identifier | |||
|
211 | next : \start | |||
|
212 | * token: \text | |||
|
213 | regex: '.' | |||
|
214 | next : \start | |||
|
215 | ||||
|
216 | comment: | |||
|
217 | * token: \comment.doc | |||
|
218 | regex: '.*?\\*/' | |||
|
219 | next : \start | |||
|
220 | * token: \comment.doc | |||
|
221 | regex: '.+' | |||
|
222 | ||||
|
223 | qdoc: | |||
|
224 | token: \string | |||
|
225 | regex: ".*?'''" | |||
|
226 | next : \key | |||
|
227 | stringfill | |||
|
228 | ||||
|
229 | qqdoc: | |||
|
230 | token: \string | |||
|
231 | regex: '.*?"""' | |||
|
232 | next : \key | |||
|
233 | stringfill | |||
|
234 | ||||
|
235 | qstring: | |||
|
236 | token: \string | |||
|
237 | regex: /[^\\']*(?:\\.[^\\']*)*'/$ | |||
|
238 | next : \key | |||
|
239 | stringfill | |||
|
240 | ||||
|
241 | qqstring: | |||
|
242 | token: \string | |||
|
243 | regex: /[^\\"]*(?:\\.[^\\"]*)*"/$ | |||
|
244 | next : \key | |||
|
245 | stringfill | |||
|
246 | ||||
|
247 | js: | |||
|
248 | token: \string | |||
|
249 | regex: /[^\\`]*(?:\\.[^\\`]*)*`/$ | |||
|
250 | next : \key | |||
|
251 | stringfill | |||
|
252 | ||||
|
253 | words: | |||
|
254 | token: \string | |||
|
255 | regex: '.*?\\]>' | |||
|
256 | next : \key | |||
|
257 | stringfill | |||
|
258 | ||||
|
259 | # for optimization, precompile the regexps | |||
|
260 | for idx, r of Rules | |||
|
261 | if Array.isArray r | |||
|
262 | for rr, i in r | |||
|
263 | if rr.regex then Rules[idx][i].regex = new RegExp '^'+rr.regex | |||
|
264 | else if r.regex then Rules[idx].regex = new RegExp '^'+r.regex | |||
|
265 | ||||
|
266 | CodeMirror.defineMIME 'text/x-livescript', 'livescript' |
@@ -0,0 +1,74 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Lua mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../addon/edit/matchbrackets.js"></script> | |||
|
8 | <script src="../../lib/codemirror.js"></script> | |||
|
9 | <script src="lua.js"></script> | |||
|
10 | <link rel="stylesheet" href="../../theme/neat.css"> | |||
|
11 | <style>.CodeMirror {border: 1px solid black;}</style> | |||
|
12 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
13 | </head> | |||
|
14 | <body> | |||
|
15 | <h1>CodeMirror: Lua mode</h1> | |||
|
16 | <form><textarea id="code" name="code"> | |||
|
17 | --[[ | |||
|
18 | example useless code to show lua syntax highlighting | |||
|
19 | this is multiline comment | |||
|
20 | ]] | |||
|
21 | ||||
|
22 | function blahblahblah(x) | |||
|
23 | ||||
|
24 | local table = { | |||
|
25 | "asd" = 123, | |||
|
26 | "x" = 0.34, | |||
|
27 | } | |||
|
28 | if x ~= 3 then | |||
|
29 | print( x ) | |||
|
30 | elseif x == "string" | |||
|
31 | my_custom_function( 0x34 ) | |||
|
32 | else | |||
|
33 | unknown_function( "some string" ) | |||
|
34 | end | |||
|
35 | ||||
|
36 | --single line comment | |||
|
37 | ||||
|
38 | end | |||
|
39 | ||||
|
40 | function blablabla3() | |||
|
41 | ||||
|
42 | for k,v in ipairs( table ) do | |||
|
43 | --abcde.. | |||
|
44 | y=[=[ | |||
|
45 | x=[[ | |||
|
46 | x is a multi line string | |||
|
47 | ]] | |||
|
48 | but its definition is iside a highest level string! | |||
|
49 | ]=] | |||
|
50 | print(" \"\" ") | |||
|
51 | ||||
|
52 | s = math.sin( x ) | |||
|
53 | end | |||
|
54 | ||||
|
55 | end | |||
|
56 | </textarea></form> | |||
|
57 | <script> | |||
|
58 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
59 | tabMode: "indent", | |||
|
60 | matchBrackets: true, | |||
|
61 | theme: "neat" | |||
|
62 | }); | |||
|
63 | </script> | |||
|
64 | ||||
|
65 | <p>Loosely based on Franciszek | |||
|
66 | Wawrzak's <a href="http://codemirror.net/1/contrib/lua">CodeMirror | |||
|
67 | 1 mode</a>. One configuration parameter is | |||
|
68 | supported, <code>specials</code>, to which you can provide an | |||
|
69 | array of strings to have those identifiers highlighted with | |||
|
70 | the <code>lua-special</code> style.</p> | |||
|
71 | <p><strong>MIME types defined:</strong> <code>text/x-lua</code>.</p> | |||
|
72 | ||||
|
73 | </body> | |||
|
74 | </html> |
@@ -0,0 +1,144 b'' | |||||
|
1 | // LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's | |||
|
2 | // CodeMirror 1 mode. | |||
|
3 | // highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting | |||
|
4 | ||||
|
5 | CodeMirror.defineMode("lua", function(config, parserConfig) { | |||
|
6 | var indentUnit = config.indentUnit; | |||
|
7 | ||||
|
8 | function prefixRE(words) { | |||
|
9 | return new RegExp("^(?:" + words.join("|") + ")", "i"); | |||
|
10 | } | |||
|
11 | function wordRE(words) { | |||
|
12 | return new RegExp("^(?:" + words.join("|") + ")$", "i"); | |||
|
13 | } | |||
|
14 | var specials = wordRE(parserConfig.specials || []); | |||
|
15 | ||||
|
16 | // long list of standard functions from lua manual | |||
|
17 | var builtins = wordRE([ | |||
|
18 | "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load", | |||
|
19 | "loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require", | |||
|
20 | "select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall", | |||
|
21 | ||||
|
22 | "coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield", | |||
|
23 | ||||
|
24 | "debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable", | |||
|
25 | "debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable", | |||
|
26 | "debug.setupvalue","debug.traceback", | |||
|
27 | ||||
|
28 | "close","flush","lines","read","seek","setvbuf","write", | |||
|
29 | ||||
|
30 | "io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin", | |||
|
31 | "io.stdout","io.tmpfile","io.type","io.write", | |||
|
32 | ||||
|
33 | "math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg", | |||
|
34 | "math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max", | |||
|
35 | "math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh", | |||
|
36 | "math.sqrt","math.tan","math.tanh", | |||
|
37 | ||||
|
38 | "os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale", | |||
|
39 | "os.time","os.tmpname", | |||
|
40 | ||||
|
41 | "package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload", | |||
|
42 | "package.seeall", | |||
|
43 | ||||
|
44 | "string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub", | |||
|
45 | "string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper", | |||
|
46 | ||||
|
47 | "table.concat","table.insert","table.maxn","table.remove","table.sort" | |||
|
48 | ]); | |||
|
49 | var keywords = wordRE(["and","break","elseif","false","nil","not","or","return", | |||
|
50 | "true","function", "end", "if", "then", "else", "do", | |||
|
51 | "while", "repeat", "until", "for", "in", "local" ]); | |||
|
52 | ||||
|
53 | var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]); | |||
|
54 | var dedentTokens = wordRE(["end", "until", "\\)", "}"]); | |||
|
55 | var dedentPartial = prefixRE(["end", "until", "\\)", "}", "else", "elseif"]); | |||
|
56 | ||||
|
57 | function readBracket(stream) { | |||
|
58 | var level = 0; | |||
|
59 | while (stream.eat("=")) ++level; | |||
|
60 | stream.eat("["); | |||
|
61 | return level; | |||
|
62 | } | |||
|
63 | ||||
|
64 | function normal(stream, state) { | |||
|
65 | var ch = stream.next(); | |||
|
66 | if (ch == "-" && stream.eat("-")) { | |||
|
67 | if (stream.eat("[") && stream.eat("[")) | |||
|
68 | return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state); | |||
|
69 | stream.skipToEnd(); | |||
|
70 | return "comment"; | |||
|
71 | } | |||
|
72 | if (ch == "\"" || ch == "'") | |||
|
73 | return (state.cur = string(ch))(stream, state); | |||
|
74 | if (ch == "[" && /[\[=]/.test(stream.peek())) | |||
|
75 | return (state.cur = bracketed(readBracket(stream), "string"))(stream, state); | |||
|
76 | if (/\d/.test(ch)) { | |||
|
77 | stream.eatWhile(/[\w.%]/); | |||
|
78 | return "number"; | |||
|
79 | } | |||
|
80 | if (/[\w_]/.test(ch)) { | |||
|
81 | stream.eatWhile(/[\w\\\-_.]/); | |||
|
82 | return "variable"; | |||
|
83 | } | |||
|
84 | return null; | |||
|
85 | } | |||
|
86 | ||||
|
87 | function bracketed(level, style) { | |||
|
88 | return function(stream, state) { | |||
|
89 | var curlev = null, ch; | |||
|
90 | while ((ch = stream.next()) != null) { | |||
|
91 | if (curlev == null) {if (ch == "]") curlev = 0;} | |||
|
92 | else if (ch == "=") ++curlev; | |||
|
93 | else if (ch == "]" && curlev == level) { state.cur = normal; break; } | |||
|
94 | else curlev = null; | |||
|
95 | } | |||
|
96 | return style; | |||
|
97 | }; | |||
|
98 | } | |||
|
99 | ||||
|
100 | function string(quote) { | |||
|
101 | return function(stream, state) { | |||
|
102 | var escaped = false, ch; | |||
|
103 | while ((ch = stream.next()) != null) { | |||
|
104 | if (ch == quote && !escaped) break; | |||
|
105 | escaped = !escaped && ch == "\\"; | |||
|
106 | } | |||
|
107 | if (!escaped) state.cur = normal; | |||
|
108 | return "string"; | |||
|
109 | }; | |||
|
110 | } | |||
|
111 | ||||
|
112 | return { | |||
|
113 | startState: function(basecol) { | |||
|
114 | return {basecol: basecol || 0, indentDepth: 0, cur: normal}; | |||
|
115 | }, | |||
|
116 | ||||
|
117 | token: function(stream, state) { | |||
|
118 | if (stream.eatSpace()) return null; | |||
|
119 | var style = state.cur(stream, state); | |||
|
120 | var word = stream.current(); | |||
|
121 | if (style == "variable") { | |||
|
122 | if (keywords.test(word)) style = "keyword"; | |||
|
123 | else if (builtins.test(word)) style = "builtin"; | |||
|
124 | else if (specials.test(word)) style = "variable-2"; | |||
|
125 | } | |||
|
126 | if ((style != "comment") && (style != "string")){ | |||
|
127 | if (indentTokens.test(word)) ++state.indentDepth; | |||
|
128 | else if (dedentTokens.test(word)) --state.indentDepth; | |||
|
129 | } | |||
|
130 | return style; | |||
|
131 | }, | |||
|
132 | ||||
|
133 | indent: function(state, textAfter) { | |||
|
134 | var closing = dedentPartial.test(textAfter); | |||
|
135 | return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0)); | |||
|
136 | }, | |||
|
137 | ||||
|
138 | lineComment: "--", | |||
|
139 | blockCommentStart: "--[[", | |||
|
140 | blockCommentEnd: "]]" | |||
|
141 | }; | |||
|
142 | }); | |||
|
143 | ||||
|
144 | CodeMirror.defineMIME("text/x-lua", "lua"); |
@@ -0,0 +1,344 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Markdown mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="../../addon/edit/continuelist.js"></script> | |||
|
9 | <script src="../xml/xml.js"></script> | |||
|
10 | <script src="markdown.js"></script> | |||
|
11 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
12 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
13 | </head> | |||
|
14 | <body> | |||
|
15 | <h1>CodeMirror: Markdown mode</h1> | |||
|
16 | ||||
|
17 | <!-- source: http://daringfireball.net/projects/markdown/basics.text --> | |||
|
18 | <form><textarea id="code" name="code"> | |||
|
19 | Markdown: Basics | |||
|
20 | ================ | |||
|
21 | ||||
|
22 | <ul id="ProjectSubmenu"> | |||
|
23 | <li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li> | |||
|
24 | <li><a class="selected" title="Markdown Basics">Basics</a></li> | |||
|
25 | <li><a href="/projects/markdown/syntax" title="Markdown Syntax Documentation">Syntax</a></li> | |||
|
26 | <li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li> | |||
|
27 | <li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li> | |||
|
28 | </ul> | |||
|
29 | ||||
|
30 | ||||
|
31 | Getting the Gist of Markdown's Formatting Syntax | |||
|
32 | ------------------------------------------------ | |||
|
33 | ||||
|
34 | This page offers a brief overview of what it's like to use Markdown. | |||
|
35 | The [syntax page] [s] provides complete, detailed documentation for | |||
|
36 | every feature, but Markdown should be very easy to pick up simply by | |||
|
37 | looking at a few examples of it in action. The examples on this page | |||
|
38 | are written in a before/after style, showing example syntax and the | |||
|
39 | HTML output produced by Markdown. | |||
|
40 | ||||
|
41 | It's also helpful to simply try Markdown out; the [Dingus] [d] is a | |||
|
42 | web application that allows you type your own Markdown-formatted text | |||
|
43 | and translate it to XHTML. | |||
|
44 | ||||
|
45 | **Note:** This document is itself written using Markdown; you | |||
|
46 | can [see the source for it by adding '.text' to the URL] [src]. | |||
|
47 | ||||
|
48 | [s]: /projects/markdown/syntax "Markdown Syntax" | |||
|
49 | [d]: /projects/markdown/dingus "Markdown Dingus" | |||
|
50 | [src]: /projects/markdown/basics.text | |||
|
51 | ||||
|
52 | ||||
|
53 | ## Paragraphs, Headers, Blockquotes ## | |||
|
54 | ||||
|
55 | A paragraph is simply one or more consecutive lines of text, separated | |||
|
56 | by one or more blank lines. (A blank line is any line that looks like | |||
|
57 | a blank line -- a line containing nothing but spaces or tabs is | |||
|
58 | considered blank.) Normal paragraphs should not be indented with | |||
|
59 | spaces or tabs. | |||
|
60 | ||||
|
61 | Markdown offers two styles of headers: *Setext* and *atx*. | |||
|
62 | Setext-style headers for `<h1>` and `<h2>` are created by | |||
|
63 | "underlining" with equal signs (`=`) and hyphens (`-`), respectively. | |||
|
64 | To create an atx-style header, you put 1-6 hash marks (`#`) at the | |||
|
65 | beginning of the line -- the number of hashes equals the resulting | |||
|
66 | HTML header level. | |||
|
67 | ||||
|
68 | Blockquotes are indicated using email-style '`>`' angle brackets. | |||
|
69 | ||||
|
70 | Markdown: | |||
|
71 | ||||
|
72 | A First Level Header | |||
|
73 | ==================== | |||
|
74 | ||||
|
75 | A Second Level Header | |||
|
76 | --------------------- | |||
|
77 | ||||
|
78 | Now is the time for all good men to come to | |||
|
79 | the aid of their country. This is just a | |||
|
80 | regular paragraph. | |||
|
81 | ||||
|
82 | The quick brown fox jumped over the lazy | |||
|
83 | dog's back. | |||
|
84 | ||||
|
85 | ### Header 3 | |||
|
86 | ||||
|
87 | > This is a blockquote. | |||
|
88 | > | |||
|
89 | > This is the second paragraph in the blockquote. | |||
|
90 | > | |||
|
91 | > ## This is an H2 in a blockquote | |||
|
92 | ||||
|
93 | ||||
|
94 | Output: | |||
|
95 | ||||
|
96 | <h1>A First Level Header</h1> | |||
|
97 | ||||
|
98 | <h2>A Second Level Header</h2> | |||
|
99 | ||||
|
100 | <p>Now is the time for all good men to come to | |||
|
101 | the aid of their country. This is just a | |||
|
102 | regular paragraph.</p> | |||
|
103 | ||||
|
104 | <p>The quick brown fox jumped over the lazy | |||
|
105 | dog's back.</p> | |||
|
106 | ||||
|
107 | <h3>Header 3</h3> | |||
|
108 | ||||
|
109 | <blockquote> | |||
|
110 | <p>This is a blockquote.</p> | |||
|
111 | ||||
|
112 | <p>This is the second paragraph in the blockquote.</p> | |||
|
113 | ||||
|
114 | <h2>This is an H2 in a blockquote</h2> | |||
|
115 | </blockquote> | |||
|
116 | ||||
|
117 | ||||
|
118 | ||||
|
119 | ### Phrase Emphasis ### | |||
|
120 | ||||
|
121 | Markdown uses asterisks and underscores to indicate spans of emphasis. | |||
|
122 | ||||
|
123 | Markdown: | |||
|
124 | ||||
|
125 | Some of these words *are emphasized*. | |||
|
126 | Some of these words _are emphasized also_. | |||
|
127 | ||||
|
128 | Use two asterisks for **strong emphasis**. | |||
|
129 | Or, if you prefer, __use two underscores instead__. | |||
|
130 | ||||
|
131 | Output: | |||
|
132 | ||||
|
133 | <p>Some of these words <em>are emphasized</em>. | |||
|
134 | Some of these words <em>are emphasized also</em>.</p> | |||
|
135 | ||||
|
136 | <p>Use two asterisks for <strong>strong emphasis</strong>. | |||
|
137 | Or, if you prefer, <strong>use two underscores instead</strong>.</p> | |||
|
138 | ||||
|
139 | ||||
|
140 | ||||
|
141 | ## Lists ## | |||
|
142 | ||||
|
143 | Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`, | |||
|
144 | `+`, and `-`) as list markers. These three markers are | |||
|
145 | interchangable; this: | |||
|
146 | ||||
|
147 | * Candy. | |||
|
148 | * Gum. | |||
|
149 | * Booze. | |||
|
150 | ||||
|
151 | this: | |||
|
152 | ||||
|
153 | + Candy. | |||
|
154 | + Gum. | |||
|
155 | + Booze. | |||
|
156 | ||||
|
157 | and this: | |||
|
158 | ||||
|
159 | - Candy. | |||
|
160 | - Gum. | |||
|
161 | - Booze. | |||
|
162 | ||||
|
163 | all produce the same output: | |||
|
164 | ||||
|
165 | <ul> | |||
|
166 | <li>Candy.</li> | |||
|
167 | <li>Gum.</li> | |||
|
168 | <li>Booze.</li> | |||
|
169 | </ul> | |||
|
170 | ||||
|
171 | Ordered (numbered) lists use regular numbers, followed by periods, as | |||
|
172 | list markers: | |||
|
173 | ||||
|
174 | 1. Red | |||
|
175 | 2. Green | |||
|
176 | 3. Blue | |||
|
177 | ||||
|
178 | Output: | |||
|
179 | ||||
|
180 | <ol> | |||
|
181 | <li>Red</li> | |||
|
182 | <li>Green</li> | |||
|
183 | <li>Blue</li> | |||
|
184 | </ol> | |||
|
185 | ||||
|
186 | If you put blank lines between items, you'll get `<p>` tags for the | |||
|
187 | list item text. You can create multi-paragraph list items by indenting | |||
|
188 | the paragraphs by 4 spaces or 1 tab: | |||
|
189 | ||||
|
190 | * A list item. | |||
|
191 | ||||
|
192 | With multiple paragraphs. | |||
|
193 | ||||
|
194 | * Another item in the list. | |||
|
195 | ||||
|
196 | Output: | |||
|
197 | ||||
|
198 | <ul> | |||
|
199 | <li><p>A list item.</p> | |||
|
200 | <p>With multiple paragraphs.</p></li> | |||
|
201 | <li><p>Another item in the list.</p></li> | |||
|
202 | </ul> | |||
|
203 | ||||
|
204 | ||||
|
205 | ||||
|
206 | ### Links ### | |||
|
207 | ||||
|
208 | Markdown supports two styles for creating links: *inline* and | |||
|
209 | *reference*. With both styles, you use square brackets to delimit the | |||
|
210 | text you want to turn into a link. | |||
|
211 | ||||
|
212 | Inline-style links use parentheses immediately after the link text. | |||
|
213 | For example: | |||
|
214 | ||||
|
215 | This is an [example link](http://example.com/). | |||
|
216 | ||||
|
217 | Output: | |||
|
218 | ||||
|
219 | <p>This is an <a href="http://example.com/"> | |||
|
220 | example link</a>.</p> | |||
|
221 | ||||
|
222 | Optionally, you may include a title attribute in the parentheses: | |||
|
223 | ||||
|
224 | This is an [example link](http://example.com/ "With a Title"). | |||
|
225 | ||||
|
226 | Output: | |||
|
227 | ||||
|
228 | <p>This is an <a href="http://example.com/" title="With a Title"> | |||
|
229 | example link</a>.</p> | |||
|
230 | ||||
|
231 | Reference-style links allow you to refer to your links by names, which | |||
|
232 | you define elsewhere in your document: | |||
|
233 | ||||
|
234 | I get 10 times more traffic from [Google][1] than from | |||
|
235 | [Yahoo][2] or [MSN][3]. | |||
|
236 | ||||
|
237 | [1]: http://google.com/ "Google" | |||
|
238 | [2]: http://search.yahoo.com/ "Yahoo Search" | |||
|
239 | [3]: http://search.msn.com/ "MSN Search" | |||
|
240 | ||||
|
241 | Output: | |||
|
242 | ||||
|
243 | <p>I get 10 times more traffic from <a href="http://google.com/" | |||
|
244 | title="Google">Google</a> than from <a href="http://search.yahoo.com/" | |||
|
245 | title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" | |||
|
246 | title="MSN Search">MSN</a>.</p> | |||
|
247 | ||||
|
248 | The title attribute is optional. Link names may contain letters, | |||
|
249 | numbers and spaces, but are *not* case sensitive: | |||
|
250 | ||||
|
251 | I start my morning with a cup of coffee and | |||
|
252 | [The New York Times][NY Times]. | |||
|
253 | ||||
|
254 | [ny times]: http://www.nytimes.com/ | |||
|
255 | ||||
|
256 | Output: | |||
|
257 | ||||
|
258 | <p>I start my morning with a cup of coffee and | |||
|
259 | <a href="http://www.nytimes.com/">The New York Times</a>.</p> | |||
|
260 | ||||
|
261 | ||||
|
262 | ### Images ### | |||
|
263 | ||||
|
264 | Image syntax is very much like link syntax. | |||
|
265 | ||||
|
266 | Inline (titles are optional): | |||
|
267 | ||||
|
268 | ![alt text](/path/to/img.jpg "Title") | |||
|
269 | ||||
|
270 | Reference-style: | |||
|
271 | ||||
|
272 | ![alt text][id] | |||
|
273 | ||||
|
274 | [id]: /path/to/img.jpg "Title" | |||
|
275 | ||||
|
276 | Both of the above examples produce the same output: | |||
|
277 | ||||
|
278 | <img src="/path/to/img.jpg" alt="alt text" title="Title" /> | |||
|
279 | ||||
|
280 | ||||
|
281 | ||||
|
282 | ### Code ### | |||
|
283 | ||||
|
284 | In a regular paragraph, you can create code span by wrapping text in | |||
|
285 | backtick quotes. Any ampersands (`&`) and angle brackets (`<` or | |||
|
286 | `>`) will automatically be translated into HTML entities. This makes | |||
|
287 | it easy to use Markdown to write about HTML example code: | |||
|
288 | ||||
|
289 | I strongly recommend against using any `<blink>` tags. | |||
|
290 | ||||
|
291 | I wish SmartyPants used named entities like `&mdash;` | |||
|
292 | instead of decimal-encoded entites like `&#8212;`. | |||
|
293 | ||||
|
294 | Output: | |||
|
295 | ||||
|
296 | <p>I strongly recommend against using any | |||
|
297 | <code>&lt;blink&gt;</code> tags.</p> | |||
|
298 | ||||
|
299 | <p>I wish SmartyPants used named entities like | |||
|
300 | <code>&amp;mdash;</code> instead of decimal-encoded | |||
|
301 | entites like <code>&amp;#8212;</code>.</p> | |||
|
302 | ||||
|
303 | ||||
|
304 | To specify an entire block of pre-formatted code, indent every line of | |||
|
305 | the block by 4 spaces or 1 tab. Just like with code spans, `&`, `<`, | |||
|
306 | and `>` characters will be escaped automatically. | |||
|
307 | ||||
|
308 | Markdown: | |||
|
309 | ||||
|
310 | If you want your page to validate under XHTML 1.0 Strict, | |||
|
311 | you've got to put paragraph tags in your blockquotes: | |||
|
312 | ||||
|
313 | <blockquote> | |||
|
314 | <p>For example.</p> | |||
|
315 | </blockquote> | |||
|
316 | ||||
|
317 | Output: | |||
|
318 | ||||
|
319 | <p>If you want your page to validate under XHTML 1.0 Strict, | |||
|
320 | you've got to put paragraph tags in your blockquotes:</p> | |||
|
321 | ||||
|
322 | <pre><code>&lt;blockquote&gt; | |||
|
323 | &lt;p&gt;For example.&lt;/p&gt; | |||
|
324 | &lt;/blockquote&gt; | |||
|
325 | </code></pre> | |||
|
326 | </textarea></form> | |||
|
327 | ||||
|
328 | <script> | |||
|
329 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
330 | mode: 'markdown', | |||
|
331 | lineNumbers: true, | |||
|
332 | theme: "default", | |||
|
333 | extraKeys: {"Enter": "newlineAndIndentContinueMarkdownList"} | |||
|
334 | }); | |||
|
335 | </script> | |||
|
336 | ||||
|
337 | <p>Optionally depends on the XML mode for properly highlighted inline XML blocks.</p> | |||
|
338 | ||||
|
339 | <p><strong>MIME types defined:</strong> <code>text/x-markdown</code>.</p> | |||
|
340 | ||||
|
341 | <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#markdown_*">normal</a>, <a href="../../test/index.html#verbose,markdown_*">verbose</a>.</p> | |||
|
342 | ||||
|
343 | </body> | |||
|
344 | </html> |
This diff has been collapsed as it changes many lines, (526 lines changed) Show them Hide them | |||||
@@ -0,0 +1,526 b'' | |||||
|
1 | CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { | |||
|
2 | ||||
|
3 | var htmlFound = CodeMirror.modes.hasOwnProperty("xml"); | |||
|
4 | var htmlMode = CodeMirror.getMode(cmCfg, htmlFound ? {name: "xml", htmlMode: true} : "text/plain"); | |||
|
5 | var aliases = { | |||
|
6 | html: "htmlmixed", | |||
|
7 | js: "javascript", | |||
|
8 | json: "application/json", | |||
|
9 | c: "text/x-csrc", | |||
|
10 | "c++": "text/x-c++src", | |||
|
11 | java: "text/x-java", | |||
|
12 | csharp: "text/x-csharp", | |||
|
13 | "c#": "text/x-csharp", | |||
|
14 | scala: "text/x-scala" | |||
|
15 | }; | |||
|
16 | ||||
|
17 | var getMode = (function () { | |||
|
18 | var i, modes = {}, mimes = {}, mime; | |||
|
19 | ||||
|
20 | var list = []; | |||
|
21 | for (var m in CodeMirror.modes) | |||
|
22 | if (CodeMirror.modes.propertyIsEnumerable(m)) list.push(m); | |||
|
23 | for (i = 0; i < list.length; i++) { | |||
|
24 | modes[list[i]] = list[i]; | |||
|
25 | } | |||
|
26 | var mimesList = []; | |||
|
27 | for (var m in CodeMirror.mimeModes) | |||
|
28 | if (CodeMirror.mimeModes.propertyIsEnumerable(m)) | |||
|
29 | mimesList.push({mime: m, mode: CodeMirror.mimeModes[m]}); | |||
|
30 | for (i = 0; i < mimesList.length; i++) { | |||
|
31 | mime = mimesList[i].mime; | |||
|
32 | mimes[mime] = mimesList[i].mime; | |||
|
33 | } | |||
|
34 | ||||
|
35 | for (var a in aliases) { | |||
|
36 | if (aliases[a] in modes || aliases[a] in mimes) | |||
|
37 | modes[a] = aliases[a]; | |||
|
38 | } | |||
|
39 | ||||
|
40 | return function (lang) { | |||
|
41 | return modes[lang] ? CodeMirror.getMode(cmCfg, modes[lang]) : null; | |||
|
42 | }; | |||
|
43 | }()); | |||
|
44 | ||||
|
45 | // Should underscores in words open/close em/strong? | |||
|
46 | if (modeCfg.underscoresBreakWords === undefined) | |||
|
47 | modeCfg.underscoresBreakWords = true; | |||
|
48 | ||||
|
49 | // Turn on fenced code blocks? ("```" to start/end) | |||
|
50 | if (modeCfg.fencedCodeBlocks === undefined) modeCfg.fencedCodeBlocks = false; | |||
|
51 | ||||
|
52 | // Turn on task lists? ("- [ ] " and "- [x] ") | |||
|
53 | if (modeCfg.taskLists === undefined) modeCfg.taskLists = false; | |||
|
54 | ||||
|
55 | var codeDepth = 0; | |||
|
56 | ||||
|
57 | var header = 'header' | |||
|
58 | , code = 'comment' | |||
|
59 | , quote1 = 'atom' | |||
|
60 | , quote2 = 'number' | |||
|
61 | , list1 = 'variable-2' | |||
|
62 | , list2 = 'variable-3' | |||
|
63 | , list3 = 'keyword' | |||
|
64 | , hr = 'hr' | |||
|
65 | , image = 'tag' | |||
|
66 | , linkinline = 'link' | |||
|
67 | , linkemail = 'link' | |||
|
68 | , linktext = 'link' | |||
|
69 | , linkhref = 'string' | |||
|
70 | , em = 'em' | |||
|
71 | , strong = 'strong'; | |||
|
72 | ||||
|
73 | var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/ | |||
|
74 | , ulRE = /^[*\-+]\s+/ | |||
|
75 | , olRE = /^[0-9]+\.\s+/ | |||
|
76 | , taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE | |||
|
77 | , headerRE = /^(?:\={1,}|-{1,})$/ | |||
|
78 | , textRE = /^[^!\[\]*_\\<>` "'(]+/; | |||
|
79 | ||||
|
80 | function switchInline(stream, state, f) { | |||
|
81 | state.f = state.inline = f; | |||
|
82 | return f(stream, state); | |||
|
83 | } | |||
|
84 | ||||
|
85 | function switchBlock(stream, state, f) { | |||
|
86 | state.f = state.block = f; | |||
|
87 | return f(stream, state); | |||
|
88 | } | |||
|
89 | ||||
|
90 | ||||
|
91 | // Blocks | |||
|
92 | ||||
|
93 | function blankLine(state) { | |||
|
94 | // Reset linkTitle state | |||
|
95 | state.linkTitle = false; | |||
|
96 | // Reset EM state | |||
|
97 | state.em = false; | |||
|
98 | // Reset STRONG state | |||
|
99 | state.strong = false; | |||
|
100 | // Reset state.quote | |||
|
101 | state.quote = 0; | |||
|
102 | if (!htmlFound && state.f == htmlBlock) { | |||
|
103 | state.f = inlineNormal; | |||
|
104 | state.block = blockNormal; | |||
|
105 | } | |||
|
106 | // Mark this line as blank | |||
|
107 | state.thisLineHasContent = false; | |||
|
108 | return null; | |||
|
109 | } | |||
|
110 | ||||
|
111 | function blockNormal(stream, state) { | |||
|
112 | ||||
|
113 | var prevLineIsList = (state.list !== false); | |||
|
114 | if (state.list !== false && state.indentationDiff >= 0) { // Continued list | |||
|
115 | if (state.indentationDiff < 4) { // Only adjust indentation if *not* a code block | |||
|
116 | state.indentation -= state.indentationDiff; | |||
|
117 | } | |||
|
118 | state.list = null; | |||
|
119 | } else if (state.list !== false && state.indentation > 0) { | |||
|
120 | state.list = null; | |||
|
121 | state.listDepth = Math.floor(state.indentation / 4); | |||
|
122 | } else if (state.list !== false) { // No longer a list | |||
|
123 | state.list = false; | |||
|
124 | state.listDepth = 0; | |||
|
125 | } | |||
|
126 | ||||
|
127 | if (state.indentationDiff >= 4) { | |||
|
128 | state.indentation -= 4; | |||
|
129 | stream.skipToEnd(); | |||
|
130 | return code; | |||
|
131 | } else if (stream.eatSpace()) { | |||
|
132 | return null; | |||
|
133 | } else if (stream.peek() === '#' || (state.prevLineHasContent && stream.match(headerRE)) ) { | |||
|
134 | state.header = true; | |||
|
135 | } else if (stream.eat('>')) { | |||
|
136 | state.indentation++; | |||
|
137 | state.quote = 1; | |||
|
138 | stream.eatSpace(); | |||
|
139 | while (stream.eat('>')) { | |||
|
140 | stream.eatSpace(); | |||
|
141 | state.quote++; | |||
|
142 | } | |||
|
143 | } else if (stream.peek() === '[') { | |||
|
144 | return switchInline(stream, state, footnoteLink); | |||
|
145 | } else if (stream.match(hrRE, true)) { | |||
|
146 | return hr; | |||
|
147 | } else if ((!state.prevLineHasContent || prevLineIsList) && (stream.match(ulRE, true) || stream.match(olRE, true))) { | |||
|
148 | state.indentation += 4; | |||
|
149 | state.list = true; | |||
|
150 | state.listDepth++; | |||
|
151 | if (modeCfg.taskLists && stream.match(taskListRE, false)) { | |||
|
152 | state.taskList = true; | |||
|
153 | } | |||
|
154 | } else if (modeCfg.fencedCodeBlocks && stream.match(/^```([\w+#]*)/, true)) { | |||
|
155 | // try switching mode | |||
|
156 | state.localMode = getMode(RegExp.$1); | |||
|
157 | if (state.localMode) state.localState = state.localMode.startState(); | |||
|
158 | switchBlock(stream, state, local); | |||
|
159 | return code; | |||
|
160 | } | |||
|
161 | ||||
|
162 | return switchInline(stream, state, state.inline); | |||
|
163 | } | |||
|
164 | ||||
|
165 | function htmlBlock(stream, state) { | |||
|
166 | var style = htmlMode.token(stream, state.htmlState); | |||
|
167 | if (htmlFound && style === 'tag' && state.htmlState.type !== 'openTag' && !state.htmlState.context) { | |||
|
168 | state.f = inlineNormal; | |||
|
169 | state.block = blockNormal; | |||
|
170 | } | |||
|
171 | if (state.md_inside && stream.current().indexOf(">")!=-1) { | |||
|
172 | state.f = inlineNormal; | |||
|
173 | state.block = blockNormal; | |||
|
174 | state.htmlState.context = undefined; | |||
|
175 | } | |||
|
176 | return style; | |||
|
177 | } | |||
|
178 | ||||
|
179 | function local(stream, state) { | |||
|
180 | if (stream.sol() && stream.match(/^```/, true)) { | |||
|
181 | state.localMode = state.localState = null; | |||
|
182 | state.f = inlineNormal; | |||
|
183 | state.block = blockNormal; | |||
|
184 | return code; | |||
|
185 | } else if (state.localMode) { | |||
|
186 | return state.localMode.token(stream, state.localState); | |||
|
187 | } else { | |||
|
188 | stream.skipToEnd(); | |||
|
189 | return code; | |||
|
190 | } | |||
|
191 | } | |||
|
192 | ||||
|
193 | // Inline | |||
|
194 | function getType(state) { | |||
|
195 | var styles = []; | |||
|
196 | ||||
|
197 | if (state.taskOpen) { return "meta"; } | |||
|
198 | if (state.taskClosed) { return "property"; } | |||
|
199 | ||||
|
200 | if (state.strong) { styles.push(strong); } | |||
|
201 | if (state.em) { styles.push(em); } | |||
|
202 | ||||
|
203 | if (state.linkText) { styles.push(linktext); } | |||
|
204 | ||||
|
205 | if (state.code) { styles.push(code); } | |||
|
206 | ||||
|
207 | if (state.header) { styles.push(header); } | |||
|
208 | if (state.quote) { styles.push(state.quote % 2 ? quote1 : quote2); } | |||
|
209 | if (state.list !== false) { | |||
|
210 | var listMod = (state.listDepth - 1) % 3; | |||
|
211 | if (!listMod) { | |||
|
212 | styles.push(list1); | |||
|
213 | } else if (listMod === 1) { | |||
|
214 | styles.push(list2); | |||
|
215 | } else { | |||
|
216 | styles.push(list3); | |||
|
217 | } | |||
|
218 | } | |||
|
219 | ||||
|
220 | return styles.length ? styles.join(' ') : null; | |||
|
221 | } | |||
|
222 | ||||
|
223 | function handleText(stream, state) { | |||
|
224 | if (stream.match(textRE, true)) { | |||
|
225 | return getType(state); | |||
|
226 | } | |||
|
227 | return undefined; | |||
|
228 | } | |||
|
229 | ||||
|
230 | function inlineNormal(stream, state) { | |||
|
231 | var style = state.text(stream, state); | |||
|
232 | if (typeof style !== 'undefined') | |||
|
233 | return style; | |||
|
234 | ||||
|
235 | if (state.list) { // List marker (*, +, -, 1., etc) | |||
|
236 | state.list = null; | |||
|
237 | return getType(state); | |||
|
238 | } | |||
|
239 | ||||
|
240 | if (state.taskList) { | |||
|
241 | var taskOpen = stream.match(taskListRE, true)[1] !== "x"; | |||
|
242 | if (taskOpen) state.taskOpen = true; | |||
|
243 | else state.taskClosed = true; | |||
|
244 | state.taskList = false; | |||
|
245 | return getType(state); | |||
|
246 | } | |||
|
247 | ||||
|
248 | state.taskOpen = false; | |||
|
249 | state.taskClosed = false; | |||
|
250 | ||||
|
251 | var ch = stream.next(); | |||
|
252 | ||||
|
253 | if (ch === '\\') { | |||
|
254 | stream.next(); | |||
|
255 | return getType(state); | |||
|
256 | } | |||
|
257 | ||||
|
258 | // Matches link titles present on next line | |||
|
259 | if (state.linkTitle) { | |||
|
260 | state.linkTitle = false; | |||
|
261 | var matchCh = ch; | |||
|
262 | if (ch === '(') { | |||
|
263 | matchCh = ')'; | |||
|
264 | } | |||
|
265 | matchCh = (matchCh+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); | |||
|
266 | var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh; | |||
|
267 | if (stream.match(new RegExp(regex), true)) { | |||
|
268 | return linkhref; | |||
|
269 | } | |||
|
270 | } | |||
|
271 | ||||
|
272 | // If this block is changed, it may need to be updated in GFM mode | |||
|
273 | if (ch === '`') { | |||
|
274 | var t = getType(state); | |||
|
275 | var before = stream.pos; | |||
|
276 | stream.eatWhile('`'); | |||
|
277 | var difference = 1 + stream.pos - before; | |||
|
278 | if (!state.code) { | |||
|
279 | codeDepth = difference; | |||
|
280 | state.code = true; | |||
|
281 | return getType(state); | |||
|
282 | } else { | |||
|
283 | if (difference === codeDepth) { // Must be exact | |||
|
284 | state.code = false; | |||
|
285 | return t; | |||
|
286 | } | |||
|
287 | return getType(state); | |||
|
288 | } | |||
|
289 | } else if (state.code) { | |||
|
290 | return getType(state); | |||
|
291 | } | |||
|
292 | ||||
|
293 | if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) { | |||
|
294 | stream.match(/\[[^\]]*\]/); | |||
|
295 | state.inline = state.f = linkHref; | |||
|
296 | return image; | |||
|
297 | } | |||
|
298 | ||||
|
299 | if (ch === '[' && stream.match(/.*\](\(| ?\[)/, false)) { | |||
|
300 | state.linkText = true; | |||
|
301 | return getType(state); | |||
|
302 | } | |||
|
303 | ||||
|
304 | if (ch === ']' && state.linkText) { | |||
|
305 | var type = getType(state); | |||
|
306 | state.linkText = false; | |||
|
307 | state.inline = state.f = linkHref; | |||
|
308 | return type; | |||
|
309 | } | |||
|
310 | ||||
|
311 | if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) { | |||
|
312 | return switchInline(stream, state, inlineElement(linkinline, '>')); | |||
|
313 | } | |||
|
314 | ||||
|
315 | if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) { | |||
|
316 | return switchInline(stream, state, inlineElement(linkemail, '>')); | |||
|
317 | } | |||
|
318 | ||||
|
319 | if (ch === '<' && stream.match(/^\w/, false)) { | |||
|
320 | if (stream.string.indexOf(">")!=-1) { | |||
|
321 | var atts = stream.string.substring(1,stream.string.indexOf(">")); | |||
|
322 | if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) { | |||
|
323 | state.md_inside = true; | |||
|
324 | } | |||
|
325 | } | |||
|
326 | stream.backUp(1); | |||
|
327 | return switchBlock(stream, state, htmlBlock); | |||
|
328 | } | |||
|
329 | ||||
|
330 | if (ch === '<' && stream.match(/^\/\w*?>/)) { | |||
|
331 | state.md_inside = false; | |||
|
332 | return "tag"; | |||
|
333 | } | |||
|
334 | ||||
|
335 | var ignoreUnderscore = false; | |||
|
336 | if (!modeCfg.underscoresBreakWords) { | |||
|
337 | if (ch === '_' && stream.peek() !== '_' && stream.match(/(\w)/, false)) { | |||
|
338 | var prevPos = stream.pos - 2; | |||
|
339 | if (prevPos >= 0) { | |||
|
340 | var prevCh = stream.string.charAt(prevPos); | |||
|
341 | if (prevCh !== '_' && prevCh.match(/(\w)/, false)) { | |||
|
342 | ignoreUnderscore = true; | |||
|
343 | } | |||
|
344 | } | |||
|
345 | } | |||
|
346 | } | |||
|
347 | var t = getType(state); | |||
|
348 | if (ch === '*' || (ch === '_' && !ignoreUnderscore)) { | |||
|
349 | if (state.strong === ch && stream.eat(ch)) { // Remove STRONG | |||
|
350 | state.strong = false; | |||
|
351 | return t; | |||
|
352 | } else if (!state.strong && stream.eat(ch)) { // Add STRONG | |||
|
353 | state.strong = ch; | |||
|
354 | return getType(state); | |||
|
355 | } else if (state.em === ch) { // Remove EM | |||
|
356 | state.em = false; | |||
|
357 | return t; | |||
|
358 | } else if (!state.em) { // Add EM | |||
|
359 | state.em = ch; | |||
|
360 | return getType(state); | |||
|
361 | } | |||
|
362 | } else if (ch === ' ') { | |||
|
363 | if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces | |||
|
364 | if (stream.peek() === ' ') { // Surrounded by spaces, ignore | |||
|
365 | return getType(state); | |||
|
366 | } else { // Not surrounded by spaces, back up pointer | |||
|
367 | stream.backUp(1); | |||
|
368 | } | |||
|
369 | } | |||
|
370 | } | |||
|
371 | ||||
|
372 | return getType(state); | |||
|
373 | } | |||
|
374 | ||||
|
375 | function linkHref(stream, state) { | |||
|
376 | // Check if space, and return NULL if so (to avoid marking the space) | |||
|
377 | if(stream.eatSpace()){ | |||
|
378 | return null; | |||
|
379 | } | |||
|
380 | var ch = stream.next(); | |||
|
381 | if (ch === '(' || ch === '[') { | |||
|
382 | return switchInline(stream, state, inlineElement(linkhref, ch === '(' ? ')' : ']')); | |||
|
383 | } | |||
|
384 | return 'error'; | |||
|
385 | } | |||
|
386 | ||||
|
387 | function footnoteLink(stream, state) { | |||
|
388 | if (stream.match(/^[^\]]*\]:/, true)) { | |||
|
389 | state.f = footnoteUrl; | |||
|
390 | return linktext; | |||
|
391 | } | |||
|
392 | return switchInline(stream, state, inlineNormal); | |||
|
393 | } | |||
|
394 | ||||
|
395 | function footnoteUrl(stream, state) { | |||
|
396 | // Check if space, and return NULL if so (to avoid marking the space) | |||
|
397 | if(stream.eatSpace()){ | |||
|
398 | return null; | |||
|
399 | } | |||
|
400 | // Match URL | |||
|
401 | stream.match(/^[^\s]+/, true); | |||
|
402 | // Check for link title | |||
|
403 | if (stream.peek() === undefined) { // End of line, set flag to check next line | |||
|
404 | state.linkTitle = true; | |||
|
405 | } else { // More content on line, check if link title | |||
|
406 | stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true); | |||
|
407 | } | |||
|
408 | state.f = state.inline = inlineNormal; | |||
|
409 | return linkhref; | |||
|
410 | } | |||
|
411 | ||||
|
412 | var savedInlineRE = []; | |||
|
413 | function inlineRE(endChar) { | |||
|
414 | if (!savedInlineRE[endChar]) { | |||
|
415 | // Escape endChar for RegExp (taken from http://stackoverflow.com/a/494122/526741) | |||
|
416 | endChar = (endChar+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); | |||
|
417 | // Match any non-endChar, escaped character, as well as the closing | |||
|
418 | // endChar. | |||
|
419 | savedInlineRE[endChar] = new RegExp('^(?:[^\\\\]|\\\\.)*?(' + endChar + ')'); | |||
|
420 | } | |||
|
421 | return savedInlineRE[endChar]; | |||
|
422 | } | |||
|
423 | ||||
|
424 | function inlineElement(type, endChar, next) { | |||
|
425 | next = next || inlineNormal; | |||
|
426 | return function(stream, state) { | |||
|
427 | stream.match(inlineRE(endChar)); | |||
|
428 | state.inline = state.f = next; | |||
|
429 | return type; | |||
|
430 | }; | |||
|
431 | } | |||
|
432 | ||||
|
433 | return { | |||
|
434 | startState: function() { | |||
|
435 | return { | |||
|
436 | f: blockNormal, | |||
|
437 | ||||
|
438 | prevLineHasContent: false, | |||
|
439 | thisLineHasContent: false, | |||
|
440 | ||||
|
441 | block: blockNormal, | |||
|
442 | htmlState: CodeMirror.startState(htmlMode), | |||
|
443 | indentation: 0, | |||
|
444 | ||||
|
445 | inline: inlineNormal, | |||
|
446 | text: handleText, | |||
|
447 | ||||
|
448 | linkText: false, | |||
|
449 | linkTitle: false, | |||
|
450 | em: false, | |||
|
451 | strong: false, | |||
|
452 | header: false, | |||
|
453 | taskList: false, | |||
|
454 | list: false, | |||
|
455 | listDepth: 0, | |||
|
456 | quote: 0 | |||
|
457 | }; | |||
|
458 | }, | |||
|
459 | ||||
|
460 | copyState: function(s) { | |||
|
461 | return { | |||
|
462 | f: s.f, | |||
|
463 | ||||
|
464 | prevLineHasContent: s.prevLineHasContent, | |||
|
465 | thisLineHasContent: s.thisLineHasContent, | |||
|
466 | ||||
|
467 | block: s.block, | |||
|
468 | htmlState: CodeMirror.copyState(htmlMode, s.htmlState), | |||
|
469 | indentation: s.indentation, | |||
|
470 | ||||
|
471 | localMode: s.localMode, | |||
|
472 | localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null, | |||
|
473 | ||||
|
474 | inline: s.inline, | |||
|
475 | text: s.text, | |||
|
476 | linkTitle: s.linkTitle, | |||
|
477 | em: s.em, | |||
|
478 | strong: s.strong, | |||
|
479 | header: s.header, | |||
|
480 | taskList: s.taskList, | |||
|
481 | list: s.list, | |||
|
482 | listDepth: s.listDepth, | |||
|
483 | quote: s.quote, | |||
|
484 | md_inside: s.md_inside | |||
|
485 | }; | |||
|
486 | }, | |||
|
487 | ||||
|
488 | token: function(stream, state) { | |||
|
489 | if (stream.sol()) { | |||
|
490 | if (stream.match(/^\s*$/, true)) { | |||
|
491 | state.prevLineHasContent = false; | |||
|
492 | return blankLine(state); | |||
|
493 | } else { | |||
|
494 | state.prevLineHasContent = state.thisLineHasContent; | |||
|
495 | state.thisLineHasContent = true; | |||
|
496 | } | |||
|
497 | ||||
|
498 | // Reset state.header | |||
|
499 | state.header = false; | |||
|
500 | ||||
|
501 | // Reset state.taskList | |||
|
502 | state.taskList = false; | |||
|
503 | ||||
|
504 | // Reset state.code | |||
|
505 | state.code = false; | |||
|
506 | ||||
|
507 | state.f = state.block; | |||
|
508 | var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length; | |||
|
509 | var difference = Math.floor((indentation - state.indentation) / 4) * 4; | |||
|
510 | if (difference > 4) difference = 4; | |||
|
511 | var adjustedIndentation = state.indentation + difference; | |||
|
512 | state.indentationDiff = adjustedIndentation - state.indentation; | |||
|
513 | state.indentation = adjustedIndentation; | |||
|
514 | if (indentation > 0) return null; | |||
|
515 | } | |||
|
516 | return state.f(stream, state); | |||
|
517 | }, | |||
|
518 | ||||
|
519 | blankLine: blankLine, | |||
|
520 | ||||
|
521 | getType: getType | |||
|
522 | }; | |||
|
523 | ||||
|
524 | }, "xml"); | |||
|
525 | ||||
|
526 | CodeMirror.defineMIME("text/x-markdown", "markdown"); |
This diff has been collapsed as it changes many lines, (642 lines changed) Show them Hide them | |||||
@@ -0,0 +1,642 b'' | |||||
|
1 | (function() { | |||
|
2 | var mode = CodeMirror.getMode({tabSize: 4}, "markdown"); | |||
|
3 | function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | |||
|
4 | ||||
|
5 | MT("plainText", | |||
|
6 | "foo"); | |||
|
7 | ||||
|
8 | // Code blocks using 4 spaces (regardless of CodeMirror.tabSize value) | |||
|
9 | MT("codeBlocksUsing4Spaces", | |||
|
10 | " [comment foo]"); | |||
|
11 | ||||
|
12 | // Code blocks using 4 spaces with internal indentation | |||
|
13 | MT("codeBlocksUsing4SpacesIndentation", | |||
|
14 | " [comment bar]", | |||
|
15 | " [comment hello]", | |||
|
16 | " [comment world]", | |||
|
17 | " [comment foo]", | |||
|
18 | "bar"); | |||
|
19 | ||||
|
20 | // Code blocks using 4 spaces with internal indentation | |||
|
21 | MT("codeBlocksUsing4SpacesIndentation", | |||
|
22 | " foo", | |||
|
23 | " [comment bar]", | |||
|
24 | " [comment hello]", | |||
|
25 | " [comment world]"); | |||
|
26 | ||||
|
27 | // Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value) | |||
|
28 | MT("codeBlocksUsing1Tab", | |||
|
29 | "\t[comment foo]"); | |||
|
30 | ||||
|
31 | // Inline code using backticks | |||
|
32 | MT("inlineCodeUsingBackticks", | |||
|
33 | "foo [comment `bar`]"); | |||
|
34 | ||||
|
35 | // Block code using single backtick (shouldn't work) | |||
|
36 | MT("blockCodeSingleBacktick", | |||
|
37 | "[comment `]", | |||
|
38 | "foo", | |||
|
39 | "[comment `]"); | |||
|
40 | ||||
|
41 | // Unclosed backticks | |||
|
42 | // Instead of simply marking as CODE, it would be nice to have an | |||
|
43 | // incomplete flag for CODE, that is styled slightly different. | |||
|
44 | MT("unclosedBackticks", | |||
|
45 | "foo [comment `bar]"); | |||
|
46 | ||||
|
47 | // Per documentation: "To include a literal backtick character within a | |||
|
48 | // code span, you can use multiple backticks as the opening and closing | |||
|
49 | // delimiters" | |||
|
50 | MT("doubleBackticks", | |||
|
51 | "[comment ``foo ` bar``]"); | |||
|
52 | ||||
|
53 | // Tests based on Dingus | |||
|
54 | // http://daringfireball.net/projects/markdown/dingus | |||
|
55 | // | |||
|
56 | // Multiple backticks within an inline code block | |||
|
57 | MT("consecutiveBackticks", | |||
|
58 | "[comment `foo```bar`]"); | |||
|
59 | ||||
|
60 | // Multiple backticks within an inline code block with a second code block | |||
|
61 | MT("consecutiveBackticks", | |||
|
62 | "[comment `foo```bar`] hello [comment `world`]"); | |||
|
63 | ||||
|
64 | // Unclosed with several different groups of backticks | |||
|
65 | MT("unclosedBackticks", | |||
|
66 | "[comment ``foo ``` bar` hello]"); | |||
|
67 | ||||
|
68 | // Closed with several different groups of backticks | |||
|
69 | MT("closedBackticks", | |||
|
70 | "[comment ``foo ``` bar` hello``] world"); | |||
|
71 | ||||
|
72 | // atx headers | |||
|
73 | // http://daringfireball.net/projects/markdown/syntax#header | |||
|
74 | ||||
|
75 | MT("atxH1", | |||
|
76 | "[header # foo]"); | |||
|
77 | ||||
|
78 | MT("atxH2", | |||
|
79 | "[header ## foo]"); | |||
|
80 | ||||
|
81 | MT("atxH3", | |||
|
82 | "[header ### foo]"); | |||
|
83 | ||||
|
84 | MT("atxH4", | |||
|
85 | "[header #### foo]"); | |||
|
86 | ||||
|
87 | MT("atxH5", | |||
|
88 | "[header ##### foo]"); | |||
|
89 | ||||
|
90 | MT("atxH6", | |||
|
91 | "[header ###### foo]"); | |||
|
92 | ||||
|
93 | // H6 - 7x '#' should still be H6, per Dingus | |||
|
94 | // http://daringfireball.net/projects/markdown/dingus | |||
|
95 | MT("atxH6NotH7", | |||
|
96 | "[header ####### foo]"); | |||
|
97 | ||||
|
98 | // Setext headers - H1, H2 | |||
|
99 | // Per documentation, "Any number of underlining =’s or -’s will work." | |||
|
100 | // http://daringfireball.net/projects/markdown/syntax#header | |||
|
101 | // Ideally, the text would be marked as `header` as well, but this is | |||
|
102 | // not really feasible at the moment. So, instead, we're testing against | |||
|
103 | // what works today, to avoid any regressions. | |||
|
104 | // | |||
|
105 | // Check if single underlining = works | |||
|
106 | MT("setextH1", | |||
|
107 | "foo", | |||
|
108 | "[header =]"); | |||
|
109 | ||||
|
110 | // Check if 3+ ='s work | |||
|
111 | MT("setextH1", | |||
|
112 | "foo", | |||
|
113 | "[header ===]"); | |||
|
114 | ||||
|
115 | // Check if single underlining - works | |||
|
116 | MT("setextH2", | |||
|
117 | "foo", | |||
|
118 | "[header -]"); | |||
|
119 | ||||
|
120 | // Check if 3+ -'s work | |||
|
121 | MT("setextH2", | |||
|
122 | "foo", | |||
|
123 | "[header ---]"); | |||
|
124 | ||||
|
125 | // Single-line blockquote with trailing space | |||
|
126 | MT("blockquoteSpace", | |||
|
127 | "[atom > foo]"); | |||
|
128 | ||||
|
129 | // Single-line blockquote | |||
|
130 | MT("blockquoteNoSpace", | |||
|
131 | "[atom >foo]"); | |||
|
132 | ||||
|
133 | // No blank line before blockquote | |||
|
134 | MT("blockquoteNoBlankLine", | |||
|
135 | "foo", | |||
|
136 | "[atom > bar]"); | |||
|
137 | ||||
|
138 | // Nested blockquote | |||
|
139 | MT("blockquoteSpace", | |||
|
140 | "[atom > foo]", | |||
|
141 | "[number > > foo]", | |||
|
142 | "[atom > > > foo]"); | |||
|
143 | ||||
|
144 | // Single-line blockquote followed by normal paragraph | |||
|
145 | MT("blockquoteThenParagraph", | |||
|
146 | "[atom >foo]", | |||
|
147 | "", | |||
|
148 | "bar"); | |||
|
149 | ||||
|
150 | // Multi-line blockquote (lazy mode) | |||
|
151 | MT("multiBlockquoteLazy", | |||
|
152 | "[atom >foo]", | |||
|
153 | "[atom bar]"); | |||
|
154 | ||||
|
155 | // Multi-line blockquote followed by normal paragraph (lazy mode) | |||
|
156 | MT("multiBlockquoteLazyThenParagraph", | |||
|
157 | "[atom >foo]", | |||
|
158 | "[atom bar]", | |||
|
159 | "", | |||
|
160 | "hello"); | |||
|
161 | ||||
|
162 | // Multi-line blockquote (non-lazy mode) | |||
|
163 | MT("multiBlockquote", | |||
|
164 | "[atom >foo]", | |||
|
165 | "[atom >bar]"); | |||
|
166 | ||||
|
167 | // Multi-line blockquote followed by normal paragraph (non-lazy mode) | |||
|
168 | MT("multiBlockquoteThenParagraph", | |||
|
169 | "[atom >foo]", | |||
|
170 | "[atom >bar]", | |||
|
171 | "", | |||
|
172 | "hello"); | |||
|
173 | ||||
|
174 | // Check list types | |||
|
175 | ||||
|
176 | MT("listAsterisk", | |||
|
177 | "foo", | |||
|
178 | "bar", | |||
|
179 | "", | |||
|
180 | "[variable-2 * foo]", | |||
|
181 | "[variable-2 * bar]"); | |||
|
182 | ||||
|
183 | MT("listPlus", | |||
|
184 | "foo", | |||
|
185 | "bar", | |||
|
186 | "", | |||
|
187 | "[variable-2 + foo]", | |||
|
188 | "[variable-2 + bar]"); | |||
|
189 | ||||
|
190 | MT("listDash", | |||
|
191 | "foo", | |||
|
192 | "bar", | |||
|
193 | "", | |||
|
194 | "[variable-2 - foo]", | |||
|
195 | "[variable-2 - bar]"); | |||
|
196 | ||||
|
197 | MT("listNumber", | |||
|
198 | "foo", | |||
|
199 | "bar", | |||
|
200 | "", | |||
|
201 | "[variable-2 1. foo]", | |||
|
202 | "[variable-2 2. bar]"); | |||
|
203 | ||||
|
204 | // Lists require a preceding blank line (per Dingus) | |||
|
205 | MT("listBogus", | |||
|
206 | "foo", | |||
|
207 | "1. bar", | |||
|
208 | "2. hello"); | |||
|
209 | ||||
|
210 | // Formatting in lists (*) | |||
|
211 | MT("listAsteriskFormatting", | |||
|
212 | "[variable-2 * ][variable-2&em *foo*][variable-2 bar]", | |||
|
213 | "[variable-2 * ][variable-2&strong **foo**][variable-2 bar]", | |||
|
214 | "[variable-2 * ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]", | |||
|
215 | "[variable-2 * ][variable-2&comment `foo`][variable-2 bar]"); | |||
|
216 | ||||
|
217 | // Formatting in lists (+) | |||
|
218 | MT("listPlusFormatting", | |||
|
219 | "[variable-2 + ][variable-2&em *foo*][variable-2 bar]", | |||
|
220 | "[variable-2 + ][variable-2&strong **foo**][variable-2 bar]", | |||
|
221 | "[variable-2 + ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]", | |||
|
222 | "[variable-2 + ][variable-2&comment `foo`][variable-2 bar]"); | |||
|
223 | ||||
|
224 | // Formatting in lists (-) | |||
|
225 | MT("listDashFormatting", | |||
|
226 | "[variable-2 - ][variable-2&em *foo*][variable-2 bar]", | |||
|
227 | "[variable-2 - ][variable-2&strong **foo**][variable-2 bar]", | |||
|
228 | "[variable-2 - ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]", | |||
|
229 | "[variable-2 - ][variable-2&comment `foo`][variable-2 bar]"); | |||
|
230 | ||||
|
231 | // Formatting in lists (1.) | |||
|
232 | MT("listNumberFormatting", | |||
|
233 | "[variable-2 1. ][variable-2&em *foo*][variable-2 bar]", | |||
|
234 | "[variable-2 2. ][variable-2&strong **foo**][variable-2 bar]", | |||
|
235 | "[variable-2 3. ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]", | |||
|
236 | "[variable-2 4. ][variable-2&comment `foo`][variable-2 bar]"); | |||
|
237 | ||||
|
238 | // Paragraph lists | |||
|
239 | MT("listParagraph", | |||
|
240 | "[variable-2 * foo]", | |||
|
241 | "", | |||
|
242 | "[variable-2 * bar]"); | |||
|
243 | ||||
|
244 | // Multi-paragraph lists | |||
|
245 | // | |||
|
246 | // 4 spaces | |||
|
247 | MT("listMultiParagraph", | |||
|
248 | "[variable-2 * foo]", | |||
|
249 | "", | |||
|
250 | "[variable-2 * bar]", | |||
|
251 | "", | |||
|
252 | " [variable-2 hello]"); | |||
|
253 | ||||
|
254 | // 4 spaces, extra blank lines (should still be list, per Dingus) | |||
|
255 | MT("listMultiParagraphExtra", | |||
|
256 | "[variable-2 * foo]", | |||
|
257 | "", | |||
|
258 | "[variable-2 * bar]", | |||
|
259 | "", | |||
|
260 | "", | |||
|
261 | " [variable-2 hello]"); | |||
|
262 | ||||
|
263 | // 4 spaces, plus 1 space (should still be list, per Dingus) | |||
|
264 | MT("listMultiParagraphExtraSpace", | |||
|
265 | "[variable-2 * foo]", | |||
|
266 | "", | |||
|
267 | "[variable-2 * bar]", | |||
|
268 | "", | |||
|
269 | " [variable-2 hello]", | |||
|
270 | "", | |||
|
271 | " [variable-2 world]"); | |||
|
272 | ||||
|
273 | // 1 tab | |||
|
274 | MT("listTab", | |||
|
275 | "[variable-2 * foo]", | |||
|
276 | "", | |||
|
277 | "[variable-2 * bar]", | |||
|
278 | "", | |||
|
279 | "\t[variable-2 hello]"); | |||
|
280 | ||||
|
281 | // No indent | |||
|
282 | MT("listNoIndent", | |||
|
283 | "[variable-2 * foo]", | |||
|
284 | "", | |||
|
285 | "[variable-2 * bar]", | |||
|
286 | "", | |||
|
287 | "hello"); | |||
|
288 | ||||
|
289 | // Blockquote | |||
|
290 | MT("blockquote", | |||
|
291 | "[variable-2 * foo]", | |||
|
292 | "", | |||
|
293 | "[variable-2 * bar]", | |||
|
294 | "", | |||
|
295 | " [variable-2&atom > hello]"); | |||
|
296 | ||||
|
297 | // Code block | |||
|
298 | MT("blockquoteCode", | |||
|
299 | "[variable-2 * foo]", | |||
|
300 | "", | |||
|
301 | "[variable-2 * bar]", | |||
|
302 | "", | |||
|
303 | " [comment > hello]", | |||
|
304 | "", | |||
|
305 | " [variable-2 world]"); | |||
|
306 | ||||
|
307 | // Code block followed by text | |||
|
308 | MT("blockquoteCodeText", | |||
|
309 | "[variable-2 * foo]", | |||
|
310 | "", | |||
|
311 | " [variable-2 bar]", | |||
|
312 | "", | |||
|
313 | " [comment hello]", | |||
|
314 | "", | |||
|
315 | " [variable-2 world]"); | |||
|
316 | ||||
|
317 | // Nested list | |||
|
318 | ||||
|
319 | MT("listAsteriskNested", | |||
|
320 | "[variable-2 * foo]", | |||
|
321 | "", | |||
|
322 | " [variable-3 * bar]"); | |||
|
323 | ||||
|
324 | MT("listPlusNested", | |||
|
325 | "[variable-2 + foo]", | |||
|
326 | "", | |||
|
327 | " [variable-3 + bar]"); | |||
|
328 | ||||
|
329 | MT("listDashNested", | |||
|
330 | "[variable-2 - foo]", | |||
|
331 | "", | |||
|
332 | " [variable-3 - bar]"); | |||
|
333 | ||||
|
334 | MT("listNumberNested", | |||
|
335 | "[variable-2 1. foo]", | |||
|
336 | "", | |||
|
337 | " [variable-3 2. bar]"); | |||
|
338 | ||||
|
339 | MT("listMixed", | |||
|
340 | "[variable-2 * foo]", | |||
|
341 | "", | |||
|
342 | " [variable-3 + bar]", | |||
|
343 | "", | |||
|
344 | " [keyword - hello]", | |||
|
345 | "", | |||
|
346 | " [variable-2 1. world]"); | |||
|
347 | ||||
|
348 | MT("listBlockquote", | |||
|
349 | "[variable-2 * foo]", | |||
|
350 | "", | |||
|
351 | " [variable-3 + bar]", | |||
|
352 | "", | |||
|
353 | " [atom&variable-3 > hello]"); | |||
|
354 | ||||
|
355 | MT("listCode", | |||
|
356 | "[variable-2 * foo]", | |||
|
357 | "", | |||
|
358 | " [variable-3 + bar]", | |||
|
359 | "", | |||
|
360 | " [comment hello]"); | |||
|
361 | ||||
|
362 | // Code with internal indentation | |||
|
363 | MT("listCodeIndentation", | |||
|
364 | "[variable-2 * foo]", | |||
|
365 | "", | |||
|
366 | " [comment bar]", | |||
|
367 | " [comment hello]", | |||
|
368 | " [comment world]", | |||
|
369 | " [comment foo]", | |||
|
370 | " [variable-2 bar]"); | |||
|
371 | ||||
|
372 | // List nesting edge cases | |||
|
373 | MT("listNested", | |||
|
374 | "[variable-2 * foo]", | |||
|
375 | "", | |||
|
376 | " [variable-3 * bar]", | |||
|
377 | "", | |||
|
378 | " [variable-2 hello]" | |||
|
379 | ); | |||
|
380 | MT("listNested", | |||
|
381 | "[variable-2 * foo]", | |||
|
382 | "", | |||
|
383 | " [variable-3 * bar]", | |||
|
384 | "", | |||
|
385 | " [variable-3 * foo]" | |||
|
386 | ); | |||
|
387 | ||||
|
388 | // Code followed by text | |||
|
389 | MT("listCodeText", | |||
|
390 | "[variable-2 * foo]", | |||
|
391 | "", | |||
|
392 | " [comment bar]", | |||
|
393 | "", | |||
|
394 | "hello"); | |||
|
395 | ||||
|
396 | // Following tests directly from official Markdown documentation | |||
|
397 | // http://daringfireball.net/projects/markdown/syntax#hr | |||
|
398 | ||||
|
399 | MT("hrSpace", | |||
|
400 | "[hr * * *]"); | |||
|
401 | ||||
|
402 | MT("hr", | |||
|
403 | "[hr ***]"); | |||
|
404 | ||||
|
405 | MT("hrLong", | |||
|
406 | "[hr *****]"); | |||
|
407 | ||||
|
408 | MT("hrSpaceDash", | |||
|
409 | "[hr - - -]"); | |||
|
410 | ||||
|
411 | MT("hrDashLong", | |||
|
412 | "[hr ---------------------------------------]"); | |||
|
413 | ||||
|
414 | // Inline link with title | |||
|
415 | MT("linkTitle", | |||
|
416 | "[link [[foo]]][string (http://example.com/ \"bar\")] hello"); | |||
|
417 | ||||
|
418 | // Inline link without title | |||
|
419 | MT("linkNoTitle", | |||
|
420 | "[link [[foo]]][string (http://example.com/)] bar"); | |||
|
421 | ||||
|
422 | // Inline link with image | |||
|
423 | MT("linkImage", | |||
|
424 | "[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar"); | |||
|
425 | ||||
|
426 | // Inline link with Em | |||
|
427 | MT("linkEm", | |||
|
428 | "[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar"); | |||
|
429 | ||||
|
430 | // Inline link with Strong | |||
|
431 | MT("linkStrong", | |||
|
432 | "[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar"); | |||
|
433 | ||||
|
434 | // Inline link with EmStrong | |||
|
435 | MT("linkEmStrong", | |||
|
436 | "[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string (http://example.com/)] bar"); | |||
|
437 | ||||
|
438 | // Image with title | |||
|
439 | MT("imageTitle", | |||
|
440 | "[tag ![[foo]]][string (http://example.com/ \"bar\")] hello"); | |||
|
441 | ||||
|
442 | // Image without title | |||
|
443 | MT("imageNoTitle", | |||
|
444 | "[tag ![[foo]]][string (http://example.com/)] bar"); | |||
|
445 | ||||
|
446 | // Image with asterisks | |||
|
447 | MT("imageAsterisks", | |||
|
448 | "[tag ![[*foo*]]][string (http://example.com/)] bar"); | |||
|
449 | ||||
|
450 | // Not a link. Should be normal text due to square brackets being used | |||
|
451 | // regularly in text, especially in quoted material, and no space is allowed | |||
|
452 | // between square brackets and parentheses (per Dingus). | |||
|
453 | MT("notALink", | |||
|
454 | "[[foo]] (bar)"); | |||
|
455 | ||||
|
456 | // Reference-style links | |||
|
457 | MT("linkReference", | |||
|
458 | "[link [[foo]]][string [[bar]]] hello"); | |||
|
459 | ||||
|
460 | // Reference-style links with Em | |||
|
461 | MT("linkReferenceEm", | |||
|
462 | "[link [[][link&em *foo*][link ]]][string [[bar]]] hello"); | |||
|
463 | ||||
|
464 | // Reference-style links with Strong | |||
|
465 | MT("linkReferenceStrong", | |||
|
466 | "[link [[][link&strong **foo**][link ]]][string [[bar]]] hello"); | |||
|
467 | ||||
|
468 | // Reference-style links with EmStrong | |||
|
469 | MT("linkReferenceEmStrong", | |||
|
470 | "[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string [[bar]]] hello"); | |||
|
471 | ||||
|
472 | // Reference-style links with optional space separator (per docuentation) | |||
|
473 | // "You can optionally use a space to separate the sets of brackets" | |||
|
474 | MT("linkReferenceSpace", | |||
|
475 | "[link [[foo]]] [string [[bar]]] hello"); | |||
|
476 | ||||
|
477 | // Should only allow a single space ("...use *a* space...") | |||
|
478 | MT("linkReferenceDoubleSpace", | |||
|
479 | "[[foo]] [[bar]] hello"); | |||
|
480 | ||||
|
481 | // Reference-style links with implicit link name | |||
|
482 | MT("linkImplicit", | |||
|
483 | "[link [[foo]]][string [[]]] hello"); | |||
|
484 | ||||
|
485 | // @todo It would be nice if, at some point, the document was actually | |||
|
486 | // checked to see if the referenced link exists | |||
|
487 | ||||
|
488 | // Link label, for reference-style links (taken from documentation) | |||
|
489 | ||||
|
490 | MT("labelNoTitle", | |||
|
491 | "[link [[foo]]:] [string http://example.com/]"); | |||
|
492 | ||||
|
493 | MT("labelIndented", | |||
|
494 | " [link [[foo]]:] [string http://example.com/]"); | |||
|
495 | ||||
|
496 | MT("labelSpaceTitle", | |||
|
497 | "[link [[foo bar]]:] [string http://example.com/ \"hello\"]"); | |||
|
498 | ||||
|
499 | MT("labelDoubleTitle", | |||
|
500 | "[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\""); | |||
|
501 | ||||
|
502 | MT("labelTitleDoubleQuotes", | |||
|
503 | "[link [[foo]]:] [string http://example.com/ \"bar\"]"); | |||
|
504 | ||||
|
505 | MT("labelTitleSingleQuotes", | |||
|
506 | "[link [[foo]]:] [string http://example.com/ 'bar']"); | |||
|
507 | ||||
|
508 | MT("labelTitleParenthese", | |||
|
509 | "[link [[foo]]:] [string http://example.com/ (bar)]"); | |||
|
510 | ||||
|
511 | MT("labelTitleInvalid", | |||
|
512 | "[link [[foo]]:] [string http://example.com/] bar"); | |||
|
513 | ||||
|
514 | MT("labelLinkAngleBrackets", | |||
|
515 | "[link [[foo]]:] [string <http://example.com/> \"bar\"]"); | |||
|
516 | ||||
|
517 | MT("labelTitleNextDoubleQuotes", | |||
|
518 | "[link [[foo]]:] [string http://example.com/]", | |||
|
519 | "[string \"bar\"] hello"); | |||
|
520 | ||||
|
521 | MT("labelTitleNextSingleQuotes", | |||
|
522 | "[link [[foo]]:] [string http://example.com/]", | |||
|
523 | "[string 'bar'] hello"); | |||
|
524 | ||||
|
525 | MT("labelTitleNextParenthese", | |||
|
526 | "[link [[foo]]:] [string http://example.com/]", | |||
|
527 | "[string (bar)] hello"); | |||
|
528 | ||||
|
529 | MT("labelTitleNextMixed", | |||
|
530 | "[link [[foo]]:] [string http://example.com/]", | |||
|
531 | "(bar\" hello"); | |||
|
532 | ||||
|
533 | MT("linkWeb", | |||
|
534 | "[link <http://example.com/>] foo"); | |||
|
535 | ||||
|
536 | MT("linkWebDouble", | |||
|
537 | "[link <http://example.com/>] foo [link <http://example.com/>]"); | |||
|
538 | ||||
|
539 | MT("linkEmail", | |||
|
540 | "[link <user@example.com>] foo"); | |||
|
541 | ||||
|
542 | MT("linkEmailDouble", | |||
|
543 | "[link <user@example.com>] foo [link <user@example.com>]"); | |||
|
544 | ||||
|
545 | MT("emAsterisk", | |||
|
546 | "[em *foo*] bar"); | |||
|
547 | ||||
|
548 | MT("emUnderscore", | |||
|
549 | "[em _foo_] bar"); | |||
|
550 | ||||
|
551 | MT("emInWordAsterisk", | |||
|
552 | "foo[em *bar*]hello"); | |||
|
553 | ||||
|
554 | MT("emInWordUnderscore", | |||
|
555 | "foo[em _bar_]hello"); | |||
|
556 | ||||
|
557 | // Per documentation: "...surround an * or _ with spaces, it’ll be | |||
|
558 | // treated as a literal asterisk or underscore." | |||
|
559 | ||||
|
560 | MT("emEscapedBySpaceIn", | |||
|
561 | "foo [em _bar _ hello_] world"); | |||
|
562 | ||||
|
563 | MT("emEscapedBySpaceOut", | |||
|
564 | "foo _ bar[em _hello_]world"); | |||
|
565 | ||||
|
566 | // Unclosed emphasis characters | |||
|
567 | // Instead of simply marking as EM / STRONG, it would be nice to have an | |||
|
568 | // incomplete flag for EM and STRONG, that is styled slightly different. | |||
|
569 | MT("emIncompleteAsterisk", | |||
|
570 | "foo [em *bar]"); | |||
|
571 | ||||
|
572 | MT("emIncompleteUnderscore", | |||
|
573 | "foo [em _bar]"); | |||
|
574 | ||||
|
575 | MT("strongAsterisk", | |||
|
576 | "[strong **foo**] bar"); | |||
|
577 | ||||
|
578 | MT("strongUnderscore", | |||
|
579 | "[strong __foo__] bar"); | |||
|
580 | ||||
|
581 | MT("emStrongAsterisk", | |||
|
582 | "[em *foo][em&strong **bar*][strong hello**] world"); | |||
|
583 | ||||
|
584 | MT("emStrongUnderscore", | |||
|
585 | "[em _foo][em&strong __bar_][strong hello__] world"); | |||
|
586 | ||||
|
587 | // "...same character must be used to open and close an emphasis span."" | |||
|
588 | MT("emStrongMixed", | |||
|
589 | "[em _foo][em&strong **bar*hello__ world]"); | |||
|
590 | ||||
|
591 | MT("emStrongMixed", | |||
|
592 | "[em *foo][em&strong __bar_hello** world]"); | |||
|
593 | ||||
|
594 | // These characters should be escaped: | |||
|
595 | // \ backslash | |||
|
596 | // ` backtick | |||
|
597 | // * asterisk | |||
|
598 | // _ underscore | |||
|
599 | // {} curly braces | |||
|
600 | // [] square brackets | |||
|
601 | // () parentheses | |||
|
602 | // # hash mark | |||
|
603 | // + plus sign | |||
|
604 | // - minus sign (hyphen) | |||
|
605 | // . dot | |||
|
606 | // ! exclamation mark | |||
|
607 | ||||
|
608 | MT("escapeBacktick", | |||
|
609 | "foo \\`bar\\`"); | |||
|
610 | ||||
|
611 | MT("doubleEscapeBacktick", | |||
|
612 | "foo \\\\[comment `bar\\\\`]"); | |||
|
613 | ||||
|
614 | MT("escapeAsterisk", | |||
|
615 | "foo \\*bar\\*"); | |||
|
616 | ||||
|
617 | MT("doubleEscapeAsterisk", | |||
|
618 | "foo \\\\[em *bar\\\\*]"); | |||
|
619 | ||||
|
620 | MT("escapeUnderscore", | |||
|
621 | "foo \\_bar\\_"); | |||
|
622 | ||||
|
623 | MT("doubleEscapeUnderscore", | |||
|
624 | "foo \\\\[em _bar\\\\_]"); | |||
|
625 | ||||
|
626 | MT("escapeHash", | |||
|
627 | "\\# foo"); | |||
|
628 | ||||
|
629 | MT("doubleEscapeHash", | |||
|
630 | "\\\\# foo"); | |||
|
631 | ||||
|
632 | ||||
|
633 | // Tests to make sure GFM-specific things aren't getting through | |||
|
634 | ||||
|
635 | MT("taskList", | |||
|
636 | "[variable-2 * [ ]] bar]"); | |||
|
637 | ||||
|
638 | MT("fencedCodeBlocks", | |||
|
639 | "[comment ```]", | |||
|
640 | "foo", | |||
|
641 | "[comment ```]"); | |||
|
642 | })(); |
@@ -0,0 +1,77 b'' | |||||
|
1 | CodeMirror.modeInfo = [ | |||
|
2 | {name: 'APL', mime: 'text/apl', mode: 'apl'}, | |||
|
3 | {name: 'Asterisk', mime: 'text/x-asterisk', mode: 'asterisk'}, | |||
|
4 | {name: 'C', mime: 'text/x-csrc', mode: 'clike'}, | |||
|
5 | {name: 'C++', mime: 'text/x-c++src', mode: 'clike'}, | |||
|
6 | {name: 'Cobol', mime: 'text/x-cobol', mode: 'cobol'}, | |||
|
7 | {name: 'Java', mime: 'text/x-java', mode: 'clike'}, | |||
|
8 | {name: 'C#', mime: 'text/x-csharp', mode: 'clike'}, | |||
|
9 | {name: 'Scala', mime: 'text/x-scala', mode: 'clike'}, | |||
|
10 | {name: 'Clojure', mime: 'text/x-clojure', mode: 'clojure'}, | |||
|
11 | {name: 'CoffeeScript', mime: 'text/x-coffeescript', mode: 'coffeescript'}, | |||
|
12 | {name: 'Common Lisp', mime: 'text/x-common-lisp', mode: 'commonlisp'}, | |||
|
13 | {name: 'CSS', mime: 'text/css', mode: 'css'}, | |||
|
14 | {name: 'D', mime: 'text/x-d', mode: 'd'}, | |||
|
15 | {name: 'diff', mime: 'text/x-diff', mode: 'diff'}, | |||
|
16 | {name: 'ECL', mime: 'text/x-ecl', mode: 'ecl'}, | |||
|
17 | {name: 'Erlang', mime: 'text/x-erlang', mode: 'erlang'}, | |||
|
18 | {name: 'Gas', mime: 'text/x-gas', mode: 'gas'}, | |||
|
19 | {name: 'GitHub Flavored Markdown', mode: 'gfm'}, | |||
|
20 | {name: 'GO', mime: 'text/x-go', mode: 'go'}, | |||
|
21 | {name: 'Groovy', mime: 'text/x-groovy', mode: 'groovy'}, | |||
|
22 | {name: 'Haskell', mime: 'text/x-haskell', mode: 'haskell'}, | |||
|
23 | {name: 'Haxe', mime: 'text/x-haxe', mode: 'haxe'}, | |||
|
24 | {name: 'ASP.NET', mime: 'application/x-aspx', mode: 'htmlembedded'}, | |||
|
25 | {name: 'Embedded Javascript', mime: 'application/x-ejs', mode: 'htmlembedded'}, | |||
|
26 | {name: 'JavaServer Pages', mime: 'application/x-jsp', mode: 'htmlembedded'}, | |||
|
27 | {name: 'HTML', mime: 'text/html', mode: 'htmlmixed'}, | |||
|
28 | {name: 'HTTP', mime: 'message/http', mode: 'http'}, | |||
|
29 | {name: 'JavaScript', mime: 'text/javascript', mode: 'javascript'}, | |||
|
30 | {name: 'JSON', mime: 'application/x-json', mode: 'javascript'}, | |||
|
31 | {name: 'JSON', mime: 'application/json', mode: 'javascript'}, | |||
|
32 | {name: 'TypeScript', mime: 'application/typescript', mode: 'javascript'}, | |||
|
33 | {name: 'Jinja2', mime: 'jinja2', mode: 'jinja2'}, | |||
|
34 | {name: 'LESS', mime: 'text/x-less', mode: 'less'}, | |||
|
35 | {name: 'LiveScript', mime: 'text/x-livescript', mode: 'livescript'}, | |||
|
36 | {name: 'Lua', mime: 'text/x-lua', mode: 'lua'}, | |||
|
37 | {name: 'Markdown (GitHub-flavour)', mime: 'text/x-markdown', mode: 'markdown'}, | |||
|
38 | {name: 'mIRC', mime: 'text/mirc', mode: 'mirc'}, | |||
|
39 | {name: 'NTriples', mime: 'text/n-triples', mode: 'ntriples'}, | |||
|
40 | {name: 'OCaml', mime: 'text/x-ocaml', mode: 'ocaml'}, | |||
|
41 | {name: 'Pascal', mime: 'text/x-pascal', mode: 'pascal'}, | |||
|
42 | {name: 'Perl', mime: 'text/x-perl', mode: 'perl'}, | |||
|
43 | {name: 'PHP', mime: 'text/x-php', mode: 'php'}, | |||
|
44 | {name: 'PHP(HTML)', mime: 'application/x-httpd-php', mode: 'php'}, | |||
|
45 | {name: 'Pig', mime: 'text/x-pig', mode: 'pig'}, | |||
|
46 | {name: 'Plain Text', mime: 'text/plain', mode: 'null'}, | |||
|
47 | {name: 'Properties files', mime: 'text/x-properties', mode: 'clike'}, | |||
|
48 | {name: 'Python', mime: 'text/x-python', mode: 'python'}, | |||
|
49 | {name: 'R', mime: 'text/x-rsrc', mode: 'r'}, | |||
|
50 | {name: 'reStructuredText', mime: 'text/x-rst', mode: 'rst'}, | |||
|
51 | {name: 'Ruby', mime: 'text/x-ruby', mode: 'ruby'}, | |||
|
52 | {name: 'Rust', mime: 'text/x-rustsrc', mode: 'rust'}, | |||
|
53 | {name: 'Sass', mime: 'text/x-sass', mode: 'sass'}, | |||
|
54 | {name: 'Scheme', mime: 'text/x-scheme', mode: 'scheme'}, | |||
|
55 | {name: 'SCSS', mime: 'text/x-scss', mode: 'css'}, | |||
|
56 | {name: 'Shell', mime: 'text/x-sh', mode: 'shell'}, | |||
|
57 | {name: 'Sieve', mime: 'application/sieve', mode: 'sieve'}, | |||
|
58 | {name: 'Smalltalk', mime: 'text/x-stsrc', mode: 'smalltalk'}, | |||
|
59 | {name: 'Smarty', mime: 'text/x-smarty', mode: 'smarty'}, | |||
|
60 | {name: 'SPARQL', mime: 'application/x-sparql-query', mode: 'sparql'}, | |||
|
61 | {name: 'SQL', mime: 'text/x-sql', mode: 'sql'}, | |||
|
62 | {name: 'MariaDB', mime: 'text/x-mariadb', mode: 'sql'}, | |||
|
63 | {name: 'sTeX', mime: 'text/x-stex', mode: 'stex'}, | |||
|
64 | {name: 'LaTeX', mime: 'text/x-latex', mode: 'stex'}, | |||
|
65 | {name: 'Tcl', mime: 'text/x-tcl', mode: 'tcl'}, | |||
|
66 | {name: 'TiddlyWiki ', mime: 'text/x-tiddlywiki', mode: 'tiddlywiki'}, | |||
|
67 | {name: 'Tiki wiki', mime: 'text/tiki', mode: 'tiki'}, | |||
|
68 | {name: 'VB.NET', mime: 'text/x-vb', mode: 'vb'}, | |||
|
69 | {name: 'VBScript', mime: 'text/vbscript', mode: 'vbscript'}, | |||
|
70 | {name: 'Velocity', mime: 'text/velocity', mode: 'velocity'}, | |||
|
71 | {name: 'Verilog', mime: 'text/x-verilog', mode: 'verilog'}, | |||
|
72 | {name: 'XML', mime: 'application/xml', mode: 'xml'}, | |||
|
73 | {name: 'HTML', mime: 'text/html', mode: 'xml'}, | |||
|
74 | {name: 'XQuery', mime: 'application/xquery', mode: 'xquery'}, | |||
|
75 | {name: 'YAML', mime: 'text/x-yaml', mode: 'yaml'}, | |||
|
76 | {name: 'Z80', mime: 'text/x-z80', mode: 'z80'} | |||
|
77 | ]; |
@@ -0,0 +1,149 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: mIRC mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="mirc.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../theme/twilight.css"> | |||
|
10 | <style>.CodeMirror {border: 1px solid black;}</style> | |||
|
11 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
12 | </head> | |||
|
13 | <body> | |||
|
14 | <h1>CodeMirror: mIRC mode</h1> | |||
|
15 | <form><textarea id="code" name="code"> | |||
|
16 | ;AKA Nick Tracker by Ford_Lawnmower irc.GeekShed.net #Script-Help | |||
|
17 | ;*****************************************************************************; | |||
|
18 | ;**Start Setup | |||
|
19 | ;Change JoinDisplay, below, for On Join AKA Display. On = 1 - Off = 0 | |||
|
20 | alias -l JoinDisplay { return 1 } | |||
|
21 | ;Change MaxNicks, below, to the number of nicknames you want to store for each hostmask. I wouldn't go over 400 with this ;/ | |||
|
22 | alias -l MaxNicks { return 20 } | |||
|
23 | ;Change AKALogo, below, To the text you want displayed before each AKA result. | |||
|
24 | alias -l AKALogo { return 06 05A06K07A 06 } | |||
|
25 | ;**End Setup | |||
|
26 | ;*****************************************************************************; | |||
|
27 | On *:Join:#: { | |||
|
28 | if ($nick == $me) { .timer 1 1 ialupdateCheck $chan } | |||
|
29 | NickNamesAdd $nick $+($network,$wildsite) | |||
|
30 | if ($JoinDisplay) { .timerNickNames $+ $nick 1 2 NickNames.display $nick $chan $network $wildsite } | |||
|
31 | } | |||
|
32 | on *:Nick: { NickNamesAdd $newnick $+($network,$wildsite) $nick } | |||
|
33 | alias -l NickNames.display { | |||
|
34 | if ($gettok($hget(NickNames,$+($3,$4)),0,126) > 1) { | |||
|
35 | echo -g $2 $AKALogo $+(09,$1) $AKALogo 07 $mid($replace($hget(NickNames,$+($3,$4)),$chr(126),$chr(44)),2,-1) | |||
|
36 | } | |||
|
37 | } | |||
|
38 | alias -l NickNamesAdd { | |||
|
39 | if ($hget(NickNames,$2)) { | |||
|
40 | if (!$regex($hget(NickNames,$2),/~\Q $+ $replacecs($1,\E,\E\\E\Q) $+ \E~/i)) { | |||
|
41 | if ($gettok($hget(NickNames,$2),0,126) <= $MaxNicks) { | |||
|
42 | hadd NickNames $2 $+($hget(NickNames,$2),$1,~) | |||
|
43 | } | |||
|
44 | else { | |||
|
45 | hadd NickNames $2 $+($mid($hget(NickNames,$2),$pos($hget(NickNames,$2),~,2)),$1,~) | |||
|
46 | } | |||
|
47 | } | |||
|
48 | } | |||
|
49 | else { | |||
|
50 | hadd -m NickNames $2 $+(~,$1,~,$iif($3,$+($3,~))) | |||
|
51 | } | |||
|
52 | } | |||
|
53 | alias -l Fix.All.MindUser { | |||
|
54 | var %Fix.Count = $hfind(NickNames,/[^~]+[0-9]{4}~/,0,r).data | |||
|
55 | while (%Fix.Count) { | |||
|
56 | if ($Fix.MindUser($hget(NickNames,$hfind(NickNames,/[^~]+[0-9]{4}~/,%Fix.Count,r).data))) { | |||
|
57 | echo -ag Record %Fix.Count - $v1 - Was Cleaned | |||
|
58 | hadd NickNames $hfind(NickNames,/[^~]+[0-9]{4}~/,%Fix.Count,r).data $v1 | |||
|
59 | } | |||
|
60 | dec %Fix.Count | |||
|
61 | } | |||
|
62 | } | |||
|
63 | alias -l Fix.MindUser { return $regsubex($1,/[^~]+[0-9]{4}~/g,$null) } | |||
|
64 | menu nicklist,query { | |||
|
65 | - | |||
|
66 | .AKA | |||
|
67 | ..Check $$1: { | |||
|
68 | if ($gettok($hget(NickNames,$+($network,$address($1,2))),0,126) > 1) { | |||
|
69 | NickNames.display $1 $active $network $address($1,2) | |||
|
70 | } | |||
|
71 | else { echo -ag $AKALogo $+(09,$1) 07has not been known by any other nicknames while I have been watching. } | |||
|
72 | } | |||
|
73 | ..Cleanup $$1:hadd NickNames $+($network,$address($1,2)) $fix.minduser($hget(NickNames,$+($network,$address($1,2)))) | |||
|
74 | ..Clear $$1:hadd NickNames $+($network,$address($1,2)) $+(~,$1,~) | |||
|
75 | ..AKA Search Dialog:dialog $iif($dialog(AKA_Search),-v,-m) AKA_Search AKA_Search | |||
|
76 | - | |||
|
77 | } | |||
|
78 | menu status,channel { | |||
|
79 | - | |||
|
80 | .AKA | |||
|
81 | ..AKA Search Dialog:dialog $iif($dialog(AKA_Search),-v,-m) AKA_Search AKA_Search | |||
|
82 | ..Clean All Records:Fix.All.Minduser | |||
|
83 | - | |||
|
84 | } | |||
|
85 | dialog AKA_Search { | |||
|
86 | title "AKA Search Engine" | |||
|
87 | size -1 -1 206 221 | |||
|
88 | option dbu | |||
|
89 | edit "", 1, 8 5 149 10, autohs | |||
|
90 | button "Search", 2, 163 4 32 12 | |||
|
91 | radio "Search HostMask", 4, 61 22 55 10 | |||
|
92 | radio "Search Nicknames", 5, 123 22 56 10 | |||
|
93 | list 6, 8 38 190 169, sort extsel vsbar | |||
|
94 | button "Check Selected", 7, 67 206 40 12 | |||
|
95 | button "Close", 8, 160 206 38 12, cancel | |||
|
96 | box "Search Type", 3, 11 17 183 18 | |||
|
97 | button "Copy to Clipboard", 9, 111 206 46 12 | |||
|
98 | } | |||
|
99 | On *:Dialog:Aka_Search:init:*: { did -c $dname 5 } | |||
|
100 | On *:Dialog:Aka_Search:Sclick:2,7,9: { | |||
|
101 | if ($did == 2) && ($did($dname,1)) { | |||
|
102 | did -r $dname 6 | |||
|
103 | var %search $+(*,$v1,*), %type $iif($did($dname,5).state,data,item), %matches = $hfind(NickNames,%search,0,w). [ $+ [ %type ] ] | |||
|
104 | while (%matches) { | |||
|
105 | did -a $dname 6 $hfind(NickNames,%search,%matches,w). [ $+ [ %type ] ] | |||
|
106 | dec %matches | |||
|
107 | } | |||
|
108 | did -c $dname 6 1 | |||
|
109 | } | |||
|
110 | elseif ($did == 7) && ($did($dname,6).seltext) { echo -ga $AKALogo 07 $mid($replace($hget(NickNames,$v1),$chr(126),$chr(44)),2,-1) } | |||
|
111 | elseif ($did == 9) && ($did($dname,6).seltext) { clipboard $mid($v1,$pos($v1,*,1)) } | |||
|
112 | } | |||
|
113 | On *:Start:{ | |||
|
114 | if (!$hget(NickNames)) { hmake NickNames 10 } | |||
|
115 | if ($isfile(NickNames.hsh)) { hload NickNames NickNames.hsh } | |||
|
116 | } | |||
|
117 | On *:Exit: { if ($hget(NickNames)) { hsave NickNames NickNames.hsh } } | |||
|
118 | On *:Disconnect: { if ($hget(NickNames)) { hsave NickNames NickNames.hsh } } | |||
|
119 | On *:Unload: { hfree NickNames } | |||
|
120 | alias -l ialupdateCheck { | |||
|
121 | inc -z $+(%,ialupdateCheck,$network) $calc($nick($1,0) / 4) | |||
|
122 | ;If your ial is already being updated on join .who $1 out. | |||
|
123 | ;If you are using /names to update ial you will still need this line. | |||
|
124 | .who $1 | |||
|
125 | } | |||
|
126 | Raw 352:*: { | |||
|
127 | if ($($+(%,ialupdateCheck,$network),2)) haltdef | |||
|
128 | NickNamesAdd $6 $+($network,$address($6,2)) | |||
|
129 | } | |||
|
130 | Raw 315:*: { | |||
|
131 | if ($($+(%,ialupdateCheck,$network),2)) haltdef | |||
|
132 | } | |||
|
133 | ||||
|
134 | </textarea></form> | |||
|
135 | <script> | |||
|
136 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
137 | tabMode: "indent", | |||
|
138 | theme: "twilight", | |||
|
139 | lineNumbers: true, | |||
|
140 | matchBrackets: true, | |||
|
141 | indentUnit: 4, | |||
|
142 | mode: "text/mirc" | |||
|
143 | }); | |||
|
144 | </script> | |||
|
145 | ||||
|
146 | <p><strong>MIME types defined:</strong> <code>text/mirc</code>.</p> | |||
|
147 | ||||
|
148 | </body> | |||
|
149 | </html> |
@@ -0,0 +1,177 b'' | |||||
|
1 | //mIRC mode by Ford_Lawnmower :: Based on Velocity mode by Steve O'Hara | |||
|
2 | CodeMirror.defineMIME("text/mirc", "mirc"); | |||
|
3 | CodeMirror.defineMode("mirc", function() { | |||
|
4 | function parseWords(str) { | |||
|
5 | var obj = {}, words = str.split(" "); | |||
|
6 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | |||
|
7 | return obj; | |||
|
8 | } | |||
|
9 | var specials = parseWords("$! $$ $& $? $+ $abook $abs $active $activecid " + | |||
|
10 | "$activewid $address $addtok $agent $agentname $agentstat $agentver " + | |||
|
11 | "$alias $and $anick $ansi2mirc $aop $appactive $appstate $asc $asctime " + | |||
|
12 | "$asin $atan $avoice $away $awaymsg $awaytime $banmask $base $bfind " + | |||
|
13 | "$binoff $biton $bnick $bvar $bytes $calc $cb $cd $ceil $chan $chanmodes " + | |||
|
14 | "$chantypes $chat $chr $cid $clevel $click $cmdbox $cmdline $cnick $color " + | |||
|
15 | "$com $comcall $comchan $comerr $compact $compress $comval $cos $count " + | |||
|
16 | "$cr $crc $creq $crlf $ctime $ctimer $ctrlenter $date $day $daylight " + | |||
|
17 | "$dbuh $dbuw $dccignore $dccport $dde $ddename $debug $decode $decompress " + | |||
|
18 | "$deltok $devent $dialog $did $didreg $didtok $didwm $disk $dlevel $dll " + | |||
|
19 | "$dllcall $dname $dns $duration $ebeeps $editbox $emailaddr $encode $error " + | |||
|
20 | "$eval $event $exist $feof $ferr $fgetc $file $filename $filtered $finddir " + | |||
|
21 | "$finddirn $findfile $findfilen $findtok $fline $floor $fopen $fread $fserve " + | |||
|
22 | "$fulladdress $fulldate $fullname $fullscreen $get $getdir $getdot $gettok $gmt " + | |||
|
23 | "$group $halted $hash $height $hfind $hget $highlight $hnick $hotline " + | |||
|
24 | "$hotlinepos $ial $ialchan $ibl $idle $iel $ifmatch $ignore $iif $iil " + | |||
|
25 | "$inelipse $ini $inmidi $inpaste $inpoly $input $inrect $inroundrect " + | |||
|
26 | "$insong $instok $int $inwave $ip $isalias $isbit $isdde $isdir $isfile " + | |||
|
27 | "$isid $islower $istok $isupper $keychar $keyrpt $keyval $knick $lactive " + | |||
|
28 | "$lactivecid $lactivewid $left $len $level $lf $line $lines $link $lock " + | |||
|
29 | "$lock $locked $log $logstamp $logstampfmt $longfn $longip $lower $ltimer " + | |||
|
30 | "$maddress $mask $matchkey $matchtok $md5 $me $menu $menubar $menucontext " + | |||
|
31 | "$menutype $mid $middir $mircdir $mircexe $mircini $mklogfn $mnick $mode " + | |||
|
32 | "$modefirst $modelast $modespl $mouse $msfile $network $newnick $nick $nofile " + | |||
|
33 | "$nopath $noqt $not $notags $notify $null $numeric $numok $oline $onpoly " + | |||
|
34 | "$opnick $or $ord $os $passivedcc $pic $play $pnick $port $portable $portfree " + | |||
|
35 | "$pos $prefix $prop $protect $puttok $qt $query $rand $r $rawmsg $read $readomo " + | |||
|
36 | "$readn $regex $regml $regsub $regsubex $remove $remtok $replace $replacex " + | |||
|
37 | "$reptok $result $rgb $right $round $scid $scon $script $scriptdir $scriptline " + | |||
|
38 | "$sdir $send $server $serverip $sfile $sha1 $shortfn $show $signal $sin " + | |||
|
39 | "$site $sline $snick $snicks $snotify $sock $sockbr $sockerr $sockname " + | |||
|
40 | "$sorttok $sound $sqrt $ssl $sreq $sslready $status $strip $str $stripped " + | |||
|
41 | "$syle $submenu $switchbar $tan $target $ticks $time $timer $timestamp " + | |||
|
42 | "$timestampfmt $timezone $tip $titlebar $toolbar $treebar $trust $ulevel " + | |||
|
43 | "$ulist $upper $uptime $url $usermode $v1 $v2 $var $vcmd $vcmdstat $vcmdver " + | |||
|
44 | "$version $vnick $vol $wid $width $wildsite $wildtok $window $wrap $xor"); | |||
|
45 | var keywords = parseWords("abook ajinvite alias aline ame amsg anick aop auser autojoin avoice " + | |||
|
46 | "away background ban bcopy beep bread break breplace bset btrunc bunset bwrite " + | |||
|
47 | "channel clear clearall cline clipboard close cnick color comclose comopen " + | |||
|
48 | "comreg continue copy creq ctcpreply ctcps dcc dccserver dde ddeserver " + | |||
|
49 | "debug dec describe dialog did didtok disable disconnect dlevel dline dll " + | |||
|
50 | "dns dqwindow drawcopy drawdot drawfill drawline drawpic drawrect drawreplace " + | |||
|
51 | "drawrot drawsave drawscroll drawtext ebeeps echo editbox emailaddr enable " + | |||
|
52 | "events exit fclose filter findtext finger firewall flash flist flood flush " + | |||
|
53 | "flushini font fopen fseek fsend fserve fullname fwrite ghide gload gmove " + | |||
|
54 | "gopts goto gplay gpoint gqreq groups gshow gsize gstop gtalk gunload hadd " + | |||
|
55 | "halt haltdef hdec hdel help hfree hinc hload hmake hop hsave ial ialclear " + | |||
|
56 | "ialmark identd if ignore iline inc invite iuser join kick linesep links list " + | |||
|
57 | "load loadbuf localinfo log mdi me menubar mkdir mnick mode msg nick noop notice " + | |||
|
58 | "notify omsg onotice part partall pdcc perform play playctrl pop protect pvoice " + | |||
|
59 | "qme qmsg query queryn quit raw reload remini remote remove rename renwin " + | |||
|
60 | "reseterror resetidle return rlevel rline rmdir run ruser save savebuf saveini " + | |||
|
61 | "say scid scon server set showmirc signam sline sockaccept sockclose socklist " + | |||
|
62 | "socklisten sockmark sockopen sockpause sockread sockrename sockudp sockwrite " + | |||
|
63 | "sound speak splay sreq strip switchbar timer timestamp titlebar tnick tokenize " + | |||
|
64 | "toolbar topic tray treebar ulist unload unset unsetall updatenl url uwho " + | |||
|
65 | "var vcadd vcmd vcrem vol while whois window winhelp write writeint if isalnum " + | |||
|
66 | "isalpha isaop isavoice isban ischan ishop isignore isin isincs isletter islower " + | |||
|
67 | "isnotify isnum ison isop isprotect isreg isupper isvoice iswm iswmcs " + | |||
|
68 | "elseif else goto menu nicklist status title icon size option text edit " + | |||
|
69 | "button check radio box scroll list combo link tab item"); | |||
|
70 | var functions = parseWords("if elseif else and not or eq ne in ni for foreach while switch"); | |||
|
71 | var isOperatorChar = /[+\-*&%=<>!?^\/\|]/; | |||
|
72 | function chain(stream, state, f) { | |||
|
73 | state.tokenize = f; | |||
|
74 | return f(stream, state); | |||
|
75 | } | |||
|
76 | function tokenBase(stream, state) { | |||
|
77 | var beforeParams = state.beforeParams; | |||
|
78 | state.beforeParams = false; | |||
|
79 | var ch = stream.next(); | |||
|
80 | if (/[\[\]{}\(\),\.]/.test(ch)) { | |||
|
81 | if (ch == "(" && beforeParams) state.inParams = true; | |||
|
82 | else if (ch == ")") state.inParams = false; | |||
|
83 | return null; | |||
|
84 | } | |||
|
85 | else if (/\d/.test(ch)) { | |||
|
86 | stream.eatWhile(/[\w\.]/); | |||
|
87 | return "number"; | |||
|
88 | } | |||
|
89 | else if (ch == "\\") { | |||
|
90 | stream.eat("\\"); | |||
|
91 | stream.eat(/./); | |||
|
92 | return "number"; | |||
|
93 | } | |||
|
94 | else if (ch == "/" && stream.eat("*")) { | |||
|
95 | return chain(stream, state, tokenComment); | |||
|
96 | } | |||
|
97 | else if (ch == ";" && stream.match(/ *\( *\(/)) { | |||
|
98 | return chain(stream, state, tokenUnparsed); | |||
|
99 | } | |||
|
100 | else if (ch == ";" && !state.inParams) { | |||
|
101 | stream.skipToEnd(); | |||
|
102 | return "comment"; | |||
|
103 | } | |||
|
104 | else if (ch == '"') { | |||
|
105 | stream.eat(/"/); | |||
|
106 | return "keyword"; | |||
|
107 | } | |||
|
108 | else if (ch == "$") { | |||
|
109 | stream.eatWhile(/[$_a-z0-9A-Z\.:]/); | |||
|
110 | if (specials && specials.propertyIsEnumerable(stream.current().toLowerCase())) { | |||
|
111 | return "keyword"; | |||
|
112 | } | |||
|
113 | else { | |||
|
114 | state.beforeParams = true; | |||
|
115 | return "builtin"; | |||
|
116 | } | |||
|
117 | } | |||
|
118 | else if (ch == "%") { | |||
|
119 | stream.eatWhile(/[^,^\s^\(^\)]/); | |||
|
120 | state.beforeParams = true; | |||
|
121 | return "string"; | |||
|
122 | } | |||
|
123 | else if (isOperatorChar.test(ch)) { | |||
|
124 | stream.eatWhile(isOperatorChar); | |||
|
125 | return "operator"; | |||
|
126 | } | |||
|
127 | else { | |||
|
128 | stream.eatWhile(/[\w\$_{}]/); | |||
|
129 | var word = stream.current().toLowerCase(); | |||
|
130 | if (keywords && keywords.propertyIsEnumerable(word)) | |||
|
131 | return "keyword"; | |||
|
132 | if (functions && functions.propertyIsEnumerable(word)) { | |||
|
133 | state.beforeParams = true; | |||
|
134 | return "keyword"; | |||
|
135 | } | |||
|
136 | return null; | |||
|
137 | } | |||
|
138 | } | |||
|
139 | function tokenComment(stream, state) { | |||
|
140 | var maybeEnd = false, ch; | |||
|
141 | while (ch = stream.next()) { | |||
|
142 | if (ch == "/" && maybeEnd) { | |||
|
143 | state.tokenize = tokenBase; | |||
|
144 | break; | |||
|
145 | } | |||
|
146 | maybeEnd = (ch == "*"); | |||
|
147 | } | |||
|
148 | return "comment"; | |||
|
149 | } | |||
|
150 | function tokenUnparsed(stream, state) { | |||
|
151 | var maybeEnd = 0, ch; | |||
|
152 | while (ch = stream.next()) { | |||
|
153 | if (ch == ";" && maybeEnd == 2) { | |||
|
154 | state.tokenize = tokenBase; | |||
|
155 | break; | |||
|
156 | } | |||
|
157 | if (ch == ")") | |||
|
158 | maybeEnd++; | |||
|
159 | else if (ch != " ") | |||
|
160 | maybeEnd = 0; | |||
|
161 | } | |||
|
162 | return "meta"; | |||
|
163 | } | |||
|
164 | return { | |||
|
165 | startState: function() { | |||
|
166 | return { | |||
|
167 | tokenize: tokenBase, | |||
|
168 | beforeParams: false, | |||
|
169 | inParams: false | |||
|
170 | }; | |||
|
171 | }, | |||
|
172 | token: function(stream, state) { | |||
|
173 | if (stream.eatSpace()) return null; | |||
|
174 | return state.tokenize(stream, state); | |||
|
175 | } | |||
|
176 | }; | |||
|
177 | }); |
@@ -0,0 +1,33 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: NTriples mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="ntriples.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style type="text/css"> | |||
|
11 | .CodeMirror { | |||
|
12 | border: 1px solid #eee; | |||
|
13 | } | |||
|
14 | </style> | |||
|
15 | </head> | |||
|
16 | <body> | |||
|
17 | <h1>CodeMirror: NTriples mode</h1> | |||
|
18 | <form> | |||
|
19 | <textarea id="ntriples" name="ntriples"> | |||
|
20 | <http://Sub1> <http://pred1> <http://obj> . | |||
|
21 | <http://Sub2> <http://pred2#an2> "literal 1" . | |||
|
22 | <http://Sub3#an3> <http://pred3> _:bnode3 . | |||
|
23 | _:bnode4 <http://pred4> "literal 2"@lang . | |||
|
24 | _:bnode5 <http://pred5> "literal 3"^^<http://type> . | |||
|
25 | </textarea> | |||
|
26 | </form> | |||
|
27 | ||||
|
28 | <script> | |||
|
29 | var editor = CodeMirror.fromTextArea(document.getElementById("ntriples"), {}); | |||
|
30 | </script> | |||
|
31 | <p><strong>MIME types defined:</strong> <code>text/n-triples</code>.</p> | |||
|
32 | </body> | |||
|
33 | </html> |
@@ -0,0 +1,170 b'' | |||||
|
1 | /********************************************************** | |||
|
2 | * This script provides syntax highlighting support for | |||
|
3 | * the Ntriples format. | |||
|
4 | * Ntriples format specification: | |||
|
5 | * http://www.w3.org/TR/rdf-testcases/#ntriples | |||
|
6 | ***********************************************************/ | |||
|
7 | ||||
|
8 | /* | |||
|
9 | The following expression defines the defined ASF grammar transitions. | |||
|
10 | ||||
|
11 | pre_subject -> | |||
|
12 | { | |||
|
13 | ( writing_subject_uri | writing_bnode_uri ) | |||
|
14 | -> pre_predicate | |||
|
15 | -> writing_predicate_uri | |||
|
16 | -> pre_object | |||
|
17 | -> writing_object_uri | writing_object_bnode | | |||
|
18 | ( | |||
|
19 | writing_object_literal | |||
|
20 | -> writing_literal_lang | writing_literal_type | |||
|
21 | ) | |||
|
22 | -> post_object | |||
|
23 | -> BEGIN | |||
|
24 | } otherwise { | |||
|
25 | -> ERROR | |||
|
26 | } | |||
|
27 | */ | |||
|
28 | CodeMirror.defineMode("ntriples", function() { | |||
|
29 | ||||
|
30 | var Location = { | |||
|
31 | PRE_SUBJECT : 0, | |||
|
32 | WRITING_SUB_URI : 1, | |||
|
33 | WRITING_BNODE_URI : 2, | |||
|
34 | PRE_PRED : 3, | |||
|
35 | WRITING_PRED_URI : 4, | |||
|
36 | PRE_OBJ : 5, | |||
|
37 | WRITING_OBJ_URI : 6, | |||
|
38 | WRITING_OBJ_BNODE : 7, | |||
|
39 | WRITING_OBJ_LITERAL : 8, | |||
|
40 | WRITING_LIT_LANG : 9, | |||
|
41 | WRITING_LIT_TYPE : 10, | |||
|
42 | POST_OBJ : 11, | |||
|
43 | ERROR : 12 | |||
|
44 | }; | |||
|
45 | function transitState(currState, c) { | |||
|
46 | var currLocation = currState.location; | |||
|
47 | var ret; | |||
|
48 | ||||
|
49 | // Opening. | |||
|
50 | if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI; | |||
|
51 | else if(currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI; | |||
|
52 | else if(currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI; | |||
|
53 | else if(currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI; | |||
|
54 | else if(currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE; | |||
|
55 | else if(currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL; | |||
|
56 | ||||
|
57 | // Closing. | |||
|
58 | else if(currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED; | |||
|
59 | else if(currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED; | |||
|
60 | else if(currLocation == Location.WRITING_PRED_URI && c == '>') ret = Location.PRE_OBJ; | |||
|
61 | else if(currLocation == Location.WRITING_OBJ_URI && c == '>') ret = Location.POST_OBJ; | |||
|
62 | else if(currLocation == Location.WRITING_OBJ_BNODE && c == ' ') ret = Location.POST_OBJ; | |||
|
63 | else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ; | |||
|
64 | else if(currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ; | |||
|
65 | else if(currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ; | |||
|
66 | ||||
|
67 | // Closing typed and language literal. | |||
|
68 | else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG; | |||
|
69 | else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE; | |||
|
70 | ||||
|
71 | // Spaces. | |||
|
72 | else if( c == ' ' && | |||
|
73 | ( | |||
|
74 | currLocation == Location.PRE_SUBJECT || | |||
|
75 | currLocation == Location.PRE_PRED || | |||
|
76 | currLocation == Location.PRE_OBJ || | |||
|
77 | currLocation == Location.POST_OBJ | |||
|
78 | ) | |||
|
79 | ) ret = currLocation; | |||
|
80 | ||||
|
81 | // Reset. | |||
|
82 | else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT; | |||
|
83 | ||||
|
84 | // Error | |||
|
85 | else ret = Location.ERROR; | |||
|
86 | ||||
|
87 | currState.location=ret; | |||
|
88 | } | |||
|
89 | ||||
|
90 | return { | |||
|
91 | startState: function() { | |||
|
92 | return { | |||
|
93 | location : Location.PRE_SUBJECT, | |||
|
94 | uris : [], | |||
|
95 | anchors : [], | |||
|
96 | bnodes : [], | |||
|
97 | langs : [], | |||
|
98 | types : [] | |||
|
99 | }; | |||
|
100 | }, | |||
|
101 | token: function(stream, state) { | |||
|
102 | var ch = stream.next(); | |||
|
103 | if(ch == '<') { | |||
|
104 | transitState(state, ch); | |||
|
105 | var parsedURI = ''; | |||
|
106 | stream.eatWhile( function(c) { if( c != '#' && c != '>' ) { parsedURI += c; return true; } return false;} ); | |||
|
107 | state.uris.push(parsedURI); | |||
|
108 | if( stream.match('#', false) ) return 'variable'; | |||
|
109 | stream.next(); | |||
|
110 | transitState(state, '>'); | |||
|
111 | return 'variable'; | |||
|
112 | } | |||
|
113 | if(ch == '#') { | |||
|
114 | var parsedAnchor = ''; | |||
|
115 | stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false;}); | |||
|
116 | state.anchors.push(parsedAnchor); | |||
|
117 | return 'variable-2'; | |||
|
118 | } | |||
|
119 | if(ch == '>') { | |||
|
120 | transitState(state, '>'); | |||
|
121 | return 'variable'; | |||
|
122 | } | |||
|
123 | if(ch == '_') { | |||
|
124 | transitState(state, ch); | |||
|
125 | var parsedBNode = ''; | |||
|
126 | stream.eatWhile(function(c) { if( c != ' ' ) { parsedBNode += c; return true; } return false;}); | |||
|
127 | state.bnodes.push(parsedBNode); | |||
|
128 | stream.next(); | |||
|
129 | transitState(state, ' '); | |||
|
130 | return 'builtin'; | |||
|
131 | } | |||
|
132 | if(ch == '"') { | |||
|
133 | transitState(state, ch); | |||
|
134 | stream.eatWhile( function(c) { return c != '"'; } ); | |||
|
135 | stream.next(); | |||
|
136 | if( stream.peek() != '@' && stream.peek() != '^' ) { | |||
|
137 | transitState(state, '"'); | |||
|
138 | } | |||
|
139 | return 'string'; | |||
|
140 | } | |||
|
141 | if( ch == '@' ) { | |||
|
142 | transitState(state, '@'); | |||
|
143 | var parsedLang = ''; | |||
|
144 | stream.eatWhile(function(c) { if( c != ' ' ) { parsedLang += c; return true; } return false;}); | |||
|
145 | state.langs.push(parsedLang); | |||
|
146 | stream.next(); | |||
|
147 | transitState(state, ' '); | |||
|
148 | return 'string-2'; | |||
|
149 | } | |||
|
150 | if( ch == '^' ) { | |||
|
151 | stream.next(); | |||
|
152 | transitState(state, '^'); | |||
|
153 | var parsedType = ''; | |||
|
154 | stream.eatWhile(function(c) { if( c != '>' ) { parsedType += c; return true; } return false;} ); | |||
|
155 | state.types.push(parsedType); | |||
|
156 | stream.next(); | |||
|
157 | transitState(state, '>'); | |||
|
158 | return 'variable'; | |||
|
159 | } | |||
|
160 | if( ch == ' ' ) { | |||
|
161 | transitState(state, ch); | |||
|
162 | } | |||
|
163 | if( ch == '.' ) { | |||
|
164 | transitState(state, ch); | |||
|
165 | } | |||
|
166 | } | |||
|
167 | }; | |||
|
168 | }); | |||
|
169 | ||||
|
170 | CodeMirror.defineMIME("text/n-triples", "ntriples"); |
@@ -0,0 +1,131 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <meta charset=utf-8> | |||
|
3 | <title>CodeMirror: OCaml mode</title> | |||
|
4 | ||||
|
5 | <link rel=stylesheet href=../../lib/codemirror.css> | |||
|
6 | <link rel=stylesheet href=../../doc/docs.css> | |||
|
7 | ||||
|
8 | <style type=text/css> | |||
|
9 | .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} | |||
|
10 | </style> | |||
|
11 | ||||
|
12 | <script src=../../lib/codemirror.js></script> | |||
|
13 | <script src=../../addon/edit/matchbrackets.js></script> | |||
|
14 | <script src=ocaml.js></script> | |||
|
15 | ||||
|
16 | <h1>CodeMirror: OCaml mode</h1> | |||
|
17 | ||||
|
18 | <textarea id=code> | |||
|
19 | (* Summing a list of integers *) | |||
|
20 | let rec sum xs = | |||
|
21 | match xs with | |||
|
22 | | [] -> 0 | |||
|
23 | | x :: xs' -> x + sum xs' | |||
|
24 | ||||
|
25 | (* Quicksort *) | |||
|
26 | let rec qsort = function | |||
|
27 | | [] -> [] | |||
|
28 | | pivot :: rest -> | |||
|
29 | let is_less x = x < pivot in | |||
|
30 | let left, right = List.partition is_less rest in | |||
|
31 | qsort left @ [pivot] @ qsort right | |||
|
32 | ||||
|
33 | (* Fibonacci Sequence *) | |||
|
34 | let rec fib_aux n a b = | |||
|
35 | match n with | |||
|
36 | | 0 -> a | |||
|
37 | | _ -> fib_aux (n - 1) (a + b) a | |||
|
38 | let fib n = fib_aux n 0 1 | |||
|
39 | ||||
|
40 | (* Birthday paradox *) | |||
|
41 | let year_size = 365. | |||
|
42 | ||||
|
43 | let rec birthday_paradox prob people = | |||
|
44 | let prob' = (year_size -. float people) /. year_size *. prob in | |||
|
45 | if prob' < 0.5 then | |||
|
46 | Printf.printf "answer = %d\n" (people+1) | |||
|
47 | else | |||
|
48 | birthday_paradox prob' (people+1) ;; | |||
|
49 | ||||
|
50 | birthday_paradox 1.0 1 | |||
|
51 | ||||
|
52 | (* Church numerals *) | |||
|
53 | let zero f x = x | |||
|
54 | let succ n f x = f (n f x) | |||
|
55 | let one = succ zero | |||
|
56 | let two = succ (succ zero) | |||
|
57 | let add n1 n2 f x = n1 f (n2 f x) | |||
|
58 | let to_string n = n (fun k -> "S" ^ k) "0" | |||
|
59 | let _ = to_string (add (succ two) two) | |||
|
60 | ||||
|
61 | (* Elementary functions *) | |||
|
62 | let square x = x * x;; | |||
|
63 | let rec fact x = | |||
|
64 | if x <= 1 then 1 else x * fact (x - 1);; | |||
|
65 | ||||
|
66 | (* Automatic memory management *) | |||
|
67 | let l = 1 :: 2 :: 3 :: [];; | |||
|
68 | [1; 2; 3];; | |||
|
69 | 5 :: l;; | |||
|
70 | ||||
|
71 | (* Polymorphism: sorting lists *) | |||
|
72 | let rec sort = function | |||
|
73 | | [] -> [] | |||
|
74 | | x :: l -> insert x (sort l) | |||
|
75 | ||||
|
76 | and insert elem = function | |||
|
77 | | [] -> [elem] | |||
|
78 | | x :: l -> | |||
|
79 | if elem < x then elem :: x :: l else x :: insert elem l;; | |||
|
80 | ||||
|
81 | (* Imperative features *) | |||
|
82 | let add_polynom p1 p2 = | |||
|
83 | let n1 = Array.length p1 | |||
|
84 | and n2 = Array.length p2 in | |||
|
85 | let result = Array.create (max n1 n2) 0 in | |||
|
86 | for i = 0 to n1 - 1 do result.(i) <- p1.(i) done; | |||
|
87 | for i = 0 to n2 - 1 do result.(i) <- result.(i) + p2.(i) done; | |||
|
88 | result;; | |||
|
89 | add_polynom [| 1; 2 |] [| 1; 2; 3 |];; | |||
|
90 | ||||
|
91 | (* We may redefine fact using a reference cell and a for loop *) | |||
|
92 | let fact n = | |||
|
93 | let result = ref 1 in | |||
|
94 | for i = 2 to n do | |||
|
95 | result := i * !result | |||
|
96 | done; | |||
|
97 | !result;; | |||
|
98 | fact 5;; | |||
|
99 | ||||
|
100 | (* Triangle (graphics) *) | |||
|
101 | let () = | |||
|
102 | ignore( Glut.init Sys.argv ); | |||
|
103 | Glut.initDisplayMode ~double_buffer:true (); | |||
|
104 | ignore (Glut.createWindow ~title:"OpenGL Demo"); | |||
|
105 | let angle t = 10. *. t *. t in | |||
|
106 | let render () = | |||
|
107 | GlClear.clear [ `color ]; | |||
|
108 | GlMat.load_identity (); | |||
|
109 | GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. (); | |||
|
110 | GlDraw.begins `triangles; | |||
|
111 | List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.]; | |||
|
112 | GlDraw.ends (); | |||
|
113 | Glut.swapBuffers () in | |||
|
114 | GlMat.mode `modelview; | |||
|
115 | Glut.displayFunc ~cb:render; | |||
|
116 | Glut.idleFunc ~cb:(Some Glut.postRedisplay); | |||
|
117 | Glut.mainLoop () | |||
|
118 | ||||
|
119 | (* A Hundred Lines of Caml - http://caml.inria.fr/about/taste.en.html *) | |||
|
120 | (* OCaml page on Wikipedia - http://en.wikipedia.org/wiki/OCaml *) | |||
|
121 | </textarea> | |||
|
122 | ||||
|
123 | <script> | |||
|
124 | var editor = CodeMirror.fromTextArea(document.getElementById('code'), { | |||
|
125 | mode: 'ocaml', | |||
|
126 | lineNumbers: true, | |||
|
127 | matchBrackets: true | |||
|
128 | }); | |||
|
129 | </script> | |||
|
130 | ||||
|
131 | <p><strong>MIME types defined:</strong> <code>text/x-ocaml</code>.</p> |
@@ -0,0 +1,116 b'' | |||||
|
1 | CodeMirror.defineMode('ocaml', function() { | |||
|
2 | ||||
|
3 | var words = { | |||
|
4 | 'true': 'atom', | |||
|
5 | 'false': 'atom', | |||
|
6 | 'let': 'keyword', | |||
|
7 | 'rec': 'keyword', | |||
|
8 | 'in': 'keyword', | |||
|
9 | 'of': 'keyword', | |||
|
10 | 'and': 'keyword', | |||
|
11 | 'succ': 'keyword', | |||
|
12 | 'if': 'keyword', | |||
|
13 | 'then': 'keyword', | |||
|
14 | 'else': 'keyword', | |||
|
15 | 'for': 'keyword', | |||
|
16 | 'to': 'keyword', | |||
|
17 | 'while': 'keyword', | |||
|
18 | 'do': 'keyword', | |||
|
19 | 'done': 'keyword', | |||
|
20 | 'fun': 'keyword', | |||
|
21 | 'function': 'keyword', | |||
|
22 | 'val': 'keyword', | |||
|
23 | 'type': 'keyword', | |||
|
24 | 'mutable': 'keyword', | |||
|
25 | 'match': 'keyword', | |||
|
26 | 'with': 'keyword', | |||
|
27 | 'try': 'keyword', | |||
|
28 | 'raise': 'keyword', | |||
|
29 | 'begin': 'keyword', | |||
|
30 | 'end': 'keyword', | |||
|
31 | 'open': 'builtin', | |||
|
32 | 'trace': 'builtin', | |||
|
33 | 'ignore': 'builtin', | |||
|
34 | 'exit': 'builtin', | |||
|
35 | 'print_string': 'builtin', | |||
|
36 | 'print_endline': 'builtin' | |||
|
37 | }; | |||
|
38 | ||||
|
39 | function tokenBase(stream, state) { | |||
|
40 | var ch = stream.next(); | |||
|
41 | ||||
|
42 | if (ch === '"') { | |||
|
43 | state.tokenize = tokenString; | |||
|
44 | return state.tokenize(stream, state); | |||
|
45 | } | |||
|
46 | if (ch === '(') { | |||
|
47 | if (stream.eat('*')) { | |||
|
48 | state.commentLevel++; | |||
|
49 | state.tokenize = tokenComment; | |||
|
50 | return state.tokenize(stream, state); | |||
|
51 | } | |||
|
52 | } | |||
|
53 | if (ch === '~') { | |||
|
54 | stream.eatWhile(/\w/); | |||
|
55 | return 'variable-2'; | |||
|
56 | } | |||
|
57 | if (ch === '`') { | |||
|
58 | stream.eatWhile(/\w/); | |||
|
59 | return 'quote'; | |||
|
60 | } | |||
|
61 | if (/\d/.test(ch)) { | |||
|
62 | stream.eatWhile(/[\d]/); | |||
|
63 | if (stream.eat('.')) { | |||
|
64 | stream.eatWhile(/[\d]/); | |||
|
65 | } | |||
|
66 | return 'number'; | |||
|
67 | } | |||
|
68 | if ( /[+\-*&%=<>!?|]/.test(ch)) { | |||
|
69 | return 'operator'; | |||
|
70 | } | |||
|
71 | stream.eatWhile(/\w/); | |||
|
72 | var cur = stream.current(); | |||
|
73 | return words[cur] || 'variable'; | |||
|
74 | } | |||
|
75 | ||||
|
76 | function tokenString(stream, state) { | |||
|
77 | var next, end = false, escaped = false; | |||
|
78 | while ((next = stream.next()) != null) { | |||
|
79 | if (next === '"' && !escaped) { | |||
|
80 | end = true; | |||
|
81 | break; | |||
|
82 | } | |||
|
83 | escaped = !escaped && next === '\\'; | |||
|
84 | } | |||
|
85 | if (end && !escaped) { | |||
|
86 | state.tokenize = tokenBase; | |||
|
87 | } | |||
|
88 | return 'string'; | |||
|
89 | }; | |||
|
90 | ||||
|
91 | function tokenComment(stream, state) { | |||
|
92 | var prev, next; | |||
|
93 | while(state.commentLevel > 0 && (next = stream.next()) != null) { | |||
|
94 | if (prev === '(' && next === '*') state.commentLevel++; | |||
|
95 | if (prev === '*' && next === ')') state.commentLevel--; | |||
|
96 | prev = next; | |||
|
97 | } | |||
|
98 | if (state.commentLevel <= 0) { | |||
|
99 | state.tokenize = tokenBase; | |||
|
100 | } | |||
|
101 | return 'comment'; | |||
|
102 | } | |||
|
103 | ||||
|
104 | return { | |||
|
105 | startState: function() {return {tokenize: tokenBase, commentLevel: 0};}, | |||
|
106 | token: function(stream, state) { | |||
|
107 | if (stream.eatSpace()) return null; | |||
|
108 | return state.tokenize(stream, state); | |||
|
109 | }, | |||
|
110 | ||||
|
111 | blockCommentStart: "(*", | |||
|
112 | blockCommentEnd: "*)" | |||
|
113 | }; | |||
|
114 | }); | |||
|
115 | ||||
|
116 | CodeMirror.defineMIME('text/x-ocaml', 'ocaml'); |
@@ -0,0 +1,7 b'' | |||||
|
1 | Copyright (c) 2011 souceLair <support@sourcelair.com> | |||
|
2 | ||||
|
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
|
4 | ||||
|
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |||
|
6 | ||||
|
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -0,0 +1,48 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Pascal mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="pascal.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Pascal mode</h1> | |||
|
14 | ||||
|
15 | <div><textarea id="code" name="code"> | |||
|
16 | (* Example Pascal code *) | |||
|
17 | ||||
|
18 | while a <> b do writeln('Waiting'); | |||
|
19 | ||||
|
20 | if a > b then | |||
|
21 | writeln('Condition met') | |||
|
22 | else | |||
|
23 | writeln('Condition not met'); | |||
|
24 | ||||
|
25 | for i := 1 to 10 do | |||
|
26 | writeln('Iteration: ', i:1); | |||
|
27 | ||||
|
28 | repeat | |||
|
29 | a := a + 1 | |||
|
30 | until a = 10; | |||
|
31 | ||||
|
32 | case i of | |||
|
33 | 0: write('zero'); | |||
|
34 | 1: write('one'); | |||
|
35 | 2: write('two') | |||
|
36 | end; | |||
|
37 | </textarea></div> | |||
|
38 | ||||
|
39 | <script> | |||
|
40 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
41 | lineNumbers: true, | |||
|
42 | mode: "text/x-pascal" | |||
|
43 | }); | |||
|
44 | </script> | |||
|
45 | ||||
|
46 | <p><strong>MIME types defined:</strong> <code>text/x-pascal</code>.</p> | |||
|
47 | </body> | |||
|
48 | </html> |
@@ -0,0 +1,94 b'' | |||||
|
1 | CodeMirror.defineMode("pascal", function() { | |||
|
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 atoms = {"null": true}; | |||
|
11 | ||||
|
12 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | |||
|
13 | ||||
|
14 | function tokenBase(stream, state) { | |||
|
15 | var ch = stream.next(); | |||
|
16 | if (ch == "#" && state.startOfLine) { | |||
|
17 | stream.skipToEnd(); | |||
|
18 | return "meta"; | |||
|
19 | } | |||
|
20 | if (ch == '"' || ch == "'") { | |||
|
21 | state.tokenize = tokenString(ch); | |||
|
22 | return state.tokenize(stream, state); | |||
|
23 | } | |||
|
24 | if (ch == "(" && stream.eat("*")) { | |||
|
25 | state.tokenize = tokenComment; | |||
|
26 | return tokenComment(stream, state); | |||
|
27 | } | |||
|
28 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |||
|
29 | return null; | |||
|
30 | } | |||
|
31 | if (/\d/.test(ch)) { | |||
|
32 | stream.eatWhile(/[\w\.]/); | |||
|
33 | return "number"; | |||
|
34 | } | |||
|
35 | if (ch == "/") { | |||
|
36 | if (stream.eat("/")) { | |||
|
37 | stream.skipToEnd(); | |||
|
38 | return "comment"; | |||
|
39 | } | |||
|
40 | } | |||
|
41 | if (isOperatorChar.test(ch)) { | |||
|
42 | stream.eatWhile(isOperatorChar); | |||
|
43 | return "operator"; | |||
|
44 | } | |||
|
45 | stream.eatWhile(/[\w\$_]/); | |||
|
46 | var cur = stream.current(); | |||
|
47 | if (keywords.propertyIsEnumerable(cur)) return "keyword"; | |||
|
48 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | |||
|
49 | return "variable"; | |||
|
50 | } | |||
|
51 | ||||
|
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 == "\\"; | |||
|
58 | } | |||
|
59 | if (end || !escaped) state.tokenize = null; | |||
|
60 | return "string"; | |||
|
61 | }; | |||
|
62 | } | |||
|
63 | ||||
|
64 | function tokenComment(stream, state) { | |||
|
65 | var maybeEnd = false, ch; | |||
|
66 | while (ch = stream.next()) { | |||
|
67 | if (ch == ")" && maybeEnd) { | |||
|
68 | state.tokenize = null; | |||
|
69 | break; | |||
|
70 | } | |||
|
71 | maybeEnd = (ch == "*"); | |||
|
72 | } | |||
|
73 | return "comment"; | |||
|
74 | } | |||
|
75 | ||||
|
76 | // Interface | |||
|
77 | ||||
|
78 | return { | |||
|
79 | startState: function() { | |||
|
80 | return {tokenize: null}; | |||
|
81 | }, | |||
|
82 | ||||
|
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; | |||
|
87 | return style; | |||
|
88 | }, | |||
|
89 | ||||
|
90 | electricChars: "{}" | |||
|
91 | }; | |||
|
92 | }); | |||
|
93 | ||||
|
94 | CodeMirror.defineMIME("text/x-pascal", "pascal"); |
@@ -0,0 +1,19 b'' | |||||
|
1 | Copyright (C) 2011 by Sabaca <mail@sabaca.com> under the MIT license. | |||
|
2 | ||||
|
3 | Permission is hereby granted, free of charge, to any person obtaining a copy | |||
|
4 | of this software and associated documentation files (the "Software"), to deal | |||
|
5 | in the Software without restriction, including without limitation the rights | |||
|
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
|
7 | copies of the Software, and to permit persons to whom the Software is | |||
|
8 | furnished to do so, subject to the following conditions: | |||
|
9 | ||||
|
10 | The above copyright notice and this permission notice shall be included in | |||
|
11 | all copies or substantial portions of the Software. | |||
|
12 | ||||
|
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
|
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
|
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
|
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
|
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
|
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
|
19 | THE SOFTWARE. |
@@ -0,0 +1,62 b'' | |||||
|
1 | <!doctype html> | |||
|
2 | <html> | |||
|
3 | <head> | |||
|
4 | <meta charset="utf-8"> | |||
|
5 | <title>CodeMirror: Perl mode</title> | |||
|
6 | <link rel="stylesheet" href="../../lib/codemirror.css"> | |||
|
7 | <script src="../../lib/codemirror.js"></script> | |||
|
8 | <script src="perl.js"></script> | |||
|
9 | <link rel="stylesheet" href="../../doc/docs.css"> | |||
|
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |||
|
11 | </head> | |||
|
12 | <body> | |||
|
13 | <h1>CodeMirror: Perl mode</h1> | |||
|
14 | ||||
|
15 | <div><textarea id="code" name="code"> | |||
|
16 | #!/usr/bin/perl | |||
|
17 | ||||
|
18 | use Something qw(func1 func2); | |||
|
19 | ||||
|
20 | # strings | |||
|
21 | my $s1 = qq'single line'; | |||
|
22 | our $s2 = q(multi- | |||
|
23 | line); | |||
|
24 | ||||
|
25 | =item Something | |||
|
26 | Example. | |||
|
27 | =cut | |||
|
28 | ||||
|
29 | my $html=<<'HTML' | |||
|
30 | <html> | |||
|
31 | <title>hi!</title> | |||
|
32 | </html> | |||
|
33 | HTML | |||
|
34 | ||||
|
35 | print "first,".join(',', 'second', qq~third~); | |||
|
36 | ||||
|
37 | if($s1 =~ m[(?<!\s)(l.ne)\z]o) { | |||
|
38 | $h->{$1}=$$.' predefined variables'; | |||
|
39 | $s2 =~ s/\-line//ox; | |||
|
40 | $s1 =~ s[ | |||
|
41 | line ] | |||
|
42 | [ | |||
|
43 | block | |||
|
44 | ]ox; | |||
|
45 | } | |||
|
46 | ||||
|
47 | 1; # numbers and comments | |||
|
48 | ||||
|
49 | __END__ | |||
|
50 | something... | |||
|
51 | ||||
|
52 | </textarea></div> | |||
|
53 | ||||
|
54 | <script> | |||
|
55 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |||
|
56 | lineNumbers: true | |||
|
57 | }); | |||
|
58 | </script> | |||
|
59 | ||||
|
60 | <p><strong>MIME types defined:</strong> <code>text/x-perl</code>.</p> | |||
|
61 | </body> | |||
|
62 | </html> |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now