| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: Range Collapsing Demo</title> | ||
| <link rel="stylesheet" href="../lib/codemirror.css"> | ||
| <script src="../lib/codemirror.js"></script> | ||
| <script src="../addon/fold/collapserange.js"></script> | ||
| <script src="../mode/javascript/javascript.js"></script> | ||
| <link rel="stylesheet" href="../doc/docs.css"> | ||
|
|
||
| <style type="text/css"> | ||
| .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} | ||
| .CodeMirror-collapserange { width: .6em; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: Range Collapsing Demo</h1> | ||
|
|
||
| <form><textarea id="code" name="code">(function() { | ||
| CodeMirror.defineOption("collapseRange", false, function(cm, val, old) { | ||
| var wasOn = old && old != CodeMirror.Init; | ||
| if (val && !wasOn) | ||
| enableRangeCollapsing(cm); | ||
| else if (!val && wasOn) | ||
| disableRangeCollapsing(cm); | ||
| }); | ||
|
|
||
| var gutterClass = "CodeMirror-collapserange"; | ||
|
|
||
| function enableRangeCollapsing(cm) { | ||
| cm.on("gutterClick", gutterClick); | ||
| cm.setOption("gutters", (cm.getOption("gutters") || []).concat([gutterClass])); | ||
| } | ||
|
|
||
| function disableRangeCollapsing(cm) { | ||
| cm.rangeCollapseStart = null; | ||
| cm.off("gutterClick", gutterClick); | ||
| var gutters = cm.getOption("gutters"); | ||
| for (var i = 0; i < gutters.length && gutters[i] != gutterClass; ++i) {} | ||
| cm.setOption("gutters", gutters.slice(0, i).concat(gutters.slice(i + 1))); | ||
| } | ||
|
|
||
| function gutterClick(cm, line, gutter) { | ||
| if (gutter != gutterClass) return; | ||
|
|
||
| var start = cm.rangeCollapseStart; | ||
| if (start) { | ||
| var old = cm.getLineNumber(start); | ||
| cm.setGutterMarker(start, gutterClass, null); | ||
| cm.rangeCollapseStart = null; | ||
| var from = Math.min(old, line), to = Math.max(old, line); | ||
| if (from != to) { | ||
| // Finish this fold | ||
| var fold = cm.markText({line: from + 1, ch: 0}, {line: to - 1}, { | ||
| collapsed: true, | ||
| inclusiveLeft: true, | ||
| inclusiveRight: true, | ||
| clearOnEnter: true | ||
| }); | ||
| var topLine = cm.setGutterMarker(from, gutterClass, makeMarker(true, true, clear)); | ||
| var botLine = cm.setGutterMarker(to, gutterClass, makeMarker(false, true, clear)); | ||
| CodeMirror.on(fold, "clear", clear); | ||
|
|
||
| function clear() { | ||
| cm.setGutterMarker(topLine, gutterClass, null); | ||
| cm.setGutterMarker(botLine, gutterClass, null); | ||
| fold.clear(); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Start a new fold | ||
| cm.rangeCollapseStart = cm.setGutterMarker(line, gutterClass, makeMarker(true, false)); | ||
| } | ||
|
|
||
| function makeMarker(isTop, isFinished, handler) { | ||
| var node = document.createElement("div"); | ||
| node.innerHTML = isTop ? "\u25bc" : "\u25b2"; | ||
| if (!isFinished) node.style.color = "red"; | ||
| node.style.fontSize = "85%"; | ||
| node.style.cursor = "pointer"; | ||
| if (handler) CodeMirror.on(node, "mousedown", handler); | ||
| return node; | ||
| } | ||
| })(); | ||
| </textarea></form> | ||
|
|
||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| collapseRange: true, | ||
| mode: "javascript" | ||
| }); | ||
| </script> | ||
|
|
||
| <p>Click on the right side of the gutter, then click again below, | ||
| the code between will collapse. Click on either arrow to expand. | ||
| To use, simply include the collapserange.js file and | ||
| set <code>collapseRange: true</code> in options. </p> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"/> | ||
| <title>CodeMirror: Mode list</title> | ||
| <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/> | ||
| <link rel="stylesheet" type="text/css" href="docs.css"/> | ||
| </head> | ||
| <body> | ||
|
|
||
| <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMirror</a></h1> | ||
|
|
||
| <div class="grey"> | ||
| <img src="baboon.png" class="logo" alt="logo"/> | ||
| <pre> | ||
| /* Full list of | ||
| modes */ | ||
| </pre> | ||
| </div> | ||
|
|
||
| <p>Every mode in the distribution. The list on the front-page leaves | ||
| out some of the more obscure ones.</p> | ||
|
|
||
| <div style="-webkit-columns: 50px 3; -moz-columns: 50px 3; columns: 50px 3;"> | ||
| <ul> | ||
| <li><a href="../mode/apl/index.html">APL</a></li> | ||
| <li><a href="../mode/asterisk/index.html">Asterisk dialplan</a></li> | ||
| <li><a href="../mode/clike/index.html">C, C++, C#</a></li> | ||
| <li><a href="../mode/clojure/index.html">Clojure</a></li> | ||
| <li><a href="../mode/coffeescript/index.html">CoffeeScript</a></li> | ||
| <li><a href="../mode/commonlisp/index.html">Common Lisp</a></li> | ||
| <li><a href="../mode/css/index.html">CSS</a></li> | ||
| <li><a href="../mode/d/index.html">D</a></li> | ||
| <li><a href="../mode/diff/index.html">diff</a></li> | ||
| <li><a href="../mode/ecl/index.html">ECL</a></li> | ||
| <li><a href="../mode/erlang/index.html">Erlang</a></li> | ||
| <li><a href="../mode/go/index.html">Go</a></li> | ||
| <li><a href="../mode/groovy/index.html">Groovy</a></li> | ||
| <li><a href="../mode/haskell/index.html">Haskell</a></li> | ||
| <li><a href="../mode/haxe/index.html">Haxe</a></li> | ||
| <li><a href="../mode/htmlembedded/index.html">HTML embedded scripts</a></li> | ||
| <li><a href="../mode/htmlmixed/index.html">HTML mixed-mode</a></li> | ||
| <li><a href="../mode/http/index.html">HTTP</a></li> | ||
| <li><a href="../mode/clike/index.html">Java</a></li> | ||
| <li><a href="../mode/javascript/index.html">JavaScript</a></li> | ||
| <li><a href="../mode/jinja2/index.html">Jinja2</a></li> | ||
| <li><a href="../mode/less/index.html">LESS</a></li> | ||
| <li><a href="../mode/lua/index.html">Lua</a></li> | ||
| <li><a href="../mode/markdown/index.html">Markdown</a> (<a href="../mode/gfm/index.html">GitHub-flavour</a>)</li> | ||
| <li><a href="../mode/ntriples/index.html">NTriples</a></li> | ||
| <li><a href="../mode/ocaml/index.html">OCaml</a></li> | ||
| <li><a href="../mode/pascal/index.html">Pascal</a></li> | ||
| <li><a href="../mode/perl/index.html">Perl</a></li> | ||
| <li><a href="../mode/php/index.html">PHP</a></li> | ||
| <li><a href="../mode/pig/index.html">Pig Latin</a></li> | ||
| <li><a href="../mode/properties/index.html">Properties files</a></li> | ||
| <li><a href="../mode/python/index.html">Python</a></li> | ||
| <li><a href="../mode/r/index.html">R</a></li> | ||
| <li>RPM <a href="../mode/rpm/spec/index.html">spec</a> and <a href="../mode/rpm/changes/index.html">changelog</a></li> | ||
| <li><a href="../mode/rst/index.html">reStructuredText</a></li> | ||
| <li><a href="../mode/ruby/index.html">Ruby</a></li> | ||
| <li><a href="../mode/rust/index.html">Rust</a></li> | ||
| <li><a href="../mode/sass/index.html">Sass</a></li> | ||
| <li><a href="../mode/clike/scala.html">Scala</a></li> | ||
| <li><a href="../mode/scheme/index.html">Scheme</a></li> | ||
| <li><a href="../mode/shell/index.html">Shell</a></li> | ||
| <li><a href="../mode/sieve/index.html">Sieve</a></li> | ||
| <li><a href="../mode/smalltalk/index.html">Smalltalk</a></li> | ||
| <li><a href="../mode/smarty/index.html">Smarty</a></li> | ||
| <li><a href="../mode/sql/index.html">SQL</a> (several dialects)</li> | ||
| <li><a href="../mode/sparql/index.html">SPARQL</a></li> | ||
| <li><a href="../mode/stex/index.html">sTeX, LaTeX</a></li> | ||
| <li><a href="../mode/tiddlywiki/index.html">Tiddlywiki</a></li> | ||
| <li><a href="../mode/tiki/index.html">Tiki wiki</a></li> | ||
| <li><a href="../mode/vb/index.html">VB.NET</a></li> | ||
| <li><a href="../mode/vbscript/index.html">VBScript</a></li> | ||
| <li><a href="../mode/velocity/index.html">Velocity</a></li> | ||
| <li><a href="../mode/verilog/index.html">Verilog</a></li> | ||
| <li><a href="../mode/xml/index.html">XML/HTML</a></li> | ||
| <li><a href="../mode/xquery/index.html">XQuery</a></li> | ||
| <li><a href="../mode/yaml/index.html">YAML</a></li> | ||
| <li><a href="../mode/z80/index.html">Z80</a></li> | ||
| </ul> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| CodeMirror.defineMode("apl", function() { | ||
| var builtInOps = { | ||
| ".": "innerProduct", | ||
| "\\": "scan", | ||
| "/": "reduce", | ||
| "⌿": "reduce1Axis", | ||
| "⍀": "scan1Axis", | ||
| "¨": "each", | ||
| "⍣": "power" | ||
| }; | ||
| var builtInFuncs = { | ||
| "+": ["conjugate", "add"], | ||
| "−": ["negate", "subtract"], | ||
| "×": ["signOf", "multiply"], | ||
| "÷": ["reciprocal", "divide"], | ||
| "⌈": ["ceiling", "greaterOf"], | ||
| "⌊": ["floor", "lesserOf"], | ||
| "∣": ["absolute", "residue"], | ||
| "⍳": ["indexGenerate", "indexOf"], | ||
| "?": ["roll", "deal"], | ||
| "⋆": ["exponentiate", "toThePowerOf"], | ||
| "⍟": ["naturalLog", "logToTheBase"], | ||
| "○": ["piTimes", "circularFuncs"], | ||
| "!": ["factorial", "binomial"], | ||
| "⌹": ["matrixInverse", "matrixDivide"], | ||
| "<": [null, "lessThan"], | ||
| "≤": [null, "lessThanOrEqual"], | ||
| "=": [null, "equals"], | ||
| ">": [null, "greaterThan"], | ||
| "≥": [null, "greaterThanOrEqual"], | ||
| "≠": [null, "notEqual"], | ||
| "≡": ["depth", "match"], | ||
| "≢": [null, "notMatch"], | ||
| "∈": ["enlist", "membership"], | ||
| "⍷": [null, "find"], | ||
| "∪": ["unique", "union"], | ||
| "∩": [null, "intersection"], | ||
| "∼": ["not", "without"], | ||
| "∨": [null, "or"], | ||
| "∧": [null, "and"], | ||
| "⍱": [null, "nor"], | ||
| "⍲": [null, "nand"], | ||
| "⍴": ["shapeOf", "reshape"], | ||
| ",": ["ravel", "catenate"], | ||
| "⍪": [null, "firstAxisCatenate"], | ||
| "⌽": ["reverse", "rotate"], | ||
| "⊖": ["axis1Reverse", "axis1Rotate"], | ||
| "⍉": ["transpose", null], | ||
| "↑": ["first", "take"], | ||
| "↓": [null, "drop"], | ||
| "⊂": ["enclose", "partitionWithAxis"], | ||
| "⊃": ["diclose", "pick"], | ||
| "⌷": [null, "index"], | ||
| "⍋": ["gradeUp", null], | ||
| "⍒": ["gradeDown", null], | ||
| "⊤": ["encode", null], | ||
| "⊥": ["decode", null], | ||
| "⍕": ["format", "formatByExample"], | ||
| "⍎": ["execute", null], | ||
| "⊣": ["stop", "left"], | ||
| "⊢": ["pass", "right"] | ||
| }; | ||
|
|
||
| var isOperator = /[\.\/⌿⍀¨⍣]/; | ||
| var isNiladic = /⍬/; | ||
| var isFunction = /[\+−×÷⌈⌊∣⍳\?⋆⍟○!⌹<≤=>≥≠≡≢∈⍷∪∩∼∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢]/; | ||
| var isArrow = /←/; | ||
| var isComment = /[⍝#].*$/; | ||
|
|
||
| var stringEater = function(type) { | ||
| var prev; | ||
| prev = false; | ||
| return function(c) { | ||
| prev = c; | ||
| if (c === type) { | ||
| return prev === "\\"; | ||
| } | ||
| return true; | ||
| }; | ||
| }; | ||
| return { | ||
| startState: function() { | ||
| return { | ||
| prev: false, | ||
| func: false, | ||
| op: false, | ||
| string: false, | ||
| escape: false | ||
| }; | ||
| }, | ||
| token: function(stream, state) { | ||
| var ch, funcName, word; | ||
| if (stream.eatSpace()) { | ||
| return null; | ||
| } | ||
| ch = stream.next(); | ||
| if (ch === '"' || ch === "'") { | ||
| stream.eatWhile(stringEater(ch)); | ||
| stream.next(); | ||
| state.prev = true; | ||
| return "string"; | ||
| } | ||
| if (/[\[{\(]/.test(ch)) { | ||
| state.prev = false; | ||
| return null; | ||
| } | ||
| if (/[\]}\)]/.test(ch)) { | ||
| state.prev = true; | ||
| return null; | ||
| } | ||
| if (isNiladic.test(ch)) { | ||
| state.prev = false; | ||
| return "niladic"; | ||
| } | ||
| if (/[¯\d]/.test(ch)) { | ||
| if (state.func) { | ||
| state.func = false; | ||
| state.prev = false; | ||
| } else { | ||
| state.prev = true; | ||
| } | ||
| stream.eatWhile(/[\w\.]/); | ||
| return "number"; | ||
| } | ||
| if (isOperator.test(ch)) { | ||
| return "operator apl-" + builtInOps[ch]; | ||
| } | ||
| if (isArrow.test(ch)) { | ||
| return "apl-arrow"; | ||
| } | ||
| if (isFunction.test(ch)) { | ||
| funcName = "apl-"; | ||
| if (builtInFuncs[ch] != null) { | ||
| if (state.prev) { | ||
| funcName += builtInFuncs[ch][1]; | ||
| } else { | ||
| funcName += builtInFuncs[ch][0]; | ||
| } | ||
| } | ||
| state.func = true; | ||
| state.prev = false; | ||
| return "function " + funcName; | ||
| } | ||
| if (isComment.test(ch)) { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| if (ch === "∘" && stream.peek() === ".") { | ||
| stream.next(); | ||
| return "function jot-dot"; | ||
| } | ||
| stream.eatWhile(/[\w\$_]/); | ||
| word = stream.current(); | ||
| state.prev = true; | ||
| return "keyword"; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME("text/apl", "apl"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: APL mode</title> | ||
| <link rel="stylesheet" href="../../doc/docs.css"> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="../../addon/edit/matchbrackets.js"></script> | ||
| <script src="./apl.js"></script> | ||
| <style> | ||
| .CodeMirror { border: 2px inset #dee; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: APL mode</h1> | ||
|
|
||
| <form><textarea id="code" name="code"> | ||
| ⍝ Conway's game of life | ||
|
|
||
| ⍝ This example was inspired by the impressive demo at | ||
| ⍝ http://www.youtube.com/watch?v=a9xAKttWgP4 | ||
|
|
||
| ⍝ Create a matrix: | ||
| ⍝ 0 1 1 | ||
| ⍝ 1 1 0 | ||
| ⍝ 0 1 0 | ||
| creature ← (3 3 ⍴ ⍳ 9) ∈ 1 2 3 4 7 ⍝ Original creature from demo | ||
| creature ← (3 3 ⍴ ⍳ 9) ∈ 1 3 6 7 8 ⍝ Glider | ||
|
|
||
| ⍝ Place the creature on a larger board, near the centre | ||
| board ← ¯1 ⊖ ¯2 ⌽ 5 7 ↑ creature | ||
|
|
||
| ⍝ A function to move from one generation to the next | ||
| life ← {∨/ 1 ⍵ ∧ 3 4 = ⊂+/ +⌿ 1 0 ¯1 ∘.⊖ 1 0 ¯1 ⌽¨ ⊂⍵} | ||
|
|
||
| ⍝ Compute n-th generation and format it as a | ||
| ⍝ character matrix | ||
| gen ← {' #'[(life ⍣ ⍵) board]} | ||
|
|
||
| ⍝ Show first three generations | ||
| (gen 1) (gen 2) (gen 3) | ||
| </textarea></form> | ||
|
|
||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| matchBrackets: true, | ||
| mode: "text/apl" | ||
| }); | ||
| </script> | ||
|
|
||
| <p>Simple mode that tries to handle APL as well as it can.</p> | ||
| <p>It attempts to label functions/operators based upon | ||
| monadic/dyadic usage (but this is far from fully fleshed out). | ||
| This means there are meaningful classnames so hover states can | ||
| have popups etc.</p> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/apl</code> (APL code)</p> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| /* | ||
| * ===================================================================================== | ||
| * | ||
| * Filename: mode/asterisk/asterisk.js | ||
| * | ||
| * Description: CodeMirror mode for Asterisk dialplan | ||
| * | ||
| * Created: 05/17/2012 09:20:25 PM | ||
| * Revision: none | ||
| * | ||
| * Author: Stas Kobzar (stas@modulis.ca), | ||
| * Company: Modulis.ca Inc. | ||
| * | ||
| * ===================================================================================== | ||
| */ | ||
|
|
||
| CodeMirror.defineMode("asterisk", function() { | ||
| var atoms = ["exten", "same", "include","ignorepat","switch"], | ||
| dpcmd = ["#include","#exec"], | ||
| apps = [ | ||
| "addqueuemember","adsiprog","aelsub","agentlogin","agentmonitoroutgoing","agi", | ||
| "alarmreceiver","amd","answer","authenticate","background","backgrounddetect", | ||
| "bridge","busy","callcompletioncancel","callcompletionrequest","celgenuserevent", | ||
| "changemonitor","chanisavail","channelredirect","chanspy","clearhash","confbridge", | ||
| "congestion","continuewhile","controlplayback","dahdiacceptr2call","dahdibarge", | ||
| "dahdiras","dahdiscan","dahdisendcallreroutingfacility","dahdisendkeypadfacility", | ||
| "datetime","dbdel","dbdeltree","deadagi","dial","dictate","directory","disa", | ||
| "dumpchan","eagi","echo","endwhile","exec","execif","execiftime","exitwhile","extenspy", | ||
| "externalivr","festival","flash","followme","forkcdr","getcpeid","gosub","gosubif", | ||
| "goto","gotoif","gotoiftime","hangup","iax2provision","ices","importvar","incomplete", | ||
| "ivrdemo","jabberjoin","jabberleave","jabbersend","jabbersendgroup","jabberstatus", | ||
| "jack","log","macro","macroexclusive","macroexit","macroif","mailboxexists","meetme", | ||
| "meetmeadmin","meetmechanneladmin","meetmecount","milliwatt","minivmaccmess","minivmdelete", | ||
| "minivmgreet","minivmmwi","minivmnotify","minivmrecord","mixmonitor","monitor","morsecode", | ||
| "mp3player","mset","musiconhold","nbscat","nocdr","noop","odbc","odbc","odbcfinish", | ||
| "originate","ospauth","ospfinish","osplookup","ospnext","page","park","parkandannounce", | ||
| "parkedcall","pausemonitor","pausequeuemember","pickup","pickupchan","playback","playtones", | ||
| "privacymanager","proceeding","progress","queue","queuelog","raiseexception","read","readexten", | ||
| "readfile","receivefax","receivefax","receivefax","record","removequeuemember", | ||
| "resetcdr","retrydial","return","ringing","sayalpha","saycountedadj","saycountednoun", | ||
| "saycountpl","saydigits","saynumber","sayphonetic","sayunixtime","senddtmf","sendfax", | ||
| "sendfax","sendfax","sendimage","sendtext","sendurl","set","setamaflags", | ||
| "setcallerpres","setmusiconhold","sipaddheader","sipdtmfmode","sipremoveheader","skel", | ||
| "slastation","slatrunk","sms","softhangup","speechactivategrammar","speechbackground", | ||
| "speechcreate","speechdeactivategrammar","speechdestroy","speechloadgrammar","speechprocessingsound", | ||
| "speechstart","speechunloadgrammar","stackpop","startmusiconhold","stopmixmonitor","stopmonitor", | ||
| "stopmusiconhold","stopplaytones","system","testclient","testserver","transfer","tryexec", | ||
| "trysystem","unpausemonitor","unpausequeuemember","userevent","verbose","vmauthenticate", | ||
| "vmsayname","voicemail","voicemailmain","wait","waitexten","waitfornoise","waitforring", | ||
| "waitforsilence","waitmusiconhold","waituntil","while","zapateller" | ||
| ]; | ||
|
|
||
| function basicToken(stream,state){ | ||
| var cur = ''; | ||
| var ch = ''; | ||
| ch = stream.next(); | ||
| // comment | ||
| if(ch == ";") { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| // context | ||
| if(ch == '[') { | ||
| stream.skipTo(']'); | ||
| stream.eat(']'); | ||
| return "header"; | ||
| } | ||
| // string | ||
| if(ch == '"') { | ||
| stream.skipTo('"'); | ||
| return "string"; | ||
| } | ||
| if(ch == "'") { | ||
| stream.skipTo("'"); | ||
| return "string-2"; | ||
| } | ||
| // dialplan commands | ||
| if(ch == '#') { | ||
| stream.eatWhile(/\w/); | ||
| cur = stream.current(); | ||
| if(dpcmd.indexOf(cur) !== -1) { | ||
| stream.skipToEnd(); | ||
| return "strong"; | ||
| } | ||
| } | ||
| // application args | ||
| if(ch == '$'){ | ||
| var ch1 = stream.peek(); | ||
| if(ch1 == '{'){ | ||
| stream.skipTo('}'); | ||
| stream.eat('}'); | ||
| return "variable-3"; | ||
| } | ||
| } | ||
| // extension | ||
| stream.eatWhile(/\w/); | ||
| cur = stream.current(); | ||
| if(atoms.indexOf(cur) !== -1) { | ||
| state.extenStart = true; | ||
| switch(cur) { | ||
| case 'same': state.extenSame = true; break; | ||
| case 'include': | ||
| case 'switch': | ||
| case 'ignorepat': | ||
| state.extenInclude = true;break; | ||
| default:break; | ||
| } | ||
| return "atom"; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| startState: function() { | ||
| return { | ||
| extenStart: false, | ||
| extenSame: false, | ||
| extenInclude: false, | ||
| extenExten: false, | ||
| extenPriority: false, | ||
| extenApplication: false | ||
| }; | ||
| }, | ||
| token: function(stream, state) { | ||
|
|
||
| var cur = ''; | ||
| var ch = ''; | ||
| if(stream.eatSpace()) return null; | ||
| // extension started | ||
| if(state.extenStart){ | ||
| stream.eatWhile(/[^\s]/); | ||
| cur = stream.current(); | ||
| if(/^=>?$/.test(cur)){ | ||
| state.extenExten = true; | ||
| state.extenStart = false; | ||
| return "strong"; | ||
| } else { | ||
| state.extenStart = false; | ||
| stream.skipToEnd(); | ||
| return "error"; | ||
| } | ||
| } else if(state.extenExten) { | ||
| // set exten and priority | ||
| state.extenExten = false; | ||
| state.extenPriority = true; | ||
| stream.eatWhile(/[^,]/); | ||
| if(state.extenInclude) { | ||
| stream.skipToEnd(); | ||
| state.extenPriority = false; | ||
| state.extenInclude = false; | ||
| } | ||
| if(state.extenSame) { | ||
| state.extenPriority = false; | ||
| state.extenSame = false; | ||
| state.extenApplication = true; | ||
| } | ||
| return "tag"; | ||
| } else if(state.extenPriority) { | ||
| state.extenPriority = false; | ||
| state.extenApplication = true; | ||
| ch = stream.next(); // get comma | ||
| if(state.extenSame) return null; | ||
| stream.eatWhile(/[^,]/); | ||
| return "number"; | ||
| } else if(state.extenApplication) { | ||
| stream.eatWhile(/,/); | ||
| cur = stream.current(); | ||
| if(cur === ',') return null; | ||
| stream.eatWhile(/\w/); | ||
| cur = stream.current().toLowerCase(); | ||
| state.extenApplication = false; | ||
| if(apps.indexOf(cur) !== -1){ | ||
| return "def strong"; | ||
| } | ||
| } else{ | ||
| return basicToken(stream,state); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME("text/x-asterisk", "asterisk"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: Asterisk dialplan mode</title> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="asterisk.js"></script> | ||
| <style> | ||
| .CodeMirror {border: 1px solid #999;} | ||
| .cm-s-default span.cm-arrow { color: red; } | ||
| </style> | ||
| <link rel="stylesheet" href="../../doc/docs.css"> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: Asterisk dialplan mode</h1> | ||
| <form><textarea id="code" name="code"> | ||
| ; extensions.conf - the Asterisk dial plan | ||
| ; | ||
|
|
||
| [general] | ||
| ; | ||
| ; If static is set to no, or omitted, then the pbx_config will rewrite | ||
| ; this file when extensions are modified. Remember that all comments | ||
| ; made in the file will be lost when that happens. | ||
| static=yes | ||
|
|
||
| #include "/etc/asterisk/additional_general.conf | ||
|
|
||
| [iaxprovider] | ||
| switch => IAX2/user:[key]@myserver/mycontext | ||
|
|
||
| [dynamic] | ||
| #exec /usr/bin/dynamic-peers.pl | ||
|
|
||
| [trunkint] | ||
| ; | ||
| ; International long distance through trunk | ||
| ; | ||
| exten => _9011.,1,Macro(dundi-e164,${EXTEN:4}) | ||
| exten => _9011.,n,Dial(${GLOBAL(TRUNK)}/${FILTER(0-9,${EXTEN:${GLOBAL(TRUNKMSD)}})}) | ||
|
|
||
| [local] | ||
| ; | ||
| ; Master context for local, toll-free, and iaxtel calls only | ||
| ; | ||
| ignorepat => 9 | ||
| include => default | ||
|
|
||
| [demo] | ||
| include => stdexten | ||
| ; | ||
| ; We start with what to do when a call first comes in. | ||
| ; | ||
| exten => s,1,Wait(1) ; Wait a second, just for fun | ||
| same => n,Answer ; Answer the line | ||
| same => n,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 seconds | ||
| same => n,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 seconds | ||
| same => n(restart),BackGround(demo-congrats) ; Play a congratulatory message | ||
| same => n(instruct),BackGround(demo-instruct) ; Play some instructions | ||
| same => n,WaitExten ; Wait for an extension to be dialed. | ||
|
|
||
| exten => 2,1,BackGround(demo-moreinfo) ; Give some more information. | ||
| exten => 2,n,Goto(s,instruct) | ||
|
|
||
| exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french | ||
| exten => 3,n,Goto(s,restart) ; Start with the congratulations | ||
|
|
||
| exten => 1000,1,Goto(default,s,1) | ||
| ; | ||
| ; We also create an example user, 1234, who is on the console and has | ||
| ; voicemail, etc. | ||
| ; | ||
| exten => 1234,1,Playback(transfer,skip) ; "Please hold while..." | ||
| ; (but skip if channel is not up) | ||
| exten => 1234,n,Gosub(${EXTEN},stdexten(${GLOBAL(CONSOLE)})) | ||
| exten => 1234,n,Goto(default,s,1) ; exited Voicemail | ||
|
|
||
| exten => 1235,1,Voicemail(1234,u) ; Right to voicemail | ||
|
|
||
| exten => 1236,1,Dial(Console/dsp) ; Ring forever | ||
| exten => 1236,n,Voicemail(1234,b) ; Unless busy | ||
|
|
||
| ; | ||
| ; # for when they're done with the demo | ||
| ; | ||
| exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo" | ||
| exten => #,n,Hangup ; Hang them up. | ||
|
|
||
| ; | ||
| ; A timeout and "invalid extension rule" | ||
| ; | ||
| exten => t,1,Goto(#,1) ; If they take too long, give up | ||
| exten => i,1,Playback(invalid) ; "That's not valid, try again" | ||
|
|
||
| ; | ||
| ; Create an extension, 500, for dialing the | ||
| ; Asterisk demo. | ||
| ; | ||
| exten => 500,1,Playback(demo-abouttotry); Let them know what's going on | ||
| exten => 500,n,Dial(IAX2/guest@pbx.digium.com/s@default) ; Call the Asterisk demo | ||
| exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site | ||
| exten => 500,n,Goto(s,6) ; Return to the start over message. | ||
|
|
||
| ; | ||
| ; Create an extension, 600, for evaluating echo latency. | ||
| ; | ||
| exten => 600,1,Playback(demo-echotest) ; Let them know what's going on | ||
| exten => 600,n,Echo ; Do the echo test | ||
| exten => 600,n,Playback(demo-echodone) ; Let them know it's over | ||
| exten => 600,n,Goto(s,6) ; Start over | ||
|
|
||
| ; | ||
| ; You can use the Macro Page to intercom a individual user | ||
| exten => 76245,1,Macro(page,SIP/Grandstream1) | ||
| ; or if your peernames are the same as extensions | ||
| exten => _7XXX,1,Macro(page,SIP/${EXTEN}) | ||
| ; | ||
| ; | ||
| ; System Wide Page at extension 7999 | ||
| ; | ||
| exten => 7999,1,Set(TIMEOUT(absolute)=60) | ||
| exten => 7999,2,Page(Local/Grandstream1@page&Local/Xlite1@page&Local/1234@page/n,d) | ||
|
|
||
| ; Give voicemail at extension 8500 | ||
| ; | ||
| exten => 8500,1,VoicemailMain | ||
| exten => 8500,n,Goto(s,6) | ||
|
|
||
| </textarea></form> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| mode: "text/x-asterisk", | ||
| matchBrackets: true, | ||
| lineNumber: true | ||
| }); | ||
| </script> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/x-asterisk</code>.</p> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| CodeMirror.defineMode("d", function(config, parserConfig) { | ||
| var indentUnit = config.indentUnit, | ||
| statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, | ||
| keywords = parserConfig.keywords || {}, | ||
| builtin = parserConfig.builtin || {}, | ||
| blockKeywords = parserConfig.blockKeywords || {}, | ||
| atoms = parserConfig.atoms || {}, | ||
| hooks = parserConfig.hooks || {}, | ||
| multiLineStrings = parserConfig.multiLineStrings; | ||
| var isOperatorChar = /[+\-*&%=<>!?|\/]/; | ||
|
|
||
| var curPunc; | ||
|
|
||
| function tokenBase(stream, state) { | ||
| var ch = stream.next(); | ||
| if (hooks[ch]) { | ||
| var result = hooks[ch](stream, state); | ||
| if (result !== false) return result; | ||
| } | ||
| if (ch == '"' || ch == "'" || ch == "`") { | ||
| state.tokenize = tokenString(ch); | ||
| return state.tokenize(stream, state); | ||
| } | ||
| if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | ||
| curPunc = ch; | ||
| return null; | ||
| } | ||
| if (/\d/.test(ch)) { | ||
| stream.eatWhile(/[\w\.]/); | ||
| return "number"; | ||
| } | ||
| if (ch == "/") { | ||
| if (stream.eat("+")) { | ||
| state.tokenize = tokenComment; | ||
| return tokenNestedComment(stream, state); | ||
| } | ||
| if (stream.eat("*")) { | ||
| state.tokenize = tokenComment; | ||
| return tokenComment(stream, state); | ||
| } | ||
| if (stream.eat("/")) { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| } | ||
| if (isOperatorChar.test(ch)) { | ||
| stream.eatWhile(isOperatorChar); | ||
| return "operator"; | ||
| } | ||
| stream.eatWhile(/[\w\$_]/); | ||
| var cur = stream.current(); | ||
| if (keywords.propertyIsEnumerable(cur)) { | ||
| if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | ||
| return "keyword"; | ||
| } | ||
| if (builtin.propertyIsEnumerable(cur)) { | ||
| if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | ||
| return "builtin"; | ||
| } | ||
| if (atoms.propertyIsEnumerable(cur)) return "atom"; | ||
| return "variable"; | ||
| } | ||
|
|
||
| function tokenString(quote) { | ||
| return function(stream, state) { | ||
| var escaped = false, next, end = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next == quote && !escaped) {end = true; break;} | ||
| escaped = !escaped && next == "\\"; | ||
| } | ||
| if (end || !(escaped || multiLineStrings)) | ||
| state.tokenize = null; | ||
| return "string"; | ||
| }; | ||
| } | ||
|
|
||
| function tokenComment(stream, state) { | ||
| var maybeEnd = false, ch; | ||
| while (ch = stream.next()) { | ||
| if (ch == "/" && maybeEnd) { | ||
| state.tokenize = null; | ||
| break; | ||
| } | ||
| maybeEnd = (ch == "*"); | ||
| } | ||
| return "comment"; | ||
| } | ||
|
|
||
| function tokenNestedComment(stream, state) { | ||
| var maybeEnd = false, ch; | ||
| while (ch = stream.next()) { | ||
| if (ch == "/" && maybeEnd) { | ||
| state.tokenize = null; | ||
| break; | ||
| } | ||
| maybeEnd = (ch == "+"); | ||
| } | ||
| return "comment"; | ||
| } | ||
|
|
||
| function Context(indented, column, type, align, prev) { | ||
| this.indented = indented; | ||
| this.column = column; | ||
| this.type = type; | ||
| this.align = align; | ||
| this.prev = prev; | ||
| } | ||
| function pushContext(state, col, type) { | ||
| var indent = state.indented; | ||
| if (state.context && state.context.type == "statement") | ||
| indent = state.context.indented; | ||
| return state.context = new Context(indent, col, type, null, state.context); | ||
| } | ||
| function popContext(state) { | ||
| var t = state.context.type; | ||
| if (t == ")" || t == "]" || t == "}") | ||
| state.indented = state.context.indented; | ||
| return state.context = state.context.prev; | ||
| } | ||
|
|
||
| // Interface | ||
|
|
||
| return { | ||
| startState: function(basecolumn) { | ||
| return { | ||
| tokenize: null, | ||
| context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | ||
| indented: 0, | ||
| startOfLine: true | ||
| }; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| var ctx = state.context; | ||
| if (stream.sol()) { | ||
| if (ctx.align == null) ctx.align = false; | ||
| state.indented = stream.indentation(); | ||
| state.startOfLine = true; | ||
| } | ||
| if (stream.eatSpace()) return null; | ||
| curPunc = null; | ||
| var style = (state.tokenize || tokenBase)(stream, state); | ||
| if (style == "comment" || style == "meta") return style; | ||
| if (ctx.align == null) ctx.align = true; | ||
|
|
||
| if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state); | ||
| else if (curPunc == "{") pushContext(state, stream.column(), "}"); | ||
| else if (curPunc == "[") pushContext(state, stream.column(), "]"); | ||
| else if (curPunc == "(") pushContext(state, stream.column(), ")"); | ||
| else if (curPunc == "}") { | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| if (ctx.type == "}") ctx = popContext(state); | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| } | ||
| else if (curPunc == ctx.type) popContext(state); | ||
| else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement")) | ||
| pushContext(state, stream.column(), "statement"); | ||
| state.startOfLine = false; | ||
| return style; | ||
| }, | ||
|
|
||
| indent: function(state, textAfter) { | ||
| if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass; | ||
| var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); | ||
| if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; | ||
| var closing = firstChar == ctx.type; | ||
| if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit); | ||
| else if (ctx.align) return ctx.column + (closing ? 0 : 1); | ||
| else return ctx.indented + (closing ? 0 : indentUnit); | ||
| }, | ||
|
|
||
| electricChars: "{}" | ||
| }; | ||
| }); | ||
|
|
||
| (function() { | ||
| function words(str) { | ||
| var obj = {}, words = str.split(" "); | ||
| for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | ||
| return obj; | ||
| } | ||
|
|
||
| var blockKeywords = "body catch class do else enum for foreach foreach_reverse if in interface mixin " + | ||
| "out scope struct switch try union unittest version while with"; | ||
|
|
||
| CodeMirror.defineMIME("text/x-d", { | ||
| name: "d", | ||
| keywords: words("abstract alias align asm assert auto break case cast cdouble cent cfloat const continue " + | ||
| "debug default delegate delete deprecated export extern final finally function goto immutable " + | ||
| "import inout invariant is lazy macro module new nothrow override package pragma private " + | ||
| "protected public pure ref return shared short static super synchronized template this " + | ||
| "throw typedef typeid typeof volatile __FILE__ __LINE__ __gshared __traits __vector __parameters " + | ||
| blockKeywords), | ||
| blockKeywords: words(blockKeywords), | ||
| builtin: words("bool byte char creal dchar double float idouble ifloat int ireal long real short ubyte " + | ||
| "ucent uint ulong ushort wchar wstring void size_t sizediff_t"), | ||
| atoms: words("exit failure success true false null"), | ||
| hooks: { | ||
| "@": function(stream, _state) { | ||
| stream.eatWhile(/[\w\$_]/); | ||
| return "meta"; | ||
| } | ||
| } | ||
| }); | ||
| }()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: D mode</title> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="../../addon/edit/matchbrackets.js"></script> | ||
| <script src="d.js"></script> | ||
| <link rel="stylesheet" href="../../doc/docs.css"> | ||
| <style>.CodeMirror {border: 2px inset #dee;}</style> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: D mode</h1> | ||
|
|
||
| <form><textarea id="code" name="code"> | ||
| /* D demo code // copied from phobos/sd/metastrings.d */ | ||
| // Written in the D programming language. | ||
|
|
||
| /** | ||
| Templates with which to do compile-time manipulation of strings. | ||
|
|
||
| Macros: | ||
| WIKI = Phobos/StdMetastrings | ||
|
|
||
| Copyright: Copyright Digital Mars 2007 - 2009. | ||
| License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. | ||
| Authors: $(WEB digitalmars.com, Walter Bright), | ||
| Don Clugston | ||
| Source: $(PHOBOSSRC std/_metastrings.d) | ||
| */ | ||
| /* | ||
| Copyright Digital Mars 2007 - 2009. | ||
| Distributed under the Boost Software License, Version 1.0. | ||
| (See accompanying file LICENSE_1_0.txt or copy at | ||
| http://www.boost.org/LICENSE_1_0.txt) | ||
| */ | ||
| module std.metastrings; | ||
|
|
||
| /** | ||
| Formats constants into a string at compile time. Analogous to $(XREF | ||
| string,format). | ||
|
|
||
| Parameters: | ||
|
|
||
| A = tuple of constants, which can be strings, characters, or integral | ||
| values. | ||
|
|
||
| Formats: | ||
| * The formats supported are %s for strings, and %% | ||
| * for the % character. | ||
| Example: | ||
| --- | ||
| import std.metastrings; | ||
| import std.stdio; | ||
|
|
||
| void main() | ||
| { | ||
| string s = Format!("Arg %s = %s", "foo", 27); | ||
| writefln(s); // "Arg foo = 27" | ||
| } | ||
| * --- | ||
| */ | ||
|
|
||
| template Format(A...) | ||
| { | ||
| static if (A.length == 0) | ||
| enum Format = ""; | ||
| else static if (is(typeof(A[0]) : const(char)[])) | ||
| enum Format = FormatString!(A[0], A[1..$]); | ||
| else | ||
| enum Format = toStringNow!(A[0]) ~ Format!(A[1..$]); | ||
| } | ||
|
|
||
| template FormatString(const(char)[] F, A...) | ||
| { | ||
| static if (F.length == 0) | ||
| enum FormatString = Format!(A); | ||
| else static if (F.length == 1) | ||
| enum FormatString = F[0] ~ Format!(A); | ||
| else static if (F[0..2] == "%s") | ||
| enum FormatString | ||
| = toStringNow!(A[0]) ~ FormatString!(F[2..$],A[1..$]); | ||
| else static if (F[0..2] == "%%") | ||
| enum FormatString = "%" ~ FormatString!(F[2..$],A); | ||
| else | ||
| { | ||
| static assert(F[0] != '%', "unrecognized format %" ~ F[1]); | ||
| enum FormatString = F[0] ~ FormatString!(F[1..$],A); | ||
| } | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| auto s = Format!("hel%slo", "world", -138, 'c', true); | ||
| assert(s == "helworldlo-138ctrue", "[" ~ s ~ "]"); | ||
| } | ||
|
|
||
| /** | ||
| * Convert constant argument to a string. | ||
| */ | ||
|
|
||
| template toStringNow(ulong v) | ||
| { | ||
| static if (v < 10) | ||
| enum toStringNow = "" ~ cast(char)(v + '0'); | ||
| else | ||
| enum toStringNow = toStringNow!(v / 10) ~ toStringNow!(v % 10); | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| static assert(toStringNow!(1uL << 62) == "4611686018427387904"); | ||
| } | ||
|
|
||
| /// ditto | ||
| template toStringNow(long v) | ||
| { | ||
| static if (v < 0) | ||
| enum toStringNow = "-" ~ toStringNow!(cast(ulong) -v); | ||
| else | ||
| enum toStringNow = toStringNow!(cast(ulong) v); | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| static assert(toStringNow!(0x100000000) == "4294967296"); | ||
| static assert(toStringNow!(-138L) == "-138"); | ||
| } | ||
|
|
||
| /// ditto | ||
| template toStringNow(uint U) | ||
| { | ||
| enum toStringNow = toStringNow!(cast(ulong)U); | ||
| } | ||
|
|
||
| /// ditto | ||
| template toStringNow(int I) | ||
| { | ||
| enum toStringNow = toStringNow!(cast(long)I); | ||
| } | ||
|
|
||
| /// ditto | ||
| template toStringNow(bool B) | ||
| { | ||
| enum toStringNow = B ? "true" : "false"; | ||
| } | ||
|
|
||
| /// ditto | ||
| template toStringNow(string S) | ||
| { | ||
| enum toStringNow = S; | ||
| } | ||
|
|
||
| /// ditto | ||
| template toStringNow(char C) | ||
| { | ||
| enum toStringNow = "" ~ C; | ||
| } | ||
|
|
||
|
|
||
| /******** | ||
| * Parse unsigned integer literal from the start of string s. | ||
| * returns: | ||
| * .value = the integer literal as a string, | ||
| * .rest = the string following the integer literal | ||
| * Otherwise: | ||
| * .value = null, | ||
| * .rest = s | ||
| */ | ||
|
|
||
| template parseUinteger(const(char)[] s) | ||
| { | ||
| static if (s.length == 0) | ||
| { | ||
| enum value = ""; | ||
| enum rest = ""; | ||
| } | ||
| else static if (s[0] >= '0' && s[0] <= '9') | ||
| { | ||
| enum value = s[0] ~ parseUinteger!(s[1..$]).value; | ||
| enum rest = parseUinteger!(s[1..$]).rest; | ||
| } | ||
| else | ||
| { | ||
| enum value = ""; | ||
| enum rest = s; | ||
| } | ||
| } | ||
|
|
||
| /******** | ||
| Parse integer literal optionally preceded by $(D '-') from the start | ||
| of string $(D s). | ||
|
|
||
| Returns: | ||
| .value = the integer literal as a string, | ||
| .rest = the string following the integer literal | ||
|
|
||
| Otherwise: | ||
| .value = null, | ||
| .rest = s | ||
| */ | ||
|
|
||
| template parseInteger(const(char)[] s) | ||
| { | ||
| static if (s.length == 0) | ||
| { | ||
| enum value = ""; | ||
| enum rest = ""; | ||
| } | ||
| else static if (s[0] >= '0' && s[0] <= '9') | ||
| { | ||
| enum value = s[0] ~ parseUinteger!(s[1..$]).value; | ||
| enum rest = parseUinteger!(s[1..$]).rest; | ||
| } | ||
| else static if (s.length >= 2 && | ||
| s[0] == '-' && s[1] >= '0' && s[1] <= '9') | ||
| { | ||
| enum value = s[0..2] ~ parseUinteger!(s[2..$]).value; | ||
| enum rest = parseUinteger!(s[2..$]).rest; | ||
| } | ||
| else | ||
| { | ||
| enum value = ""; | ||
| enum rest = s; | ||
| } | ||
| } | ||
|
|
||
| unittest | ||
| { | ||
| assert(parseUinteger!("1234abc").value == "1234"); | ||
| assert(parseUinteger!("1234abc").rest == "abc"); | ||
| assert(parseInteger!("-1234abc").value == "-1234"); | ||
| assert(parseInteger!("-1234abc").rest == "abc"); | ||
| } | ||
|
|
||
| /** | ||
| Deprecated aliases held for backward compatibility. | ||
| */ | ||
| deprecated alias toStringNow ToString; | ||
| /// Ditto | ||
| deprecated alias parseUinteger ParseUinteger; | ||
| /// Ditto | ||
| deprecated alias parseUinteger ParseInteger; | ||
|
|
||
| </textarea></form> | ||
|
|
||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| matchBrackets: true, | ||
| indentUnit: 4, | ||
| mode: "text/x-d" | ||
| }); | ||
| </script> | ||
|
|
||
| <p>Simple mode that handle D-Syntax (<a href="http://www.dlang.org">DLang Homepage</a>).</p> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/x-d</code> | ||
| .</p> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,225 +1,84 @@ | ||
| (function() { | ||
| var mode = CodeMirror.getMode({tabSize: 4}, "gfm"); | ||
| function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | ||
|
|
||
| MT("emInWordAsterisk", | ||
| "foo[em *bar*]hello"); | ||
|
|
||
| MT("emInWordUnderscore", | ||
| "foo_bar_hello"); | ||
|
|
||
| MT("emStrongUnderscore", | ||
| "[strong __][emstrong _foo__][em _] bar"); | ||
|
|
||
| MT("fencedCodeBlocks", | ||
| "[comment ```]", | ||
| "[comment foo]", | ||
| "", | ||
| "[comment ```]", | ||
| "bar"); | ||
|
|
||
| MT("fencedCodeBlockModeSwitching", | ||
| "[comment ```javascript]", | ||
| "[variable foo]", | ||
| "", | ||
| "[comment ```]", | ||
| "bar"); | ||
|
|
||
| MT("SHA", | ||
| "foo [link be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] bar"); | ||
|
|
||
| MT("shortSHA", | ||
| "foo [link be6a8cc] bar"); | ||
|
|
||
| MT("tooShortSHA", | ||
| "foo be6a8c bar"); | ||
|
|
||
| MT("longSHA", | ||
| "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd22 bar"); | ||
|
|
||
| MT("badSHA", | ||
| "foo be6a8cc1c1ecfe9489fb51e4869af15a13fc2cg2 bar"); | ||
|
|
||
| MT("userSHA", | ||
| "foo [link bar@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] hello"); | ||
|
|
||
| MT("userProjectSHA", | ||
| "foo [link bar/hello@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2] world"); | ||
|
|
||
| MT("num", | ||
| "foo [link #1] bar"); | ||
|
|
||
| MT("badNum", | ||
| "foo #1bar hello"); | ||
|
|
||
| MT("userNum", | ||
| "foo [link bar#1] hello"); | ||
|
|
||
| MT("userProjectNum", | ||
| "foo [link bar/hello#1] world"); | ||
|
|
||
| MT("vanillaLink", | ||
| "foo [link http://www.example.com/] bar"); | ||
|
|
||
| MT("vanillaLinkPunctuation", | ||
| "foo [link http://www.example.com/]. bar"); | ||
|
|
||
| MT("vanillaLinkExtension", | ||
| "foo [link http://www.example.com/index.html] bar"); | ||
|
|
||
| MT("notALink", | ||
| "[comment ```css]", | ||
| "[tag foo] {[property color][operator :][keyword black];}", | ||
| "[comment ```][link http://www.example.com/]"); | ||
|
|
||
| MT("notALink", | ||
| "[comment ``foo `bar` http://www.example.com/``] hello"); | ||
|
|
||
| MT("notALink", | ||
| "[comment `foo]", | ||
| "[link http://www.example.com/]", | ||
| "[comment `foo]", | ||
| "", | ||
| "[link http://www.example.com/]"); | ||
| })(); |